66 lines
1.7 KiB
JavaScript
66 lines
1.7 KiB
JavaScript
// This file allows using Node.js in combination with
|
|
// all available plugins. Usage: "node run <script>"
|
|
import * as util from "node:util";
|
|
import process from "node:process";
|
|
|
|
// Disable experimental warnings (Type Stripping, etc)
|
|
{
|
|
const { emit: originalEmit } = process;
|
|
const warnings = ["ExperimentalWarning"];
|
|
process.emit = function (event, error) {
|
|
return event === "warning" && warnings.includes(error.name)
|
|
? false
|
|
: originalEmit.apply(process, arguments);
|
|
};
|
|
}
|
|
|
|
// Init hooks
|
|
const hot = await import("./framework/hot.ts");
|
|
|
|
const console = hot.load("@paperclover/console");
|
|
globalThis.console.log = console.info;
|
|
globalThis.console.info = console.info;
|
|
globalThis.console.warn = console.warn;
|
|
globalThis.console.error = console.error;
|
|
globalThis.console.debug = console.scoped("dbg");
|
|
|
|
globalThis.UNWRAP = (t, ...args) => {
|
|
if (t == null) {
|
|
throw new Error(
|
|
args.length > 0 ? util.format(...args) : "UNWRAP(" + t + ")",
|
|
);
|
|
}
|
|
return t;
|
|
};
|
|
globalThis.ASSERT = (t, ...args) => {
|
|
if (!t) {
|
|
throw new Error(
|
|
args.length > 0 ? util.format(...args) : "Assertion Failed",
|
|
);
|
|
}
|
|
};
|
|
|
|
// Load with hooks
|
|
if (process.argv[1].startsWith(import.meta.filename.slice(0, -".js".length))) {
|
|
if (process.argv.length == 2) {
|
|
console.error("usage: node run <script> [...args]");
|
|
process.exit(1);
|
|
}
|
|
let found;
|
|
for (const dir of ["./", "./src/", "./framework/"]) {
|
|
try {
|
|
found = hot.resolveFrom(import.meta.filename, dir + process.argv[2]);
|
|
break;
|
|
} catch (e) {
|
|
continue;
|
|
}
|
|
}
|
|
if (!found) {
|
|
console.error("Cannot find script: " + process.argv[2]);
|
|
process.exit(1);
|
|
}
|
|
process.argv = [process.argv[0], ...process.argv.slice(2)];
|
|
hot.load(found).main?.();
|
|
}
|
|
|
|
export { hot };
|