diff options
author | MCMXC <16797721+mcmxcdev@users.noreply.github.com> | 2024-02-10 18:19:14 -0700 |
---|---|---|
committer | Vijay A <vraravam@users.noreply.github.com> | 2024-02-13 06:59:44 +0530 |
commit | 7584d2d7a7110aef0331ebfa178b2295842c59fa (patch) | |
tree | 900cd71237e6231b57936fcce77ff229cd459041 /bin/console.ts | |
parent | upgrade recipes submodule (diff) | |
download | ferdium-server-7584d2d7a7110aef0331ebfa178b2295842c59fa.tar.gz ferdium-server-7584d2d7a7110aef0331ebfa178b2295842c59fa.tar.zst ferdium-server-7584d2d7a7110aef0331ebfa178b2295842c59fa.zip |
refactor: project maintenance
- work in progress
Diffstat (limited to 'bin/console.ts')
-rw-r--r-- | bin/console.ts | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/bin/console.ts b/bin/console.ts new file mode 100644 index 0000000..4b102ee --- /dev/null +++ b/bin/console.ts | |||
@@ -0,0 +1,47 @@ | |||
1 | /* | ||
2 | |-------------------------------------------------------------------------- | ||
3 | | Ace entry point | ||
4 | |-------------------------------------------------------------------------- | ||
5 | | | ||
6 | | The "console.ts" file is the entrypoint for booting the AdonisJS | ||
7 | | command-line framework and executing commands. | ||
8 | | | ||
9 | | Commands do not boot the application, unless the currently running command | ||
10 | | has "options.startApp" flag set to true. | ||
11 | | | ||
12 | */ | ||
13 | |||
14 | import 'reflect-metadata' | ||
15 | import { Ignitor, prettyPrintError } from '@adonisjs/core' | ||
16 | |||
17 | /** | ||
18 | * URL to the application root. AdonisJS need it to resolve | ||
19 | * paths to file and directories for scaffolding commands | ||
20 | */ | ||
21 | const APP_ROOT = new URL('../', import.meta.url) | ||
22 | |||
23 | /** | ||
24 | * The importer is used to import files in context of the | ||
25 | * application. | ||
26 | */ | ||
27 | const IMPORTER = (filePath: string) => { | ||
28 | if (filePath.startsWith('./') || filePath.startsWith('../')) { | ||
29 | return import(new URL(filePath, APP_ROOT).href) | ||
30 | } | ||
31 | return import(filePath) | ||
32 | } | ||
33 | |||
34 | new Ignitor(APP_ROOT, { importer: IMPORTER }) | ||
35 | .tap((app) => { | ||
36 | app.booting(async () => { | ||
37 | await import('#start/env') | ||
38 | }) | ||
39 | app.listen('SIGTERM', () => app.terminate()) | ||
40 | app.listenIf(app.managedByPm2, 'SIGINT', () => app.terminate()) | ||
41 | }) | ||
42 | .ace() | ||
43 | .handle(process.argv.splice(2)) | ||
44 | .catch((error) => { | ||
45 | process.exitCode = 1 | ||
46 | prettyPrintError(error) | ||
47 | }) | ||