microvium
Version:
A compact, embeddable scripting engine for microcontrollers for executing small scripts written in a subset of JavaScript.
104 lines • 3.42 kB
JavaScript
#!/usr/bin/env node
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// import yargs from 'yargs';
const argparse_1 = require("argparse");
const run_app_1 = require("./lib/run-app");
const process_1 = __importDefault(require("process"));
const utils_1 = require("./lib/utils");
const packageJSON = require('../package.json');
const argParse = new argparse_1.ArgumentParser({
version: packageJSON.version,
addHelp: true,
prog: 'microvium',
description: 'Microvium - A compact, embeddable scripting engine for microcontrollers for executing small scripts written in a subset of JavaScript.'
});
argParse.addArgument(['-e', '--eval'], {
metavar: '"script"',
dest: 'eval',
action: 'store',
help: 'Evaluate the given script text and output snapshot',
});
argParse.addArgument(['-s', '--snapshot'], {
metavar: 'FILENAME',
dest: 'snapshotFilename',
action: 'store',
help: 'Snapshot filename to use for output',
});
argParse.addArgument(['--no-snapshot'], {
action: 'storeTrue',
dest: 'noSnapshot',
help: 'Do not output a snapshot file',
});
// Debug mode is not finished
// argParse.addArgument(
// [ '--debug' ],
// {
// action: 'storeTrue',
// dest: 'debug',
// help: 'Start in debug mode',
// },
// );
argParse.addArgument(['--map-file'], {
metavar: 'FILENAME',
action: 'store',
dest: 'mapFile',
help: 'Generate map file (human-readable disassembly of snapshot bytecode)',
});
argParse.addArgument(['--output-disassembly'], {
action: 'storeTrue',
dest: 'outputDisassembly',
help: 'Output disassembly of snapshot bytecode file',
});
argParse.addArgument(['--generate-lib'], {
help: 'Interactively generate C runtime engine library',
action: 'storeTrue',
dest: 'generateLib',
});
argParse.addArgument(['--generate-port'], {
help: 'Interactively generate microvium port file (microvium_port.h)',
action: 'storeTrue',
dest: 'generatePort',
});
argParse.addArgument(['--output-bytes'], {
help: 'Output bytecode as comma-separated hex, suitable for use in a C constant',
action: 'storeTrue',
dest: 'outputBytes',
});
argParse.addArgument(['--output-il'], {
help: 'Output debug IL for each module',
action: 'storeTrue',
dest: 'outputIL',
});
argParse.addArgument(['--output-source-map'], {
help: 'Output file that maps bytecode offsets to source code locations',
action: 'storeTrue',
dest: 'outputSourceMap',
});
argParse.addArgument(['input'], {
nargs: '*',
help: 'Input file to run',
});
run();
async function run() {
try {
const args = argParse.parseArgs();
await (0, run_app_1.runApp)(args, false, () => argParse.printHelp());
}
catch (e) {
// fs.writeFileSync('error-details', e.toString());
if (e instanceof utils_1.MicroviumUsageError) {
console.error(e.message);
process_1.default.exit(1);
}
else {
console.error(`Microvium internal error (${e.message})`);
// console.error(e);
process_1.default.exit(1);
}
}
}
//# sourceMappingURL=cli.js.map