import {Directive} from '../Directive' import * as colors from 'colors/safe' import * as repl from 'repl' import {DependencyKey} from '../../di' /** * Launch an interactive REPL shell from within the application. * This is very useful for debugging and testing things during development. */ export class ShellDirective extends Directive { protected options: any = { welcome: `powered by Extollo, © ${(new Date()).getFullYear()} Garrett Mills\nAccess your application using the "app" global.`, prompt: `${colors.blue('(')}extollo${colors.blue(') ➤ ')}`, } /** * The created Node.js REPL server. * @protected */ protected repl?: repl.REPLServer getDescription(): string { return 'launch an interactive shell inside your application' } getKeywords(): string | string[] { return ['shell'] } getHelpText(): string { return '' } async handle(): Promise { const state: any = { app: this.app(), make: (target: DependencyKey, ...parameters: any[]) => this.make(target, ...parameters), } await new Promise(res => { this.nativeOutput(this.options.welcome) this.repl = repl.start(this.options.prompt) Object.assign(this.repl.context, state) this.repl.on('exit', () => res()) }) } }