时里院子市集
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

87 lines
2.4 KiB

#!/usr/bin/env node
/**
* 批量更新API文件中的request导入
* 将 import request from '@/utils/request' 替换为 import request from '@/utils/request-legacy'
*/
const fs = require('fs');
const path = require('path');
// 需要更新的API文件列表
const apiFiles = [
'src/api/system/dict/index.ts',
'src/api/system/dictionary/index.ts',
'src/api/system/dictionary-data/index.ts',
'src/api/system/dict-data/index.ts',
'src/api/system/menu/index.ts',
'src/api/system/organization/index.ts',
'src/api/system/operation-record/index.ts',
'src/api/system/user-file/index.ts',
'src/api/system/plug/index.ts',
'src/api/system/environment/index.ts',
'src/api/system/url/index.ts',
'src/api/system/file/index.ts',
'src/api/system/white-domain/index.ts',
'src/api/cms/cmsMpAd/index.ts',
'src/api/cms/cmsAdRecord/index.ts',
'src/api/shop/shopGoods/index.ts',
'src/api/shop/shopOrder/index.ts',
'src/api/shop/shopOrderGoods/index.ts',
'src/api/shop/shopCategory/index.ts',
'src/api/user/coupon/index.ts',
'src/api/user/points/index.ts',
'src/api/user/gift/index.ts',
'src/api/passport/index.ts'
];
function updateFile(filePath) {
try {
if (!fs.existsSync(filePath)) {
console.log(`文件不存在: ${filePath}`);
return false;
}
const content = fs.readFileSync(filePath, 'utf8');
const oldImport = "import request from '@/utils/request';";
const newImport = "import request from '@/utils/request-legacy';";
if (content.includes(oldImport)) {
const updatedContent = content.replace(oldImport, newImport);
fs.writeFileSync(filePath, updatedContent, 'utf8');
console.log(`✅ 已更新: ${filePath}`);
return true;
} else {
console.log(`⏭️ 跳过: ${filePath} (未找到目标导入)`);
return false;
}
} catch (error) {
console.error(`❌ 更新失败: ${filePath}`, error.message);
return false;
}
}
function main() {
console.log('🚀 开始批量更新API文件导入...\n');
let updatedCount = 0;
let totalCount = 0;
for (const filePath of apiFiles) {
totalCount++;
if (updateFile(filePath)) {
updatedCount++;
}
}
console.log(`\n📊 更新完成:`);
console.log(` 总文件数: ${totalCount}`);
console.log(` 已更新: ${updatedCount}`);
console.log(` 跳过: ${totalCount - updatedCount}`);
}
if (require.main === module) {
main();
}
module.exports = { updateFile };