47 lines
1.3 KiB
JavaScript
47 lines
1.3 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'));
|
||
|
|
|
||
|
|
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');
|
||
|
|
let modified = false;
|
||
|
|
|
||
|
|
if (content.includes(', { data)') || content.includes(', { { ')) {
|
||
|
|
content = content.replace(/http\.(post|put|patch)\(([^,]+),\s*\{\s*(\w+)\s*\)\)/g, 'http.$1($2, $3)');
|
||
|
|
content = content.replace(/http\.(post|put|patch)\(([^,]+),\s*\{\s*\{\s*(\w+)\s*\}\s*\)\)/g, 'http.$1($2, { $3 })');
|
||
|
|
modified = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
content = content.replace(/return res\.json\(\);/g, 'return res.data;');
|
||
|
|
content = content.replace(/return response\.json\(\);/g, 'return response.data;');
|
||
|
|
|
||
|
|
if (modified) {
|
||
|
|
fs.writeFileSync(filePath, content, 'utf8');
|
||
|
|
console.log(`Fixed: ${filename}`);
|
||
|
|
} else {
|
||
|
|
console.log(`No changes needed: ${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!');
|