53 lines
1.6 KiB
JavaScript
53 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'));
|
||
|
|
|
||
|
|
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;
|
||
|
|
|
||
|
|
const patterns = [
|
||
|
|
{ regex: /http\.(post|put)\(([^,]+),\s*\{\s*(\w+)\s*\)\)/g, replacement: 'http.$1($2, $3)' },
|
||
|
|
{ regex: /http\.(post|put)\(([^,]+),\s*\{\s*\{\s*(\w+)\s*\}\s*\)\)/g, replacement: 'http.$1($2, { $3 })' },
|
||
|
|
{ regex: /http\.post\(([^,]+),\s*\{\s*method:\s*'DELETE'\s*\}\)/g, replacement: 'http.delete($1)' },
|
||
|
|
{ regex: /http\.post\(([^,]+),\s*\{\s*method:\s*'POST'\s*\}\)/g, replacement: 'http.post($1)' },
|
||
|
|
{ regex: /http\.post\(([^,]+),\s*\{\s*\{\s*([^}]+)\s*\}\s*\)\)/g, replacement: 'http.post($1, { $2 })' },
|
||
|
|
];
|
||
|
|
|
||
|
|
patterns.forEach(({ regex, replacement }) => {
|
||
|
|
if (regex.test(content)) {
|
||
|
|
content = content.replace(regex, replacement);
|
||
|
|
modified = true;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
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!');
|