learning_ai_invt_trdg/backend/fix_imports.ts

53 lines
1.8 KiB
TypeScript

import fs from 'fs';
import path from 'path';
const testsDir = path.resolve(process.cwd(), 'tests');
const replacements = [
{ from: "from './strategies", to: "from '../src/strategies" },
{ from: "from './connectors", to: "from '../src/connectors" },
{ from: "from './config", to: "from '../src/config" },
{ from: "from './utils", to: "from '../src/utils" },
{ from: "from './services", to: "from '../src/services" },
{ from: "from './src/", to: "from '../src/" },
// Handle double quotes too if any
{ from: 'from "./strategies', to: 'from "../src/strategies' },
{ from: 'from "./connectors', to: 'from "../src/connectors' },
{ from: 'from "./config', to: 'from "../src/config' },
{ from: 'from "./utils', to: 'from "../src/utils' },
{ from: 'from "./services', to: 'from "../src/services' },
{ from: 'from "./src/', to: 'from "../src/' },
];
async function fixImports() {
console.log(`Scanning ${testsDir}...`);
if (!fs.existsSync(testsDir)) {
console.error('Tests directory not found!');
return;
}
const files = fs.readdirSync(testsDir).filter(f => f.endsWith('.ts'));
for (const file of files) {
const filePath = path.join(testsDir, file);
let content = fs.readFileSync(filePath, 'utf8');
let changed = false;
for (const rep of replacements) {
if (content.includes(rep.from)) {
content = content.replaceAll(rep.from, rep.to);
changed = true;
}
}
if (changed) {
fs.writeFileSync(filePath, content);
console.log(`✅ Fixed imports in ${file}`);
} else {
console.log(`⚪ No changes in ${file}`);
}
}
}
fixImports();