@nestjs/core
Version:
Nest - modern, fast, powerful node.js web framework (@core)
30 lines (29 loc) • 1.11 kB
JavaScript
import { Logger } from '@nestjs/common';
import { NestFactory } from '../nest-factory.js';
import { assignToObject } from './assign-to-object.util.js';
import { REPL_INITIALIZED_MESSAGE } from './constants.js';
import { ReplContext } from './repl-context.js';
import { ReplLogger } from './repl-logger.js';
import { defineDefaultCommandsOnRepl } from './repl-native-commands.js';
import { clc } from '@nestjs/common/internal';
export async function repl(module, replOptions = {}) {
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,
...replOptions,
});
assignToObject(replServer.context, replContext.globalScope);
defineDefaultCommandsOnRepl(replServer);
replServer.on('exit', async () => {
await app.close();
});
return replServer;
}