46 lines
2.2 KiB
JavaScript
46 lines
2.2 KiB
JavaScript
#!/usr/bin/env node
|
|
// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
/**
|
|
* Copy this repository's language engines into a checkout of the course site.
|
|
*
|
|
* pixi run engines-export ../course/static
|
|
*
|
|
* This repository owns the engines (docs/engines.md); the course copies from
|
|
* here. <static> is the course repository's static/ directory. For each
|
|
* engine directory (pseudo, asm86, shared) every module goes to
|
|
* <static>/js/<directory>/: a JavaScript module as written in src/engines/,
|
|
* a TypeScript one (the prover, the parser, the checker, the interpreter) as built into dist/engines/, which
|
|
* is plain ES-module JavaScript the course's pages can import unchanged.
|
|
* Source maps are not copied. Prints what it wrote, and changes nothing else
|
|
* in the course. Review the course's diff before committing it there.
|
|
*/
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { engineModules } from './engines-files.mjs';
|
|
|
|
const ROOT = fileURLToPath(new URL('..', import.meta.url));
|
|
const dir = process.argv[2];
|
|
if (!dir || !fs.existsSync(path.join(dir, 'js'))) {
|
|
console.error('usage: pixi run engines-export <the course repository\'s static/ directory>');
|
|
process.exit(2);
|
|
}
|
|
|
|
let wrote = 0, same = 0, added = 0;
|
|
for (const m of engineModules(ROOT)) {
|
|
if (!fs.existsSync(m.ours)) {
|
|
console.error(`${m.label}: ${path.relative(ROOT, m.ours)} is missing; run pixi run build first`);
|
|
process.exit(1);
|
|
}
|
|
const target = path.join(dir, 'js', m.dir, m.file);
|
|
const text = fs.readFileSync(m.ours, 'utf8').replace(/\n\/\/# sourceMappingURL=.*\n?$/, '\n');
|
|
const before = fs.existsSync(target) ? fs.readFileSync(target, 'utf8') : null;
|
|
if (before === text) { same++; continue; }
|
|
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
fs.writeFileSync(target, text);
|
|
if (before === null) { added++; console.log(`added js/${m.dir}/${m.file}${m.built ? ' (built from TypeScript)' : ''}`); }
|
|
else { wrote++; console.log(`updated js/${m.dir}/${m.file}${m.built ? ' (built from TypeScript)' : ''}`); }
|
|
}
|
|
console.log(`\n${wrote} updated, ${added} added, ${same} already the same`);
|