aboutsummaryrefslogtreecommitdiffstats
path: root/bin/console.ts
diff options
context:
space:
mode:
Diffstat (limited to 'bin/console.ts')
-rw-r--r--bin/console.ts47
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
14import 'reflect-metadata'
15import { 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 */
21const APP_ROOT = new URL('../', import.meta.url)
22
23/**
24 * The importer is used to import files in context of the
25 * application.
26 */
27const 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
34new 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 })