summaryrefslogtreecommitdiff
path: root/server/console.ts
diff options
context:
space:
mode:
authorJoseph Ditton <jditton.atomic@gmail.com>2021-11-22 14:21:53 -0700
committerJoseph Ditton <jditton.atomic@gmail.com>2021-11-22 14:21:53 -0700
commit4ae4e874689a71e33cdd7a5799fc0c85c4861367 (patch)
treed60c5d5f05ce0d0574bc168084e2b014ee999c1b /server/console.ts
parent3902da1747a3e32db0b67f1162eafd4860b3d27a (diff)
downloadlocchat-4ae4e874689a71e33cdd7a5799fc0c85c4861367.tar.gz
locchat-4ae4e874689a71e33cdd7a5799fc0c85c4861367.zip
adds start for console
Diffstat (limited to 'server/console.ts')
-rw-r--r--server/console.ts39
1 files changed, 39 insertions, 0 deletions
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();