Initial commit
Test / gate (push) Failing after 19m0s

This commit is contained in:
alexm committed 2026-11-12 22:23:54 -05:00
commit 401084bab3
265 files changed
+69224

No files matched your search

+74
View File
@@ -0,0 +1,74 @@
#!/usr/bin/env node
// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC
// SPDX-License-Identifier: Apache-2.0
/**
* Compare this repository's engines with a checkout of the course site.
*
* pixi run engines-diff ../course/static
*
* <static> is the course repository's static/ directory. This repository owns
* the engines and the course copies from here (pixi run engines-export), so
* this shows what the course has not taken yet. For each engine module (pseudo,
* asm86, shared) it compares the file the course would receive (src/engines/
* as written, or dist/engines/ for a module written in TypeScript) with the
* course's copy (the course's stylesheets are compared in pplus-web);
* prints whether they are the same, differ only in whitespace and line
* endings, or differ in content (with the number of changed lines, whitespace
* ignored), and lists files only one side has. It changes nothing.
*/
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { engineModules, ENGINE_DIRS } 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-diff <the course repository\'s static/ directory>');
process.exit(2);
}
const squash = (s) => s.replace(/\r/g, '').split('\n').map((l) => l.replace(/\s+/g, ' ').trim()).filter(Boolean);
/** Lines changed, whitespace ignored: the size of the symmetric difference of the two line multisets. */
function changed(a, b) {
const count = new Map();
for (const l of a) count.set(l, (count.get(l) || 0) + 1);
for (const l of b) count.set(l, (count.get(l) || 0) - 1);
let n = 0;
for (const v of count.values()) n += Math.abs(v);
return n;
}
function compare(ours, theirs) {
const a = fs.readFileSync(ours, 'utf8'), b = fs.readFileSync(theirs, 'utf8');
if (a === b) return { kind: 'same' };
const n = changed(squash(a), squash(b));
return n === 0 ? { kind: 'whitespace' } : { kind: 'content', n };
}
const rows = [];
const strip = (t) => t.replace(/\n\/\/# sourceMappingURL=.*\n?$/, '\n');
const mine = engineModules(ROOT);
for (const m of mine) {
const theirs = path.join(dir, 'js', m.dir, m.file);
if (!fs.existsSync(m.ours)) rows.push([m.label, 'not built: run pixi run build']);
else if (!fs.existsSync(theirs)) rows.push([m.label, 'only here']);
else {
const a = strip(fs.readFileSync(m.ours, 'utf8')), b = fs.readFileSync(theirs, 'utf8');
const r = a === b ? { kind: 'same' } : (changed(squash(a), squash(b)) === 0 ? { kind: 'whitespace' } : { kind: 'content', n: changed(squash(a), squash(b)) });
rows.push([m.label, r.kind === 'content' ? `differs: ${r.n} lines` : r.kind === 'whitespace' ? 'whitespace only' : 'same']);
}
}
for (const d of ENGINE_DIRS) {
const c = path.join(dir, 'js', d);
if (!fs.existsSync(c)) continue;
for (const f of fs.readdirSync(c).filter((x) => x.endsWith('.js')).sort()) {
if (!mine.some((m) => m.dir === d && m.file === f)) rows.push([`js/${d}/${f}`, 'only in the course']);
}
}
const w = Math.max(...rows.map((r) => r[0].length));
for (const [f, v] of rows) console.log(`${f.padEnd(w)} ${v}`);
const content = rows.filter((r) => r[1].startsWith('differs')).length;
console.log(`\n${rows.length} files: ${rows.filter((r) => r[1] === 'same').length} same, ${rows.filter((r) => r[1] === 'whitespace only').length} whitespace only, ${content} differ in content`);