(
module: Type | DynamicModule,
replOptions: ReplOptions = {},
)
| 10 | import type { ReplOptions } from 'repl'; |
| 11 | |
| 12 | export async function repl( |
| 13 | module: Type | DynamicModule, |
| 14 | replOptions: ReplOptions = {}, |
| 15 | ) { |
| 16 | const app = await NestFactory.createApplicationContext(module, { |
| 17 | abortOnError: false, |
| 18 | logger: new ReplLogger(), |
| 19 | }); |
| 20 | await app.init(); |
| 21 | |
| 22 | const replContext = new ReplContext(app); |
| 23 | Logger.log(REPL_INITIALIZED_MESSAGE); |
| 24 | |
| 25 | const _repl = await import('repl'); |
| 26 | const replServer = _repl.start({ |
| 27 | prompt: clc.green('> '), |
| 28 | ignoreUndefined: true, |
| 29 | ...replOptions, |
| 30 | }); |
| 31 | assignToObject(replServer.context, replContext.globalScope); |
| 32 | |
| 33 | defineDefaultCommandsOnRepl(replServer); |
| 34 | |
| 35 | replServer.on('exit', async () => { |
| 36 | await app.close(); |
| 37 | }); |
| 38 | |
| 39 | return replServer; |
| 40 | } |
no test coverage detected