fix: 修复空菜单无法切换为手动输入的bug,修复没有vueName无法读取到pathinfo.json中的bug

This commit is contained in:
pixel(奇淼
2024-10-26 12:17:54 +08:00
parent c3fd7b9077
commit 6bb8f8a030
3 changed files with 29 additions and 7 deletions

View File

@@ -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);