46 lines
1.6 KiB
JavaScript
46 lines
1.6 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const scriptsDir = '/home/ubuntu/zhuiguang-ai/scripts';
|
|
const files = fs.readdirSync(scriptsDir).filter(f => f.endsWith('.mjs'));
|
|
|
|
// Patterns to remove:
|
|
// 1. `const name: Type = ` -> `const name = `
|
|
// 2. `let name: Type = ` -> `let name = `
|
|
// 3. `: Type` after function parameters (tricky - skip for now)
|
|
// 4. `: Type` after variable declarations
|
|
|
|
let totalFixed = 0;
|
|
|
|
for (const file of files) {
|
|
const filePath = path.join(scriptsDir, file);
|
|
let content = fs.readFileSync(filePath, 'utf8');
|
|
const original = content;
|
|
|
|
// Remove type annotations from const/let/var declarations
|
|
// Match: `const x: Type =` or `let x: Type =`
|
|
content = content.replace(/(const|let|var)\s+(\w+)\s*:\s*[^=]+?(\s*=\s*)/g, '$1 $2 $3');
|
|
|
|
// Remove type annotations from function return types like `): Type {`
|
|
content = content.replace(/\):\s*(Promise<[^>]+>|string|number|boolean|void|any|Record<[^>]+>|Map<[^>]+>|Set<[^>]+>)\s*\{/g, ') {');
|
|
|
|
if (content !== original) {
|
|
fs.writeFileSync(filePath, content, 'utf8');
|
|
console.log('Fixed: ' + file);
|
|
totalFixed++;
|
|
}
|
|
}
|
|
|
|
console.log('\nTotal files fixed: ' + totalFixed);
|
|
|
|
// Verify task1
|
|
const task1 = fs.readFileSync(path.join(scriptsDir, 'task1-discover-tools.mjs'), 'utf8');
|
|
const tsLines = task1.split('\n').filter((line, i) => {
|
|
const lineNum = i + 1;
|
|
return line.match(/(const|let|var)\s+\w+\s*:\s*[^=]/) || line.match(/:\s*(Record|Map|Set|Promise)<[^>]+>\s*[{(]/);
|
|
});
|
|
if (tsLines.length > 0) {
|
|
console.log('\n=== Remaining TS in task1 ===');
|
|
tsLines.forEach(l => console.log(l));
|
|
}
|