import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); // 文件名映射:拼音 -> 英文 const fileMapping = { 'jiaoseguanli': 'roleManagement', 'bduanquanxianxiaoyan': 'bEndPermissionVerify', 'huihuaguanli': 'sessionManagement', 'piliangxiugai': 'batchUpdate', 'common': 'common', 'wenjianguanli': 'fileManagement', 'zhanneixin': 'internalMessage', 'daimashengchengjichu': 'codeGenBasic', 'daimashengchengpeizhi': 'codeGenConfig', 'xitongshouye': 'systemHome', 'quanxiananniu': 'permissionButton', 'caidanguanli': 'menuManagement', 'mokuaiguanli': 'moduleManagement', 'danyeguanli': 'spaManagement', 'caozuorizhi': 'operationLog', 'fangwenrizhi': 'accessLog', 'mqttfuwu': 'mqttService', 'xitongpeizhi': 'systemConfig', 'xitongzidi': 'systemDict', 'zuzhiguanli': 'organizationManagement', 'zhiweiguanli': 'positionManagement', 'yonghuguanli': 'userManagement', 'wenjianshangchuankongzhiqi': 'fileUploadController', 'yonghugerenxinxikongzhiqi': 'userCenter', }; const apiDir = path.join(__dirname, '../src/api/SimpleAdmin'); // 重命名文件 Object.entries(fileMapping).forEach(([oldName, newName]) => { const oldPath = path.join(apiDir, `${oldName}.ts`); const newPath = path.join(apiDir, `${newName}.ts`); if (fs.existsSync(oldPath) && oldName !== newName) { fs.renameSync(oldPath, newPath); console.log(`✅ 重命名: ${oldName}.ts -> ${newName}.ts`); } }); // 更新 index.ts const indexPath = path.join(apiDir, 'index.ts'); if (fs.existsSync(indexPath)) { let content = fs.readFileSync(indexPath, 'utf-8'); // 替换所有的导入和导出 Object.entries(fileMapping).forEach(([oldName, newName]) => { if (oldName !== newName) { // 替换 import 语句 const importRegex = new RegExp(`import \\* as ${oldName} from`, 'g'); content = content.replace(importRegex, `import * as ${newName} from`); // 替换导出对象中的键 const exportRegex = new RegExp(`\\b${oldName}:`, 'g'); content = content.replace(exportRegex, `${newName}:`); // 替换文件路径 content = content.replace(new RegExp(`'./${oldName}'`, 'g'), `'./${newName}'`); } }); fs.writeFileSync(indexPath, content, 'utf-8'); console.log('✅ 已更新 index.ts'); } console.log('✅ 所有文件重命名完成!');