- 将服务文件按功能分类到core、ai、analytics、security等目录 - 修复logger导入路径问题,统一使用相对路径 - 更新相关文件的导入路径引用 - 添加新的批量操作组件导出文件 - 修复dashboard页面中的类型错误 - 添加dotenv依赖到package.json
92 lines
3.3 KiB
JavaScript
92 lines
3.3 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const servicesDir = 'd:\\trae_projects\\makemd\\makemd\\dashboard\\src\\services';
|
|
|
|
const files = [
|
|
'saasTenantDataSource.ts',
|
|
'blacklistDataSource.ts',
|
|
'settingsDataSource.ts',
|
|
'autoExecutionDataSource.ts',
|
|
'leaderboardDataSource.ts',
|
|
'shopReportDataSource.ts',
|
|
'dynamicPricingDataSource.ts',
|
|
'certificateDataSource.ts',
|
|
'analyticsDataSource.ts',
|
|
'userAssetDataSource.ts',
|
|
'unifiedFulfillmentDataSource.ts',
|
|
'taskCenterDataSource.ts',
|
|
'suppliersDataSource.ts',
|
|
'storeCreationDataSource.ts',
|
|
'returnDataSource.ts',
|
|
'reportsDataSource.ts',
|
|
'productSelectionDataSource.ts',
|
|
'omnichannelMarketingDataSource.ts',
|
|
'omnichannelCommunicationDataSource.ts',
|
|
'merchantDataSource.ts',
|
|
'marketingDataSource.ts',
|
|
'logisticsDataSource.ts',
|
|
'independentSiteDataSource.ts',
|
|
'financeDataSource.ts',
|
|
'crossBorderIntegrationDataSource.ts',
|
|
'b2bTradeDataSource.ts',
|
|
'arbitrageDataSource.ts',
|
|
'afterSalesDataSource.ts',
|
|
'adOptimizationDataSource.ts',
|
|
'abTestDataSource.ts',
|
|
];
|
|
|
|
const fixFile = (filename) => {
|
|
const filePath = path.join(servicesDir, filename);
|
|
|
|
if (!fs.existsSync(filePath)) {
|
|
console.log(`File not found: ${filePath}`);
|
|
return;
|
|
}
|
|
|
|
let content = fs.readFileSync(filePath, 'utf8');
|
|
|
|
if (!content.includes('import { http }')) {
|
|
const importLine = "import { http } from './http';\n";
|
|
const firstImportIndex = content.indexOf('import ');
|
|
if (firstImportIndex !== -1) {
|
|
content = content.slice(0, firstImportIndex) + importLine + content.slice(firstImportIndex);
|
|
} else {
|
|
content = importLine + content;
|
|
}
|
|
}
|
|
|
|
content = content.replace(/fetch\(`\$\{this\.baseUrl\}/g, 'http.get(`${this.baseUrl}');
|
|
content = content.replace(/fetch\('\$\{this\.baseUrl\}/g, "http.get(`${this.baseUrl}");
|
|
content = content.replace(/fetch\("\$\{this\.baseUrl\}/g, 'http.get(`${this.baseUrl}');
|
|
|
|
content = content.replace(/const res = await fetch\(/g, 'const res = await http.get(');
|
|
content = content.replace(/const response = await fetch\(/g, 'const response = await http.get(');
|
|
|
|
content = content.replace(/http\.get\(`\$\{this\.baseUrl\}([^`]+)`, \{/g, 'http.post(`${this.baseUrl}$1`, {');
|
|
content = content.replace(/http\.get\(`\$\{this\.baseUrl\}([^`]+)`, \{/g, 'http.put(`${this.baseUrl}$1`, {');
|
|
content = content.replace(/http\.get\(`\$\{this\.baseUrl\}([^`]+)`, \{/g, 'http.delete(`${this.baseUrl}$1`, {');
|
|
|
|
content = content.replace(/method: 'POST',\s*headers: \{ 'Content-Type': 'application\/json' \},\s*body: JSON\.stringify\(([^)]+)\)\s*\}/g, '$1');
|
|
content = content.replace(/method: 'PUT',\s*headers: \{ 'Content-Type': 'application\/json' \},\s*body: JSON\.stringify\(([^)]+)\)\s*\}/g, '$1');
|
|
content = content.replace(/method: 'DELETE',\s*headers: \{ 'Content-Type': 'application\/json' \},\s*body: JSON\.stringify\(([^)]+)\)\s*\}/g, '$1');
|
|
|
|
content = content.replace(/return res\.json\(\);/g, 'return res.data;');
|
|
content = content.replace(/return response\.json\(\);/g, 'return response.data;');
|
|
|
|
fs.writeFileSync(filePath, content, 'utf8');
|
|
console.log(`Fixed: ${filename}`);
|
|
};
|
|
|
|
console.log('Fixing data source files...\n');
|
|
|
|
files.forEach(file => {
|
|
try {
|
|
fixFile(file);
|
|
} catch (error) {
|
|
console.error(`Error fixing ${file}:`, error.message);
|
|
}
|
|
});
|
|
|
|
console.log('\nAll files processed!');
|