diff options
Diffstat (limited to 'bin')
-rw-r--r-- | bin/console.ts | 47 | ||||
-rw-r--r-- | bin/server.ts | 45 | ||||
-rw-r--r-- | bin/test.ts | 60 |
3 files changed, 152 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 | }) | ||
diff --git a/bin/server.ts b/bin/server.ts new file mode 100644 index 0000000..fe0fefb --- /dev/null +++ b/bin/server.ts | |||
@@ -0,0 +1,45 @@ | |||
1 | /* | ||
2 | |-------------------------------------------------------------------------- | ||
3 | | HTTP server entrypoint | ||
4 | |-------------------------------------------------------------------------- | ||
5 | | | ||
6 | | The "server.ts" file is the entrypoint for starting the AdonisJS HTTP | ||
7 | | server. Either you can run this file directly or use the "serve" | ||
8 | | command to run this file and monitor file changes | ||
9 | | | ||
10 | */ | ||
11 | |||
12 | import 'reflect-metadata' | ||
13 | import { Ignitor, prettyPrintError } from '@adonisjs/core' | ||
14 | |||
15 | /** | ||
16 | * URL to the application root. AdonisJS need it to resolve | ||
17 | * paths to file and directories for scaffolding commands | ||
18 | */ | ||
19 | const APP_ROOT = new URL('../', import.meta.url) | ||
20 | |||
21 | /** | ||
22 | * The importer is used to import files in context of the | ||
23 | * application. | ||
24 | */ | ||
25 | const IMPORTER = (filePath: string) => { | ||
26 | if (filePath.startsWith('./') || filePath.startsWith('../')) { | ||
27 | return import(new URL(filePath, APP_ROOT).href) | ||
28 | } | ||
29 | return import(filePath) | ||
30 | } | ||
31 | |||
32 | new Ignitor(APP_ROOT, { importer: IMPORTER }) | ||
33 | .tap((app) => { | ||
34 | app.booting(async () => { | ||
35 | await import('#start/env') | ||
36 | }) | ||
37 | app.listen('SIGTERM', () => app.terminate()) | ||
38 | app.listenIf(app.managedByPm2, 'SIGINT', () => app.terminate()) | ||
39 | }) | ||
40 | .httpServer() | ||
41 | .start() | ||
42 | .catch((error) => { | ||
43 | process.exitCode = 1 | ||
44 | prettyPrintError(error) | ||
45 | }) | ||
diff --git a/bin/test.ts b/bin/test.ts new file mode 100644 index 0000000..fe7e950 --- /dev/null +++ b/bin/test.ts | |||
@@ -0,0 +1,60 @@ | |||
1 | /* | ||
2 | |-------------------------------------------------------------------------- | ||
3 | | Test runner entrypoint | ||
4 | |-------------------------------------------------------------------------- | ||
5 | | | ||
6 | | The "test.ts" file is the entrypoint for running tests using Japa. | ||
7 | | | ||
8 | | Either you can run this file directly or use the "test" | ||
9 | | command to run this file and monitor file changes. | ||
10 | | | ||
11 | */ | ||
12 | |||
13 | process.env.NODE_ENV = 'test' | ||
14 | |||
15 | import 'reflect-metadata' | ||
16 | import { Ignitor, prettyPrintError } from '@adonisjs/core' | ||
17 | import { configure, processCLIArgs, run } from '@japa/runner' | ||
18 | |||
19 | /** | ||
20 | * URL to the application root. AdonisJS need it to resolve | ||
21 | * paths to file and directories for scaffolding commands | ||
22 | */ | ||
23 | const APP_ROOT = new URL('../', import.meta.url) | ||
24 | |||
25 | /** | ||
26 | * The importer is used to import files in context of the | ||
27 | * application. | ||
28 | */ | ||
29 | const IMPORTER = (filePath: string) => { | ||
30 | if (filePath.startsWith('./') || filePath.startsWith('../')) { | ||
31 | return import(new URL(filePath, APP_ROOT).href) | ||
32 | } | ||
33 | return import(filePath) | ||
34 | } | ||
35 | |||
36 | new Ignitor(APP_ROOT, { importer: IMPORTER }) | ||
37 | .tap((app) => { | ||
38 | app.booting(async () => { | ||
39 | await import('#start/env') | ||
40 | }) | ||
41 | app.listen('SIGTERM', () => app.terminate()) | ||
42 | app.listenIf(app.managedByPm2, 'SIGINT', () => app.terminate()) | ||
43 | }) | ||
44 | .testRunner() | ||
45 | .configure(async (app) => { | ||
46 | const { runnerHooks, ...config } = await import('../tests/bootstrap.js') | ||
47 | |||
48 | processCLIArgs(process.argv.splice(2)) | ||
49 | configure({ | ||
50 | ...app.rcFile.tests, | ||
51 | ...config, | ||
52 | setup: runnerHooks.setup, | ||
53 | teardown: [...runnerHooks.teardown, () => app.terminate()], | ||
54 | }) | ||
55 | }) | ||
56 | .run(() => run()) | ||
57 | .catch((error) => { | ||
58 | process.exitCode = 1 | ||
59 | prettyPrintError(error) | ||
60 | }) | ||