mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 06:56:20 +00:00
🆙 IT ==> ENG and Remove the base path (this should a user do manual)
This commit is contained in:
+2
-2
@@ -7,8 +7,8 @@
|
||||
"configure": "node scripts/configure-json.mjs",
|
||||
"prestart": "node scripts/configure-json.mjs --if-missing",
|
||||
"prebuild": "node scripts/configure-json.mjs --if-missing && node scripts/write-asset-loader.mjs",
|
||||
"start": "vite --base=/nitro/ --host",
|
||||
"build": "vite build --base=/nitro/ && node scripts/minify-dist.mjs",
|
||||
"start": "vite --host",
|
||||
"build": "vite build && node scripts/minify-dist.mjs",
|
||||
"build:prod": "npx browserslist@latest --update-db && yarn build",
|
||||
"eslint": "eslint ./src"
|
||||
},
|
||||
|
||||
+14
-32
@@ -3,21 +3,17 @@ import { existsSync, readFileSync, writeFileSync } from 'fs';
|
||||
import { resolve } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import readline from 'readline';
|
||||
|
||||
const SCRIPT_DIR = fileURLToPath(new URL('.', import.meta.url));
|
||||
const PROJECT_ROOT = resolve(SCRIPT_DIR, '..');
|
||||
const CONFIG_FILE = resolve(PROJECT_ROOT, '.nitro-build.json');
|
||||
const VALID_MODES = new Set(['legacy', 'json5']);
|
||||
const DEFAULT_MODE = 'json5';
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
const ifMissing = args.includes('--if-missing');
|
||||
const nonInteractive = args.includes('--non-interactive') || !process.stdin.isTTY;
|
||||
|
||||
const readExisting = () =>
|
||||
{
|
||||
if(!existsSync(CONFIG_FILE)) return null;
|
||||
|
||||
try
|
||||
{
|
||||
const raw = readFileSync(CONFIG_FILE, 'utf8');
|
||||
@@ -25,10 +21,8 @@ const readExisting = () =>
|
||||
if(parsed && VALID_MODES.has(parsed.jsonMode)) return parsed;
|
||||
}
|
||||
catch {}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const writeChoice = (mode) =>
|
||||
{
|
||||
const payload = {
|
||||
@@ -37,16 +31,14 @@ const writeChoice = (mode) =>
|
||||
};
|
||||
writeFileSync(CONFIG_FILE, `${ JSON.stringify(payload, null, 2) }\n`, 'utf8');
|
||||
};
|
||||
|
||||
const printBanner = () =>
|
||||
{
|
||||
const line = '═'.repeat(60);
|
||||
process.stdout.write(`\n${ line }\n Nitro V3 — JSON mode configuration\n${ line }\n\n`);
|
||||
process.stdout.write('I file di configurazione (renderer-config, ui-config, gamedata)\npossono essere parsati in due modi:\n\n');
|
||||
process.stdout.write(' 1) JSON5 (consigliato — accetta commenti, trailing comma,\n single quote, identifier non quotati)\n');
|
||||
process.stdout.write(' 2) JSON (legacy strict — solo JSON valido standard)\n\n');
|
||||
process.stdout.write('Configuration files (renderer-config, ui-config, gamedata)\ncan be parsed in two ways:\n\n');
|
||||
process.stdout.write(' 1) JSON5 (recommended — accepts comments, trailing commas,\n single quotes, unquoted identifiers)\n');
|
||||
process.stdout.write(' 2) JSON (legacy strict — only standard valid JSON)\n\n');
|
||||
};
|
||||
|
||||
const normalizeAnswer = (raw) =>
|
||||
{
|
||||
const v = (raw || '').trim().toLowerCase();
|
||||
@@ -54,67 +46,57 @@ const normalizeAnswer = (raw) =>
|
||||
if(v === '2' || v === 'json' || v === 'legacy' || v === 'n' || v === 'no') return 'legacy';
|
||||
return null;
|
||||
};
|
||||
|
||||
const promptUser = () => new Promise(resolveFn =>
|
||||
{
|
||||
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
||||
|
||||
const ask = () =>
|
||||
{
|
||||
rl.question('Scelta [1=JSON5]: ', answer =>
|
||||
rl.question('Choice [1=JSON5]: ', answer =>
|
||||
{
|
||||
const normalized = normalizeAnswer(answer);
|
||||
if(normalized === null)
|
||||
{
|
||||
process.stdout.write(' ↳ Risposta non valida. Inserisci 1, 2, json5 o json.\n');
|
||||
process.stdout.write(' ↳ Invalid response. Please enter 1, 2, json5 or json.\n');
|
||||
return ask();
|
||||
}
|
||||
rl.close();
|
||||
resolveFn(normalized);
|
||||
});
|
||||
};
|
||||
|
||||
ask();
|
||||
});
|
||||
|
||||
const main = async () =>
|
||||
{
|
||||
const existing = readExisting();
|
||||
|
||||
if(ifMissing && existing)
|
||||
{
|
||||
process.stdout.write(`[configure-json] modalità già configurata: ${ existing.jsonMode } (skip)\n`);
|
||||
process.stdout.write(`[configure-json] mode already configured: ${ existing.jsonMode } (skip)\n`);
|
||||
return;
|
||||
}
|
||||
|
||||
if(nonInteractive)
|
||||
{
|
||||
const mode = existing?.jsonMode || DEFAULT_MODE;
|
||||
writeChoice(mode);
|
||||
process.stdout.write(`[configure-json] non interattivo — salvato: ${ mode }\n`);
|
||||
process.stdout.write(`[configure-json] non-interactive — saved: ${ mode }\n`);
|
||||
return;
|
||||
}
|
||||
|
||||
printBanner();
|
||||
if(existing) process.stdout.write(`Modalità corrente: ${ existing.jsonMode }\n\n`);
|
||||
|
||||
if(existing) process.stdout.write(`Current mode: ${ existing.jsonMode }\n\n`);
|
||||
const choice = await promptUser();
|
||||
writeChoice(choice);
|
||||
|
||||
process.stdout.write(`\n✓ Salvato in .nitro-build.json — modalità: ${ choice }\n`);
|
||||
process.stdout.write(`\n✓ Saved to .nitro-build.json — mode: ${ choice }\n`);
|
||||
if(choice === 'legacy')
|
||||
{
|
||||
process.stdout.write(' Attenzione: i file di config devono essere JSON valido stretto\n (no commenti, no trailing comma).\n');
|
||||
process.stdout.write(' Warning: config files must be strict valid JSON\n (no comments, no trailing commas).\n');
|
||||
}
|
||||
else
|
||||
{
|
||||
process.stdout.write(' JSON5 attivo: puoi usare commenti, trailing comma e single quote\n nei file di configurazione.\n');
|
||||
process.stdout.write(' JSON5 active: you can use comments, trailing commas and single quotes\n in configuration files.\n');
|
||||
}
|
||||
process.stdout.write('\n Per cambiare modalità in futuro: yarn configure\n\n');
|
||||
process.stdout.write('\n To change mode in the future: yarn configure\n\n');
|
||||
};
|
||||
|
||||
main().catch(err =>
|
||||
{
|
||||
process.stderr.write(`[configure-json] errore: ${ err?.message || err }\n`);
|
||||
process.stderr.write(`[configure-json] error: ${ err?.message || err }\n`);
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user