nope/lib/cli/repl.ts
Martin Karkowski 39c50061dc # 1.0.26
- Fixes:
  - pub-sub-system: Fixed `_notify` and `_partialMatchingUpdate`
- Added:
  - pub-sub-system: Listeners receive now: topicOfContent (the path of the data that is extracted), topicOfChange (the path of the data that emitted teh update), topicOfSubscription (the subscription.),
  - nope repl: Added the context `nope`
2022-03-21 13:45:08 +01:00

49 lines
1.1 KiB
TypeScript

/**
* @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 run from "./runNopeBackend";
/**
* Starts an interactive console with the loaded dispatcher.
*/
export async function repl(
additionalArguments: {
help: string;
type: "string" | "number";
name: string | string;
defaultValue?: any;
}[] = []
) {
const loader = await run(
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);
}