From c486e684f2a50e8ede65432af9befa06444df9e6 Mon Sep 17 00:00:00 2001 From: Kuizuo Date: Sat, 18 Nov 2023 00:19:57 +0800 Subject: [PATCH] feat(api): repl mode --- apps/api/.gitignore | 2 ++ apps/api/package.json | 3 ++- apps/api/src/repl.ts | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 apps/api/src/repl.ts diff --git a/apps/api/.gitignore b/apps/api/.gitignore index 139637f..148449d 100644 --- a/apps/api/.gitignore +++ b/apps/api/.gitignore @@ -64,3 +64,5 @@ lerna-debug.log* !.vscode/tasks.json !.vscode/launch.json !.vscode/extensions.json + +.nestjs_repl_history diff --git a/apps/api/package.json b/apps/api/package.json index f2dfb1c..485ab09 100644 --- a/apps/api/package.json +++ b/apps/api/package.json @@ -9,7 +9,8 @@ "build": "nest build", "dev": "npm run start", "dev:debug": "npm run start:debug", - "start": "cross-env NODE_ENV=development nest start -w --path tsconfig.json -- ", + "repl": "npm run start -- --entryFile repl", + "start": "cross-env NODE_ENV=development nest start -w --path tsconfig.json", "start:debug": "cross-env NODE_ENV=development nest start --debug --watch", "start:prod": "cross-env NODE_ENV=production node dist/src/main", "prod": "cross-env NODE_ENV=production pm2-runtime start ecosystem.config.js", diff --git a/apps/api/src/repl.ts b/apps/api/src/repl.ts new file mode 100644 index 0000000..3aac090 --- /dev/null +++ b/apps/api/src/repl.ts @@ -0,0 +1,13 @@ +import { repl } from '@nestjs/core' + +import { AppModule } from './app.module' + +async function bootstrap() { + const replServer = await repl(AppModule) + replServer.setupHistory('.nestjs_repl_history', (err) => { + if (err) { + console.error(err) + } + }) +} +bootstrap()