You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.0 KiB
67 lines
2.0 KiB
/**
|
|
* Repara los problemas generados por la conversión al patrón .ctx
|
|
*/
|
|
|
|
import { readFileSync, writeFileSync, readdirSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { dirname } from 'node:path';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
const terraDir = join(__dirname, '../src/uix/terra');
|
|
|
|
function findAllTsFiles(dir: string): string[] {
|
|
const files: string[] = [];
|
|
const entries = readdirSync(dir, { withFileTypes: true });
|
|
for (const entry of entries) {
|
|
const fullPath = join(dir, entry.name);
|
|
if (entry.isDirectory() && !entry.name.startsWith('.')) {
|
|
files.push(...findAllTsFiles(fullPath));
|
|
} else if (entry.isFile() && entry.name.endsWith('.svelte.ts')) {
|
|
files.push(fullPath);
|
|
}
|
|
}
|
|
return files;
|
|
}
|
|
|
|
function fixFile(filePath: string): boolean {
|
|
const content = readFileSync(filePath, 'utf-8');
|
|
const original = content;
|
|
let modified = content;
|
|
|
|
// 1. Eliminar líneas con "export ;" o ";"
|
|
modified = modified.replace(/^\s*export\s*;\s*\n?/gm, '');
|
|
modified = modified.replace(/^\s*;\s*\n?/gm, '');
|
|
|
|
// 2. Eliminar líneas duplicadas vacías consecutivas (más de 2)
|
|
modified = modified.replace(/\n{3,}/g, '\n\n');
|
|
|
|
// 3. Arreglar referencias a contextos antiguos que no se actualizaron
|
|
// CalendarRootContext.get() -> CalendarRootState.ctx.get()
|
|
modified = modified.replace(/CalendarRootContext\.get\(\)/g, 'CalendarRootState.ctx.get()');
|
|
|
|
if (modified !== original) {
|
|
writeFileSync(filePath, modified, 'utf-8');
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
const files = findAllTsFiles(terraDir);
|
|
let modified = 0;
|
|
|
|
console.log('🔧 Reparando archivos...\n');
|
|
|
|
for (const file of files) {
|
|
if (fixFile(file)) {
|
|
modified++;
|
|
const relPath = file.replace(/.*src\\uix\\terra\\/, '').replace(/\.svelte\.ts$/, '');
|
|
console.log(` ✅ ${relPath}`);
|
|
}
|
|
}
|
|
|
|
console.log(`\n📊 Resumen:`);
|
|
console.log(` Modificados: ${modified}`);
|
|
console.log(` Total procesados: ${files.length}`);
|