diff --git a/README.md b/README.md index 365d3a63..808f8be6 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ [![GitHub issues](https://img.shields.io/github/issues/WeBankFinTech/fes.js.svg?style=flat-square)](../../issues) [![MIT](https://img.shields.io/dub/l/vibe-d.svg?style=flat-square)](http://opensource.org/licenses/MIT) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](../../pulls) +[![Page Views Count](https://badges.toozhao.com/badges/01G7TRNN1PH9PMSCYWDF3EK4QT/green.svg)](https://badges.toozhao.com/stats/01G7TRNN1PH9PMSCYWDF3EK4QT "Get your own page views count badge on badges.toozhao.com") diff --git a/packages/fes-preset-built-in/src/plugins/route/index.js b/packages/fes-preset-built-in/src/plugins/route/index.js index bc3768c6..d948e565 100644 --- a/packages/fes-preset-built-in/src/plugins/route/index.js +++ b/packages/fes-preset-built-in/src/plugins/route/index.js @@ -1,6 +1,6 @@ import { readdirSync, statSync, readFileSync } from 'fs'; -import { join, extname, posix, basename } from 'path'; -import { lodash, parser, generator, logger } from '@fesjs/utils'; +import { join, extname, basename } from 'path'; +import { lodash, parser, generator, logger, winPath } from '@fesjs/utils'; import { parse } from '@vue/compiler-sfc'; import { runtimePath } from '../../utils/constants'; @@ -20,14 +20,14 @@ const isProcessFile = function (path) { }; const isProcessDirectory = function (path, item) { - const component = join(path, item); + const component = winPath(join(path, item)); return statSync(component).isDirectory() && !['components'].includes(item); }; const checkHasLayout = function (path) { const dirList = readdirSync(path); return dirList.some((item) => { - if (!isProcessFile(join(path, item))) { + if (!isProcessFile(winPath(join(path, item)))) { return false; } const ext = extname(item); @@ -37,7 +37,7 @@ const checkHasLayout = function (path) { }; const getRouteName = function (parentRoutePath, fileName) { - const routeName = posix.join(parentRoutePath, fileName); + const routeName = winPath(join(parentRoutePath, fileName)); return routeName.slice(1).replace(/\//g, '_').replace(/@/g, '_').replace(/:/g, '_').replace(/\*/g, 'FUZZYMATCH'); }; @@ -54,7 +54,7 @@ const getRoutePath = function (parentRoutePath, fileName, isFile = true) { if (fileName.includes('*')) { fileName = fileName.replace('*', ':pathMatch(.*)'); } - return posix.join(parentRoutePath, fileName); + return winPath(join(parentRoutePath, fileName)); }; function getRouteMeta(content) { @@ -90,8 +90,8 @@ const genRoutes = function (parentRoutes, path, parentRoutePath) { } dirList.forEach((item) => { // 文件或者目录的绝对路径 - const component = join(path, item); - if (isProcessFile(component)) { + const filePath = winPath(join(path, item)); + if (isProcessFile(filePath)) { const ext = extname(item); const fileName = basename(item, ext); // 路由的path @@ -106,9 +106,9 @@ const genRoutes = function (parentRoutes, path, parentRoutePath) { // 路由名称 const routeName = getRouteName(parentRoutePath, fileName); - const componentPath = posix.join(path, item); + const componentPath = winPath(filePath); - const content = readFileSync(component, 'utf-8'); + const content = readFileSync(filePath, 'utf-8'); let routeMeta = {}; if (ext === '.vue') { const { descriptor } = parse(content); @@ -146,7 +146,7 @@ const genRoutes = function (parentRoutes, path, parentRoutePath) { dirList.forEach((item) => { if (isProcessDirectory(path, item)) { // 文件或者目录的绝对路径 - const nextPath = join(path, item); + const nextPath = winPath(join(path, item)); const nextParentRouteUrl = getRoutePath(parentRoutePath, item, false); if (hasLayout) { genRoutes(layoutRoute.children, nextPath, nextParentRouteUrl);