48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Generate output HTML from template + data for space-exploration documents.
|
|
*
|
|
* Usage: node generate.mjs <docId>
|
|
* Example: node generate.mjs space-exploration-1
|
|
*
|
|
* Reads: docs/<docId>.template.html
|
|
* Reads: docs/<docId>.data.json (optional — if missing, copies template as-is)
|
|
* Writes: docs/<docId>.output.html
|
|
*/
|
|
|
|
import { readFileSync, writeFileSync, existsSync } from 'fs';
|
|
import { join, dirname } from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import { postGenerate } from '../../../src/scripts/post-generate.mjs';
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const docsDir = join(__dirname, '..', 'docs');
|
|
|
|
const docId = process.argv[2];
|
|
if (!docId) {
|
|
console.error('Usage: node generate.mjs <docId>');
|
|
process.exit(1);
|
|
}
|
|
|
|
const templatePath = join(docsDir, `${docId}.template.html`);
|
|
const dataPath = join(docsDir, `${docId}.data.json`);
|
|
const outputPath = join(docsDir, `${docId}.output.html`);
|
|
|
|
if (!existsSync(templatePath)) {
|
|
console.error(`Template not found: ${templatePath}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
let html = readFileSync(templatePath, 'utf-8');
|
|
|
|
// If data.json exists, apply it (space-exploration currently has no editor data)
|
|
if (existsSync(dataPath)) {
|
|
const data = JSON.parse(readFileSync(dataPath, 'utf-8'));
|
|
console.log(`Data file found with ${data.pages?.length || 0} pages — no transforms defined yet for space-exploration`);
|
|
}
|
|
|
|
writeFileSync(outputPath, html);
|
|
console.log(`Generated: ${outputPath}`);
|
|
await postGenerate(outputPath);
|