/
repl.ts
27 lines (23 loc) 路 889 Bytes
/
repl.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { DynamicModule, Logger, Type } from '@nestjs/common';
import { clc } from '@nestjs/common/utils/cli-colors.util';
import { NestFactory } from '../nest-factory';
import { assignToObject } from './assign-to-object.util';
import { REPL_INITIALIZED_MESSAGE } from './constants';
import { ReplContext } from './repl-context';
import { ReplLogger } from './repl-logger';
export async function repl(module: Type | DynamicModule) {
const app = await NestFactory.createApplicationContext(module, {
abortOnError: false,
logger: new ReplLogger(),
});
await app.init();
const replContext = new ReplContext(app);
Logger.log(REPL_INITIALIZED_MESSAGE);
const _repl = await import('repl');
const replServer = _repl.start({
prompt: clc.green('> '),
ignoreUndefined: true,
});
assignToObject(replServer.context, replContext.globalScope);
return replServer;
}