'use strict';
const fs=require('fs'); const path=require('path'); const ROOT=path.join(__dirname,'..');
const req=['index.js','src/index.js','src/db.js','package.json','frontend/views','frontend/public']; let ok=true;
for(const rel of req){ if(!fs.existsSync(path.join(ROOT,rel))){ console.error('[check] Falta: '+rel); ok=false; }}
function scan(dir){ if(!fs.existsSync(dir)) return; for(const e of fs.readdirSync(dir,{withFileTypes:true})){ const p=path.join(dir,e.name); if(e.isDirectory()) scan(p); else if(e.name.endsWith('.js')){ try{ new Function(fs.readFileSync(p,'utf8')); }catch(err){ console.error('[check] Sintaxis invalida: '+path.relative(ROOT,p)+': '+err.message); ok=false; } } } }
scan(path.join(ROOT,'src')); scan(path.join(ROOT,'scripts'));// installer tiene plantillas generadas para NSIS/Windows; se valida en build real.
const pkg=JSON.parse(fs.readFileSync(path.join(ROOT,'package.json'),'utf8')); if(!pkg.version){console.error('[check] package.json sin version'); ok=false;}
if(!ok) process.exit(1); console.log('[check] Proyecto validado.');
