From 4ae4e874689a71e33cdd7a5799fc0c85c4861367 Mon Sep 17 00:00:00 2001 From: Joseph Ditton Date: Mon, 22 Nov 2021 14:21:53 -0700 Subject: adds start for console --- server/console.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 server/console.ts (limited to 'server/console.ts') diff --git a/server/console.ts b/server/console.ts new file mode 100644 index 0000000..485789a --- /dev/null +++ b/server/console.ts @@ -0,0 +1,39 @@ +import 'dotenv/config'; +import { NestFactory } from '@nestjs/core'; +import * as repl from 'repl'; +import * as Logger from 'purdy'; + +const LOGGER_OPTIONS = { + indent: 2, + depth: 1, +}; + +class InteractiveNestJS { + async run() { + // create the application context + // eslint-disable-next-line @typescript-eslint/no-var-requires + const targetModule = require(`${__dirname}/app.module`); + const applicationContext = await NestFactory.createApplicationContext( + // tslint:disable-next-line: no-string-literal + targetModule['AppModule'], + ); + // eslint-disable-next-line @typescript-eslint/no-var-requires + const awaitOutside = require('await-outside'); + // start node repl + const server = repl.start({ + useColors: true, + prompt: '> ', + writer: replWriter, + ignoreUndefined: true, + }); + server.context.app = applicationContext; + awaitOutside.addAwaitOutsideToReplServer(server); + } +} + +function replWriter(value: any): string { + return Logger.stringify(value, LOGGER_OPTIONS); +} + +const session = new InteractiveNestJS(); +session.run(); -- cgit v1.2.3-70-g09d2