1350 files changed
+197
-941995
No files matched your search
+10
-10
@@ -1,10 +1,10 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* The fast loop for a Mojo program in mojo/local/: write it, run one command,
|
||||
* The fast loop for a Mojo program in library/mojo/local/: write it, run one command,
|
||||
* and have it run, be checked on the pinned compiler, be built into the app,
|
||||
* and be tested.
|
||||
*
|
||||
* pixi run play demo # one pass over mojo/local/demo.mojo
|
||||
* pixi run play demo # one pass over library/mojo/local/demo.mojo
|
||||
* pixi run play-watch demo # again on every save (tests off unless --test)
|
||||
* node scripts/play.mjs demo --no-verify # skip godbolt (offline, or a quick edit)
|
||||
* node scripts/play.mjs demo --no-test # skip the tests
|
||||
@@ -29,7 +29,7 @@ import path from 'node:path';
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||
|
||||
const ROOT = fileURLToPath(new URL('..', import.meta.url));
|
||||
const LOCAL = path.join(ROOT, 'mojo/local');
|
||||
const LOCAL = path.join(ROOT, 'library/mojo/local');
|
||||
const PY = process.env.PYTHON || 'python3';
|
||||
|
||||
const argv = process.argv.slice(2);
|
||||
@@ -46,7 +46,7 @@ function sh(cmd, args, { quiet = false } = {}) {
|
||||
|
||||
const available = (cmd) => sh(cmd, ['--version'], { quiet: true }).ok;
|
||||
|
||||
/** Exercises whose `mojoProgram` has no file in mojo/local/. */
|
||||
/** Exercises whose `mojoProgram` has no file in library/mojo/local/. */
|
||||
function danglingPrograms() {
|
||||
const dir = path.join(ROOT, 'src/exercises');
|
||||
const out = [];
|
||||
@@ -66,13 +66,13 @@ const read = (p) => (fs.existsSync(p) ? fs.readFileSync(p, 'utf8') : '');
|
||||
|
||||
async function pass(name) {
|
||||
const file = path.join(LOCAL, `${name}.mojo`);
|
||||
const rel = `mojo/local/${name}.mojo`;
|
||||
const rel = `library/mojo/local/${name}.mojo`;
|
||||
const report = [];
|
||||
const step = (what, status, note = '') => { report.push({ what, status, note }); };
|
||||
const heading = (s) => console.log(`\n▸ ${s}`);
|
||||
|
||||
if (!fs.existsSync(file)) {
|
||||
console.error(`play: ${rel} does not exist. Programs in mojo/local/: ${fs.readdirSync(LOCAL).filter((f) => f.endsWith('.mojo')).map((f) => f.replace(/\.mojo$/, '')).join(', ')}`);
|
||||
console.error(`play: ${rel} does not exist. Programs in library/mojo/local/: ${fs.readdirSync(LOCAL).filter((f) => f.endsWith('.mojo')).map((f) => f.replace(/\.mojo$/, '')).join(', ')}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -94,11 +94,11 @@ async function pass(name) {
|
||||
step('create exercise', 'ok', `src/exercises/${name}.ts`);
|
||||
}
|
||||
|
||||
// verify and status both rewrite src/mojo/generated/programs.ts from mojo/local/. An exercise that names a
|
||||
// verify and status both rewrite src/mojo/generated/programs.ts from library/mojo/local/. An exercise that names a
|
||||
// program with no file there would then make the whole catalog throw at import (src/core/catalog.ts), so stop first.
|
||||
const dangling = danglingPrograms();
|
||||
if (dangling.length) {
|
||||
step('exercises name real programs', 'FAILED', dangling.map((d) => `${d.exercise} names mojo/local/${d.program}.mojo, which does not exist`).join('; ') + '. Create the file, or remove `mojoProgram` from the exercise, then run this again. Nothing was regenerated.');
|
||||
step('exercises name real programs', 'FAILED', dangling.map((d) => `${d.exercise} names library/mojo/local/${d.program}.mojo, which does not exist`).join('; ') + '. Create the file, or remove `mojoProgram` from the exercise, then run this again. Nothing was regenerated.');
|
||||
return summarize(name, report);
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ function summarize(name, report) {
|
||||
}
|
||||
|
||||
if (!names.length && !watch) {
|
||||
console.error('usage: pixi run play <name> (or node scripts/play.mjs <name> [--watch] [--no-verify] [--no-test] [--test])\n <name> is a program in mojo/local/ (without .mojo). To make a new one: pixi run new-exercise <id>');
|
||||
console.error('usage: pixi run play <name> (or node scripts/play.mjs <name> [--watch] [--no-verify] [--no-test] [--test])\n <name> is a program in library/mojo/local/ (without .mojo). To make a new one: pixi run new-exercise <id>');
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ for (const n of names) if (!(await pass(n))) failed = true;
|
||||
|
||||
if (watch) {
|
||||
const only = new Set(names);
|
||||
console.log(`\nwatching mojo/local/${only.size ? ` for ${[...only].join(', ')}` : ''} (Ctrl+C to stop)`);
|
||||
console.log(`\nwatching library/mojo/local/${only.size ? ` for ${[...only].join(', ')}` : ''} (Ctrl+C to stop)`);
|
||||
const queue = new Set();
|
||||
let busy = false, timer = null;
|
||||
const drain = async () => {
|
||||
|
||||
Reference in new issue
Block a user