36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Parse NOVEL schedule CSV to JSON (stdout or --out=file).
|
|
*
|
|
* Usage:
|
|
* node scripts/parse-novel-schedule-csv.js [--csv=path] [--out=path]
|
|
*/
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { parseNovelScheduleCsv } = require('../src/utils/parseNovelScheduleCsv');
|
|
|
|
function argValue(name, fallback) {
|
|
const hit = process.argv.find((a) => a.startsWith(`--${name}=`));
|
|
return hit ? hit.split('=').slice(1).join('=').trim() : fallback;
|
|
}
|
|
|
|
const defaultCsv = path.join(__dirname, '..', '..', 'novel2026-goa-7-8-aug.csv');
|
|
const csvPath = argValue('csv', defaultCsv);
|
|
const outPath = argValue('out', '');
|
|
|
|
if (!fs.existsSync(csvPath)) {
|
|
console.error(`CSV not found: ${csvPath}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const text = fs.readFileSync(csvPath, 'utf8');
|
|
const result = parseNovelScheduleCsv(text);
|
|
const json = JSON.stringify(result, null, 2);
|
|
|
|
if (outPath) {
|
|
fs.writeFileSync(outPath, `${json}\n`);
|
|
console.log(`Wrote ${outPath}`);
|
|
} else {
|
|
process.stdout.write(`${json}\n`);
|
|
}
|