nope-js-browser
Version:
NoPE Runtime for the Browser. For nodejs please use nope-js-node
33 lines (32 loc) • 1.08 kB
JavaScript
/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
* @create date 2021-07-27 15:45:00
* @modify date 2021-07-27 15:45:00
* @desc [description]
*/
import { start } from "repl";
import main from "./runNopeBackend";
/**
* Starts an interactive console with the loaded dispatcher.
*/
export async function repl(additionalArguments = []) {
const loader = await main(additionalArguments, {
// skipLoadingConfig: true
}, true);
const interactiveConsole = start({});
// Assing the context
interactiveConsole.context.dispatcher = loader.dispatcher;
interactiveConsole.context.loader = loader;
interactiveConsole.context.nope = require("../index.nodejs");
// Promise, that will be finished on exiting the interactive console.
const promise = new Promise((resolve) => {
interactiveConsole.once("exit", resolve);
});
await promise;
await loader.dispatcher.dispose();
}
// If requested As Main => Perform the Operation.
if (require.main === module) {
repl().catch(console.error);
}