fix: 修复空菜单无法切换为手动输入的bug,修复没有vueName无法读取到pathinfo.json中的bug
This commit is contained in:
@@ -2,6 +2,14 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
import chokidar from 'chokidar';
|
||||
|
||||
const toPascalCase = (str) => {
|
||||
return str.replace(/(^\w|-\w)/g, clearAndUpper);
|
||||
};
|
||||
|
||||
const clearAndUpper = (text) => {
|
||||
return text.replace(/-/, '').toUpperCase();
|
||||
};
|
||||
|
||||
// 递归获取目录下所有的 .vue 文件
|
||||
const getAllVueFiles = (dir, fileList = []) => {
|
||||
const files = fs.readdirSync(dir);
|
||||
@@ -35,10 +43,8 @@ const vueFilePathPlugin = (outputFilePath) => {
|
||||
const pathNameMap = vueFiles.reduce((acc, filePath) => {
|
||||
const content = fs.readFileSync(filePath, 'utf-8');
|
||||
const componentName = extractComponentName(content);
|
||||
if (componentName) {
|
||||
let relativePath ="/" + path.relative(root, filePath).replace(/\\/g, '/');
|
||||
acc[relativePath] = componentName;
|
||||
}
|
||||
acc[relativePath] = componentName || toPascalCase(path.basename(filePath, '.vue'));
|
||||
return acc;
|
||||
}, {});
|
||||
const outputContent = JSON.stringify(pathNameMap, null, 2);
|
||||
|
Reference in New Issue
Block a user