This repository has been archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.ts
75 lines (62 loc) · 1.85 KB
/
console.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import repl from "node:repl";
import _ from "lodash";
import * as cron from "./app/cron.server";
import { db } from "./app/db.server";
import * as user from "./app/domain/user";
import { getClient, redis } from "./app/redis/redis.server";
import * as services from "./app/services";
import * as mails from "./app/mails";
const { APP_ENV, APP_VERSION } = process.env;
if (APP_ENV === "production") {
console.warn(`
===================================
=== You are on PRODUCTION !!! ===
=== You are on PRODUCTION !!! ===
=== You are on PRODUCTION !!! ===
===================================
`);
}
console.log(`
Grundsteuer Console
APP_ENV: ${APP_ENV}
APP_VERSION: ${APP_VERSION}
Type .exit to exit this console.
Type .examples to show a few usage examples.
Type .help for more help.
`);
const replServer = repl.start({ prompt: `${APP_ENV}> ` });
const initializeContext = (context: any) => {
context.env = process.env;
context.lodash = _;
context.db = db;
context.user = user;
context.redis = redis;
context.cron = cron;
context.getRedisClient = getClient;
context.services = services;
context.mails = mails;
};
initializeContext(replServer.context);
// eslint-disable-next-line @typescript-eslint/no-empty-function
replServer.setupHistory(".console_history", () => {});
replServer.on("reset", initializeContext);
replServer.on("exit", () => {
process.exit();
});
replServer.defineCommand("examples", {
help: "Show usage examples",
action() {
this.clearBufferedCommand();
console.log(`
Some examples to get you started:
> env
> lodash.times(10)
> await user.findUserByEmail("[email protected]")
> await user.deleteUserByEmail("[email protected]")
> await getRedisClient().keys("*")
Please read <PROJECT_ROOT>/console.ts to
understand what you can do in the console.
`);
this.displayPrompt();
},
});