- 将服务文件按功能分类到core、ai、analytics、security等目录 - 修复logger导入路径问题,统一使用相对路径 - 更新相关文件的导入路径引用 - 添加新的批量操作组件导出文件 - 修复dashboard页面中的类型错误 - 添加dotenv依赖到package.json
58 lines
1.6 KiB
JavaScript
58 lines
1.6 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const servicesDir = 'd:\\trae_projects\\makemd\\makemd\\dashboard\\src\\services';
|
|
|
|
const files = fs.readdirSync(servicesDir).filter(f => f.endsWith('DataSource.ts') || f.endsWith('.ts'));
|
|
|
|
const fixFile = (filename) => {
|
|
const filePath = path.join(servicesDir, filename);
|
|
|
|
if (!fs.existsSync(filePath)) {
|
|
return;
|
|
}
|
|
|
|
let content = fs.readFileSync(filePath, 'utf8');
|
|
let modified = false;
|
|
|
|
if (content.includes('.json()')) {
|
|
content = content.replace(/const\s+(\w+)\s*=\s*await\s+(\w+)\.json\(\);?\s*return\s+\1\.data;?/g, 'return $2.data;');
|
|
content = content.replace(/const\s+(\w+)\s*=\s*await\s+(\w+)\.json\(\);/g, '');
|
|
content = content.replace(/await\s+(\w+)\.json\(\)/g, '$1.data');
|
|
modified = true;
|
|
}
|
|
|
|
if (content.includes('.ok')) {
|
|
content = content.replace(/if\s*\(\s*!(\w+)\.ok\s*\)\s*\{[^}]*\}/g, '');
|
|
content = content.replace(/if\s*\(\s*!(\w+)\.ok\s*\)\s*throw\s+new\s+Error[^;]+;/g, '');
|
|
modified = true;
|
|
}
|
|
|
|
if (content.includes('AxiosRequestConfig')) {
|
|
content = content.replace(/http\.(post|put)\(([^,]+),\s*(\w+)\s*\)/g, 'http.$1($2, $3)');
|
|
modified = true;
|
|
}
|
|
|
|
if (content.includes('formData:')) {
|
|
content = content.replace(/,\s*\{\s*formData:\s*([^}]+)\s*\}/g, ', $1');
|
|
modified = true;
|
|
}
|
|
|
|
if (modified) {
|
|
fs.writeFileSync(filePath, content, 'utf8');
|
|
console.log(`Fixed: ${filename}`);
|
|
}
|
|
};
|
|
|
|
console.log('Fixing all axios issues...\n');
|
|
|
|
files.forEach(file => {
|
|
try {
|
|
fixFile(file);
|
|
} catch (error) {
|
|
console.error(`Error fixing ${file}:`, error.message);
|
|
}
|
|
});
|
|
|
|
console.log('\nAll files processed!');
|