@adonisjs/core 6.1.5-2 → 6.1.5-21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/build/commands/build.d.ts +10 -0
  2. package/build/commands/build.js +65 -22
  3. package/build/commands/commands.json +1 -1
  4. package/build/commands/configure.d.ts +30 -3
  5. package/build/commands/configure.js +103 -25
  6. package/build/commands/eject.d.ts +4 -0
  7. package/build/commands/eject.js +16 -8
  8. package/build/commands/generate_key.d.ts +4 -0
  9. package/build/commands/generate_key.js +15 -8
  10. package/build/commands/inspect_rcfile.d.ts +9 -0
  11. package/build/commands/inspect_rcfile.js +36 -0
  12. package/build/commands/list/routes.d.ts +23 -0
  13. package/build/commands/list/routes.js +29 -13
  14. package/build/commands/main.d.ts +4 -0
  15. package/build/commands/make/command.d.ts +7 -1
  16. package/build/commands/make/command.js +20 -7
  17. package/build/commands/make/controller.d.ts +10 -1
  18. package/build/commands/make/controller.js +35 -14
  19. package/build/commands/make/event.d.ts +7 -1
  20. package/build/commands/make/event.js +20 -8
  21. package/build/commands/make/exception.d.ts +14 -0
  22. package/build/commands/make/exception.js +37 -0
  23. package/build/commands/make/listener.d.ts +8 -1
  24. package/build/commands/make/listener.js +28 -12
  25. package/build/commands/make/middleware.d.ts +8 -1
  26. package/build/commands/make/middleware.js +21 -8
  27. package/build/commands/make/preload.d.ts +22 -0
  28. package/build/commands/make/preload.js +99 -0
  29. package/build/commands/make/provider.d.ts +7 -1
  30. package/build/commands/make/provider.js +28 -8
  31. package/build/commands/make/service.d.ts +14 -0
  32. package/build/commands/make/service.js +37 -0
  33. package/build/commands/make/test.d.ts +10 -1
  34. package/build/commands/make/test.js +46 -10
  35. package/build/commands/make/validator.d.ts +14 -0
  36. package/build/commands/make/validator.js +37 -0
  37. package/build/commands/make/view.d.ts +14 -0
  38. package/build/commands/make/view.js +37 -0
  39. package/build/commands/repl.d.ts +14 -0
  40. package/build/commands/repl.js +30 -0
  41. package/build/commands/serve.d.ts +12 -0
  42. package/build/commands/serve.js +78 -27
  43. package/build/commands/test.d.ts +32 -0
  44. package/build/commands/test.js +203 -0
  45. package/build/factories/app.js +8 -0
  46. package/build/factories/bodyparser.js +8 -0
  47. package/build/factories/core/ace.d.ts +4 -1
  48. package/build/factories/core/ace.js +11 -0
  49. package/build/factories/core/ignitor.d.ts +20 -1
  50. package/build/factories/core/ignitor.js +35 -1
  51. package/build/factories/core/main.js +8 -0
  52. package/build/factories/core/test_utils.d.ts +4 -1
  53. package/build/factories/core/test_utils.js +11 -0
  54. package/build/factories/encryption.js +8 -0
  55. package/build/factories/events.js +8 -0
  56. package/build/factories/hash.js +8 -0
  57. package/build/factories/http.js +8 -0
  58. package/build/factories/logger.js +8 -0
  59. package/build/factories/stubs.d.ts +10 -0
  60. package/build/factories/stubs.js +23 -1
  61. package/build/index.d.ts +6 -2
  62. package/build/index.js +14 -1
  63. package/build/modules/ace/codemods.d.ts +54 -0
  64. package/build/modules/ace/codemods.js +133 -0
  65. package/build/modules/ace/commands.d.ts +48 -0
  66. package/build/modules/ace/commands.js +54 -0
  67. package/build/modules/ace/create_kernel.d.ts +9 -0
  68. package/build/modules/ace/create_kernel.js +32 -1
  69. package/build/modules/ace/kernel.d.ts +4 -0
  70. package/build/modules/ace/kernel.js +12 -0
  71. package/build/modules/ace/main.js +8 -0
  72. package/build/modules/ace/shell.d.ts +9 -1
  73. package/build/modules/ace/shell.js +21 -0
  74. package/build/modules/app.js +8 -0
  75. package/build/modules/bodyparser/bodyparser_middleware.d.ts +4 -0
  76. package/build/modules/bodyparser/bodyparser_middleware.js +12 -0
  77. package/build/modules/bodyparser/main.js +8 -0
  78. package/build/modules/config.js +8 -0
  79. package/build/modules/container.js +8 -0
  80. package/build/modules/encryption.js +8 -0
  81. package/build/modules/env.js +8 -0
  82. package/build/modules/events.js +8 -0
  83. package/build/modules/hash/define_config.d.ts +4 -0
  84. package/build/modules/hash/define_config.js +23 -0
  85. package/build/modules/hash/drivers/argon.d.ts +1 -0
  86. package/build/modules/hash/drivers/argon.js +9 -0
  87. package/build/modules/hash/drivers/bcrypt.d.ts +1 -0
  88. package/build/modules/hash/drivers/bcrypt.js +9 -0
  89. package/build/modules/hash/drivers/scrypt.d.ts +1 -0
  90. package/build/modules/hash/drivers/scrypt.js +9 -0
  91. package/build/modules/hash/drivers_collection.d.ts +16 -4
  92. package/build/modules/hash/drivers_collection.js +31 -8
  93. package/build/modules/hash/main.d.ts +1 -0
  94. package/build/modules/hash/main.js +9 -0
  95. package/build/modules/http/main.d.ts +2 -0
  96. package/build/modules/http/main.js +10 -0
  97. package/build/modules/http/request_validator.d.ts +34 -0
  98. package/build/modules/http/request_validator.js +66 -0
  99. package/build/modules/logger.js +8 -0
  100. package/build/modules/repl.d.ts +1 -0
  101. package/build/modules/repl.js +9 -0
  102. package/build/providers/app_provider.d.ts +31 -2
  103. package/build/providers/app_provider.js +44 -15
  104. package/build/providers/edge_provider.d.ts +31 -0
  105. package/build/providers/edge_provider.js +69 -0
  106. package/build/providers/hash_provider.d.ts +22 -2
  107. package/build/providers/hash_provider.js +49 -7
  108. package/build/providers/http_provider.d.ts +17 -0
  109. package/build/providers/http_provider.js +26 -1
  110. package/build/providers/repl_provider.d.ts +13 -0
  111. package/build/providers/repl_provider.js +98 -0
  112. package/build/providers/vinejs_provider.d.ts +33 -0
  113. package/build/providers/vinejs_provider.js +84 -0
  114. package/build/services/ace.js +15 -0
  115. package/build/services/app.d.ts +8 -0
  116. package/build/services/app.js +16 -0
  117. package/build/services/config.js +11 -0
  118. package/build/services/emitter.js +13 -2
  119. package/build/services/encryption.js +13 -2
  120. package/build/services/hash.js +13 -2
  121. package/build/services/logger.js +13 -2
  122. package/build/services/repl.d.ts +3 -0
  123. package/build/services/repl.js +18 -0
  124. package/build/services/router.js +13 -2
  125. package/build/services/server.js +13 -2
  126. package/build/services/test_utils.js +15 -0
  127. package/build/src/cli_formatters/routes_list.d.ts +24 -1
  128. package/build/src/cli_formatters/routes_list.js +118 -0
  129. package/build/src/debug.d.ts +1 -1
  130. package/build/src/debug.js +8 -0
  131. package/build/src/exceptions.d.ts +1 -0
  132. package/build/src/exceptions.js +9 -0
  133. package/build/src/helpers/is.js +8 -0
  134. package/build/src/helpers/main.d.ts +1 -1
  135. package/build/src/helpers/main.js +9 -1
  136. package/build/src/helpers/parse_binding_reference.d.ts +40 -0
  137. package/build/src/helpers/parse_binding_reference.js +60 -0
  138. package/build/src/helpers/string.d.ts +26 -0
  139. package/build/src/helpers/string.js +15 -0
  140. package/build/src/helpers/types.d.ts +114 -16
  141. package/build/src/helpers/types.js +13 -0
  142. package/build/src/ignitor/ace.d.ts +12 -0
  143. package/build/src/ignitor/ace.js +50 -1
  144. package/build/src/ignitor/http.d.ts +9 -2
  145. package/build/src/ignitor/http.js +67 -0
  146. package/build/src/ignitor/main.d.ts +29 -1
  147. package/build/src/ignitor/main.js +56 -0
  148. package/build/src/ignitor/test.d.ts +10 -0
  149. package/build/src/ignitor/test.js +25 -0
  150. package/build/src/internal_helpers.d.ts +12 -5
  151. package/build/src/internal_helpers.js +35 -7
  152. package/build/src/test_utils/http.d.ts +10 -2
  153. package/build/src/test_utils/http.js +19 -0
  154. package/build/src/test_utils/main.d.ts +21 -3
  155. package/build/src/test_utils/main.js +27 -1
  156. package/build/src/types.d.ts +65 -4
  157. package/build/src/types.js +8 -0
  158. package/build/stubs/main.js +10 -0
  159. package/build/stubs/make/exception/main.stub +10 -0
  160. package/build/stubs/make/preload_file/main.stub +4 -0
  161. package/build/stubs/make/service/main.stub +4 -0
  162. package/build/stubs/make/validator/main.stub +5 -0
  163. package/build/stubs/make/view/main.stub +4 -0
  164. package/build/toolkit/commands/index_commands.d.ts +4 -0
  165. package/build/toolkit/commands/index_commands.js +13 -5
  166. package/build/toolkit/main.js +11 -0
  167. package/build/types/ace.js +8 -0
  168. package/build/types/app.js +8 -0
  169. package/build/types/bodyparser.js +8 -0
  170. package/build/types/container.js +8 -0
  171. package/build/types/encryption.js +8 -0
  172. package/build/types/events.js +8 -0
  173. package/build/types/hash.js +8 -0
  174. package/build/types/http.d.ts +7 -0
  175. package/build/types/http.js +8 -0
  176. package/build/types/logger.js +8 -0
  177. package/build/types/repl.d.ts +1 -0
  178. package/build/types/repl.js +9 -0
  179. package/package.json +83 -121
  180. package/build/commands/make/_base.d.ts +0 -6
  181. package/build/commands/make/_base.js +0 -19
  182. package/build/legacy/validator.d.ts +0 -1
  183. package/build/legacy/validator.js +0 -1
  184. package/build/modules/http.d.ts +0 -1
  185. package/build/modules/http.js +0 -1
  186. package/build/src/helpers/string_builder.d.ts +0 -23
  187. package/build/src/helpers/string_builder.js +0 -86
  188. package/build/stubs/index.js +0 -2
  189. /package/build/stubs/{index.d.ts → main.d.ts} +0 -0
@@ -2,9 +2,19 @@ import type { ApplicationService } from '../src/types.js';
2
2
  type FactoryParameters = {
3
3
  app: ApplicationService;
4
4
  };
5
+ /**
6
+ * Prepares stubs from "@adonisjs/core" package. We do not publish this class as it
7
+ * is for internal testing only using the "stubsRoot" of the core package
8
+ */
5
9
  export declare class StubsFactory {
6
10
  #private;
11
+ /**
12
+ * Merge custom factory parameters
13
+ */
7
14
  merge(params: Partial<FactoryParameters>): this;
15
+ /**
16
+ * Prepares a stub
17
+ */
8
18
  prepare(stubPath: string, data: Record<string, any>): Promise<{
9
19
  contents: any;
10
20
  destination: any;
@@ -1,18 +1,40 @@
1
+ /*
2
+ * @adonisjs/core
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
1
9
  import { AppFactory } from '@adonisjs/application/factories';
2
10
  import { stubsRoot } from '../index.js';
11
+ /**
12
+ * Prepares stubs from "@adonisjs/core" package. We do not publish this class as it
13
+ * is for internal testing only using the "stubsRoot" of the core package
14
+ */
3
15
  export class StubsFactory {
4
16
  #parameters = {};
17
+ /**
18
+ * Returns an instance of application
19
+ */
5
20
  #getApp() {
6
21
  return this.#parameters.app || new AppFactory().create(new URL('./', import.meta.url), () => { });
7
22
  }
23
+ /**
24
+ * Merge custom factory parameters
25
+ */
8
26
  merge(params) {
9
27
  this.#parameters = Object.assign(this.#parameters, params);
10
28
  return this;
11
29
  }
30
+ /**
31
+ * Prepares a stub
32
+ */
12
33
  async prepare(stubPath, data) {
13
34
  const app = this.#getApp();
14
35
  await app.init();
15
- const stub = await app.stubs.build(stubPath, {
36
+ const stubs = await app.stubs.create();
37
+ const stub = await stubs.build(stubPath, {
16
38
  source: stubsRoot,
17
39
  });
18
40
  return stub.prepare(data);
package/build/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- export { stubsRoot } from './stubs/index.js';
1
+ /// <reference types="@types/node" resolution-mode="require"/>
2
+ export { stubsRoot } from './stubs/main.js';
3
3
  export { inject } from './modules/container.js';
4
4
  export { Ignitor } from './src/ignitor/main.js';
5
5
  export declare const errors: {
@@ -140,4 +140,8 @@ export declare const errors: {
140
140
  E_INSECURE_APP_KEY: new (args?: any, options?: ErrorOptions | undefined) => import("@poppinss/utils").Exception;
141
141
  E_MISSING_APP_KEY: new (args?: any, options?: ErrorOptions | undefined) => import("@poppinss/utils").Exception;
142
142
  };
143
+ /**
144
+ * Pretty prints an error with colorful output using
145
+ * Youch terminal
146
+ */
143
147
  export declare function prettyPrintError(error: any): Promise<void>;
package/build/index.js CHANGED
@@ -1,9 +1,17 @@
1
+ /*
2
+ * @adonisjs/core
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
1
9
  import { errors as aceErrors } from '@adonisjs/ace';
2
10
  import { errors as envErrors } from '@adonisjs/env';
3
11
  import { errors as appErrors } from '@adonisjs/application';
4
12
  import { errors as encryptionErrors } from '@adonisjs/encryption';
5
13
  import { errors as httpServerErrors } from '@adonisjs/http-server';
6
- export { stubsRoot } from './stubs/index.js';
14
+ export { stubsRoot } from './stubs/main.js';
7
15
  export { inject } from './modules/container.js';
8
16
  export { Ignitor } from './src/ignitor/main.js';
9
17
  export const errors = {
@@ -13,7 +21,12 @@ export const errors = {
13
21
  ...aceErrors,
14
22
  ...envErrors,
15
23
  };
24
+ /**
25
+ * Pretty prints an error with colorful output using
26
+ * Youch terminal
27
+ */
16
28
  export async function prettyPrintError(error) {
29
+ // @ts-expect-error
17
30
  const { default: youchTerminal } = await import('youch-terminal');
18
31
  const { default: Youch } = await import('youch');
19
32
  const youch = new Youch(error, {});
@@ -0,0 +1,54 @@
1
+ import type { Logger } from '@poppinss/cliui';
2
+ import type { CodeTransformer } from '@adonisjs/assembler/code_transformer';
3
+ import type { AddMiddlewareEntry, EnvValidationDefinition } from '@adonisjs/assembler/types';
4
+ import type { Application } from '../app.js';
5
+ /**
6
+ * Codemods to modify AdonisJS source files. The codemod APIs relies on
7
+ * "@adonisjs/assembler" package and it must be installed as a dependency
8
+ * inside user application.
9
+ */
10
+ export declare class Codemods {
11
+ #private;
12
+ constructor(app: Application<any>, cliLogger: Logger);
13
+ /**
14
+ * Define one or more environment variables
15
+ */
16
+ defineEnvVariables(environmentVariables: Record<string, number | string | boolean>): Promise<void>;
17
+ /**
18
+ * Define validations for the environment variables
19
+ */
20
+ defineEnvValidations(validations: EnvValidationDefinition): Promise<void>;
21
+ /**
22
+ * Define validations for the environment variables
23
+ */
24
+ registerMiddleware(stack: 'server' | 'router' | 'named', middleware: AddMiddlewareEntry[]): Promise<void>;
25
+ /**
26
+ * Update RCFile
27
+ */
28
+ updateRcFile(...params: Parameters<CodeTransformer['updateRcFile']>): Promise<void>;
29
+ /**
30
+ * Generats the stub
31
+ */
32
+ makeUsingStub(stubsRoot: string, stubPath: string, stubState: Record<string, any>): Promise<{
33
+ relativeFileName: string;
34
+ contents: any;
35
+ destination: any;
36
+ attributes: any;
37
+ status: "created";
38
+ skipReason: null;
39
+ } | {
40
+ relativeFileName: string;
41
+ contents: any;
42
+ destination: any;
43
+ attributes: any;
44
+ status: "force_created";
45
+ skipReason: null;
46
+ } | {
47
+ relativeFileName: string;
48
+ contents: any;
49
+ destination: any;
50
+ attributes: any;
51
+ status: "skipped";
52
+ skipReason: string;
53
+ }>;
54
+ }
@@ -0,0 +1,133 @@
1
+ /*
2
+ * @adonisjs/core
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+ import { slash } from '@poppinss/utils';
10
+ import { EnvEditor } from '@adonisjs/env/editor';
11
+ /**
12
+ * Codemods to modify AdonisJS source files. The codemod APIs relies on
13
+ * "@adonisjs/assembler" package and it must be installed as a dependency
14
+ * inside user application.
15
+ */
16
+ export class Codemods {
17
+ /**
18
+ * Flag to know if assembler is installed as a
19
+ * peer dependency or not.
20
+ */
21
+ #isAssemblerInstalled;
22
+ /**
23
+ * Reference to lazily imported assembler code transformer
24
+ */
25
+ #codeTransformer;
26
+ /**
27
+ * Reference to AdonisJS application
28
+ */
29
+ #app;
30
+ /**
31
+ * Reference to CLI logger to write logs
32
+ */
33
+ #cliLogger;
34
+ constructor(app, cliLogger) {
35
+ this.#app = app;
36
+ this.#cliLogger = cliLogger;
37
+ }
38
+ /**
39
+ * Lazily imports assembler
40
+ */
41
+ async #importAssembler() {
42
+ if (this.#isAssemblerInstalled === undefined) {
43
+ this.#codeTransformer = await import('@adonisjs/assembler/code_transformer');
44
+ this.#isAssemblerInstalled = !!this.#codeTransformer;
45
+ }
46
+ }
47
+ /**
48
+ * Define one or more environment variables
49
+ */
50
+ async defineEnvVariables(environmentVariables) {
51
+ const editor = new EnvEditor(this.#app.appRoot);
52
+ await editor.load();
53
+ Object.keys(environmentVariables).forEach((key) => {
54
+ const value = environmentVariables[key];
55
+ editor.add(key, value);
56
+ });
57
+ await editor.save();
58
+ this.#cliLogger.action('update .env file').succeeded();
59
+ }
60
+ /**
61
+ * Define validations for the environment variables
62
+ */
63
+ async defineEnvValidations(validations) {
64
+ await this.#importAssembler();
65
+ if (!this.#codeTransformer) {
66
+ this.#cliLogger.warning('Cannot update "start/env.ts" file. Install "@adonisjs/assembler" to modify source files');
67
+ return;
68
+ }
69
+ const transformer = new this.#codeTransformer.CodeTransformer(this.#app.appRoot);
70
+ const action = this.#cliLogger.action('update start/env.ts file');
71
+ try {
72
+ await transformer.defineEnvValidations(validations);
73
+ action.succeeded();
74
+ }
75
+ catch (error) {
76
+ action.failed(error.message);
77
+ }
78
+ }
79
+ /**
80
+ * Define validations for the environment variables
81
+ */
82
+ async registerMiddleware(stack, middleware) {
83
+ await this.#importAssembler();
84
+ if (!this.#codeTransformer) {
85
+ this.#cliLogger.warning('Cannot update "start/kernel.ts" file. Install "@adonisjs/assembler" to modify source files');
86
+ return;
87
+ }
88
+ const transformer = new this.#codeTransformer.CodeTransformer(this.#app.appRoot);
89
+ const action = this.#cliLogger.action('update start/kernel.ts file');
90
+ try {
91
+ await transformer.addMiddlewareToStack(stack, middleware);
92
+ action.succeeded();
93
+ }
94
+ catch (error) {
95
+ action.failed(error.message);
96
+ }
97
+ }
98
+ /**
99
+ * Update RCFile
100
+ */
101
+ async updateRcFile(...params) {
102
+ await this.#importAssembler();
103
+ if (!this.#codeTransformer) {
104
+ this.#cliLogger.warning('Cannot update "adonisrc.ts" file. Install "@adonisjs/assembler" to modify source files');
105
+ return;
106
+ }
107
+ const transformer = new this.#codeTransformer.CodeTransformer(this.#app.appRoot);
108
+ const action = this.#cliLogger.action('update adonisrc.ts file');
109
+ try {
110
+ await transformer.updateRcFile(...params);
111
+ action.succeeded();
112
+ }
113
+ catch (error) {
114
+ action.failed(error.message);
115
+ }
116
+ }
117
+ /**
118
+ * Generats the stub
119
+ */
120
+ async makeUsingStub(stubsRoot, stubPath, stubState) {
121
+ const stubs = await this.#app.stubs.create();
122
+ const stub = await stubs.build(stubPath, { source: stubsRoot });
123
+ const output = await stub.generate(stubState);
124
+ const entityFileName = slash(this.#app.relativePath(output.destination));
125
+ const result = { ...output, relativeFileName: entityFileName };
126
+ if (output.status === 'skipped') {
127
+ this.#cliLogger.action(`create ${entityFileName}`).skipped(output.skipReason);
128
+ return result;
129
+ }
130
+ this.#cliLogger.action(`create ${entityFileName}`).succeeded();
131
+ return result;
132
+ }
133
+ }
@@ -2,6 +2,10 @@ import { BaseCommand as AceBaseCommand, ListCommand as AceListCommand } from '@a
2
2
  import { Kernel } from './kernel.js';
3
3
  import type { ApplicationService } from '../../src/types.js';
4
4
  import type { CommandOptions, ParsedOutput, UIPrimitives } from '../../types/ace.js';
5
+ /**
6
+ * The base command to create custom ace commands. The AdonisJS base commands
7
+ * receives the application instance
8
+ */
5
9
  export declare class BaseCommand extends AceBaseCommand {
6
10
  app: ApplicationService;
7
11
  kernel: Kernel;
@@ -9,12 +13,46 @@ export declare class BaseCommand extends AceBaseCommand {
9
13
  get staysAlive(): boolean | undefined;
10
14
  get startApp(): boolean | undefined;
11
15
  constructor(app: ApplicationService, kernel: Kernel, parsed: ParsedOutput, ui: UIPrimitives, prompt: Kernel['prompt']);
16
+ /**
17
+ * Creates the codemods module to modify source files
18
+ */
19
+ createCodemods(): Promise<import("./codemods.js").Codemods>;
20
+ /**
21
+ * The prepare template method is used to prepare the
22
+ * state for the command. This is the first method
23
+ * executed on a given command instance.
24
+ */
12
25
  prepare?(..._: any[]): any;
26
+ /**
27
+ * The interact template method is used to display the prompts
28
+ * to the user. The method is called after the prepare
29
+ * method.
30
+ */
13
31
  interact?(..._: any[]): any;
32
+ /**
33
+ * The completed method is the method invoked after the command
34
+ * finishes or results in an error.
35
+ *
36
+ * You can access the command error using the `this.error` property.
37
+ * Returning `true` from completed method supresses the error
38
+ * reporting to the kernel layer.
39
+ */
14
40
  completed?(..._: any[]): any;
41
+ /**
42
+ * Executes the command
43
+ */
15
44
  exec(): Promise<any>;
45
+ /**
46
+ * Terminate the app. A command should prefer calling this method
47
+ * over the "app.terminate", because this method only triggers
48
+ * app termination when the current command is in the charge
49
+ * of the process.
50
+ */
16
51
  terminate(): Promise<void>;
17
52
  }
53
+ /**
54
+ * The List command is used to display a list of commands
55
+ */
18
56
  export declare class ListCommand extends AceListCommand implements BaseCommand {
19
57
  app: ApplicationService;
20
58
  kernel: Kernel;
@@ -22,5 +60,15 @@ export declare class ListCommand extends AceListCommand implements BaseCommand {
22
60
  get staysAlive(): boolean | undefined;
23
61
  get startApp(): boolean | undefined;
24
62
  constructor(app: ApplicationService, kernel: Kernel, parsed: ParsedOutput, ui: UIPrimitives, prompt: Kernel['prompt']);
63
+ /**
64
+ * Creates the codemods module to modify source files
65
+ */
66
+ createCodemods(): Promise<import("./codemods.js").Codemods>;
67
+ /**
68
+ * Terminate the app. A command should prefer calling this method
69
+ * over the "app.terminate", because this method only triggers
70
+ * app termination when the current command is in the charge
71
+ * of the process.
72
+ */
25
73
  terminate(): Promise<void>;
26
74
  }
@@ -1,4 +1,16 @@
1
+ /*
2
+ * @adonisjs/core
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
1
9
  import { BaseCommand as AceBaseCommand, ListCommand as AceListCommand } from '@adonisjs/ace';
10
+ /**
11
+ * The base command to create custom ace commands. The AdonisJS base commands
12
+ * receives the application instance
13
+ */
2
14
  export class BaseCommand extends AceBaseCommand {
3
15
  app;
4
16
  kernel;
@@ -14,12 +26,28 @@ export class BaseCommand extends AceBaseCommand {
14
26
  this.app = app;
15
27
  this.kernel = kernel;
16
28
  }
29
+ /**
30
+ * Creates the codemods module to modify source files
31
+ */
32
+ async createCodemods() {
33
+ const { Codemods } = await import('./codemods.js');
34
+ return new Codemods(this.app, this.logger);
35
+ }
36
+ /**
37
+ * Executes the command
38
+ */
17
39
  async exec() {
18
40
  this.hydrate();
19
41
  try {
42
+ /**
43
+ * Executing the template methods
44
+ */
20
45
  this.prepare && (await this.app.container.call(this, 'prepare'));
21
46
  this.interact && (await this.app.container.call(this, 'interact'));
22
47
  const result = await this.app.container.call(this, 'run');
48
+ /**
49
+ * Set exit code
50
+ */
23
51
  this.result = this.result === undefined ? result : this.result;
24
52
  this.exitCode = this.exitCode ?? 0;
25
53
  }
@@ -27,6 +55,10 @@ export class BaseCommand extends AceBaseCommand {
27
55
  this.error = error;
28
56
  this.exitCode = this.exitCode ?? 1;
29
57
  }
58
+ /**
59
+ * Run the completed method (if exists) and check if has handled
60
+ * the error
61
+ */
30
62
  let errorHandled = this.completed
31
63
  ? await this.app.container.call(this, 'completed')
32
64
  : false;
@@ -35,12 +67,21 @@ export class BaseCommand extends AceBaseCommand {
35
67
  }
36
68
  return this.result;
37
69
  }
70
+ /**
71
+ * Terminate the app. A command should prefer calling this method
72
+ * over the "app.terminate", because this method only triggers
73
+ * app termination when the current command is in the charge
74
+ * of the process.
75
+ */
38
76
  async terminate() {
39
77
  if (this.kernel.getMainCommand() === this) {
40
78
  await this.app.terminate();
41
79
  }
42
80
  }
43
81
  }
82
+ /**
83
+ * The List command is used to display a list of commands
84
+ */
44
85
  export class ListCommand extends AceListCommand {
45
86
  app;
46
87
  kernel;
@@ -56,6 +97,19 @@ export class ListCommand extends AceListCommand {
56
97
  this.app = app;
57
98
  this.kernel = kernel;
58
99
  }
100
+ /**
101
+ * Creates the codemods module to modify source files
102
+ */
103
+ async createCodemods() {
104
+ const { Codemods } = await import('./codemods.js');
105
+ return new Codemods(this.app, this.logger);
106
+ }
107
+ /**
108
+ * Terminate the app. A command should prefer calling this method
109
+ * over the "app.terminate", because this method only triggers
110
+ * app termination when the current command is in the charge
111
+ * of the process.
112
+ */
59
113
  async terminate() {
60
114
  if (this.kernel.getMainCommand() === this) {
61
115
  await this.app.terminate();
@@ -1,3 +1,12 @@
1
1
  import { Kernel } from './main.js';
2
2
  import type { ApplicationService } from '../../src/types.js';
3
+ /**
4
+ * We abstract the logic for creating the ace kernel in this
5
+ * file. So that both the "console" environment and rest
6
+ * of the environments can configure and use ace.
7
+ *
8
+ * - In console environment, ace manages the lifecycle of the process
9
+ * - In other environments, ace can be pulled from the container to
10
+ * run commands
11
+ */
3
12
  export declare function createAceKernel(app: ApplicationService): Kernel;
@@ -1,11 +1,36 @@
1
+ /*
2
+ * @adonisjs/ace
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
1
9
  import { Kernel } from './main.js';
2
10
  import { FsLoader, HelpCommand } from '../../modules/ace/main.js';
11
+ /**
12
+ * We abstract the logic for creating the ace kernel in this
13
+ * file. So that both the "console" environment and rest
14
+ * of the environments can configure and use ace.
15
+ *
16
+ * - In console environment, ace manages the lifecycle of the process
17
+ * - In other environments, ace can be pulled from the container to
18
+ * run commands
19
+ */
3
20
  export function createAceKernel(app) {
4
21
  const kernel = new Kernel(app);
5
22
  kernel.addLoader(new FsLoader(app.commandsPath()));
23
+ kernel.info.set('binary', 'node ace');
24
+ /**
25
+ * Lazy import commands mentioned in the "commands" array
26
+ * of rcFile
27
+ */
6
28
  app.rcFile.commands.forEach((commandModule) => {
7
- kernel.addLoader(() => app.import(commandModule));
29
+ kernel.addLoader(() => typeof commandModule === 'function' ? commandModule() : app.import(commandModule));
8
30
  });
31
+ /**
32
+ * Custom global flags
33
+ */
9
34
  kernel.defineFlag('ansi', {
10
35
  type: 'boolean',
11
36
  showNegatedVariantInHelp: true,
@@ -15,6 +40,9 @@ export function createAceKernel(app) {
15
40
  type: 'boolean',
16
41
  description: HelpCommand.description,
17
42
  });
43
+ /**
44
+ * Flag listener to turn colors on/off
45
+ */
18
46
  kernel.on('ansi', (_, $kernel, parsed) => {
19
47
  if (parsed.flags.ansi === false) {
20
48
  $kernel.ui.switchMode('silent');
@@ -23,6 +51,9 @@ export function createAceKernel(app) {
23
51
  $kernel.ui.switchMode('normal');
24
52
  }
25
53
  });
54
+ /**
55
+ * Flag listener to display the help
56
+ */
26
57
  kernel.on('help', async (command, $kernel, parsed) => {
27
58
  parsed.args.unshift(command.commandName);
28
59
  const help = new HelpCommand($kernel, parsed, kernel.ui, kernel.prompt);
@@ -1,6 +1,10 @@
1
1
  import { Kernel as AceKernel } from '@adonisjs/ace';
2
2
  import { BaseCommand } from './commands.js';
3
3
  import type { ApplicationService } from '../../src/types.js';
4
+ /**
5
+ * The base command to create custom ace commands. The AdonisJS base commands
6
+ * receives the application instance
7
+ */
4
8
  export declare class Kernel extends AceKernel<typeof BaseCommand> {
5
9
  app: ApplicationService;
6
10
  constructor(app: ApplicationService);
@@ -1,5 +1,17 @@
1
+ /*
2
+ * @adonisjs/core
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
1
9
  import { Kernel as AceKernel } from '@adonisjs/ace';
2
10
  import { ListCommand } from './commands.js';
11
+ /**
12
+ * The base command to create custom ace commands. The AdonisJS base commands
13
+ * receives the application instance
14
+ */
3
15
  export class Kernel extends AceKernel {
4
16
  app;
5
17
  constructor(app) {
@@ -1,3 +1,11 @@
1
+ /*
2
+ * @adonisjs/core
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
1
9
  export { Kernel } from './kernel.js';
2
10
  export { BaseCommand, ListCommand } from './commands.js';
3
11
  export { args, flags, errors, Parser, FsLoader, ListLoader, cliHelpers, HelpCommand, IndexGenerator, } from '@adonisjs/ace';
@@ -1,4 +1,12 @@
1
- /// <reference types="node" resolution-mode="require"/>
1
+ /// <reference types="@types/node" resolution-mode="require"/>
2
+ /**
3
+ * Ace shell is used to run the ace commands inside a TypeScript project
4
+ * without pre-compiling TypeScript source files.
5
+ *
6
+ * Under the hood a child process is used to execute the "bin/console.ts" file. This
7
+ * is required because we have to use "ts-node/esm" loader in order to run TypeScript
8
+ * files.
9
+ */
2
10
  export declare function aceShell(cwd: URL): {
3
11
  handle(argv: string[]): Promise<void>;
4
12
  };
@@ -1,8 +1,29 @@
1
+ /*
2
+ * @adonisjs/core
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
1
9
  const DEFAULT_NODE_ARGS = [
10
+ // Use ts-node/esm loader. The project must install it
2
11
  '--loader=ts-node/esm',
12
+ // Disable annonying warnings
3
13
  '--no-warnings',
14
+ // Enable expiremental meta resolve for cases where someone uses magic import string
4
15
  '--experimental-import-meta-resolve',
16
+ // Enable source maps, since TSNode source maps are broken
17
+ '--enable-source-maps',
5
18
  ];
19
+ /**
20
+ * Ace shell is used to run the ace commands inside a TypeScript project
21
+ * without pre-compiling TypeScript source files.
22
+ *
23
+ * Under the hood a child process is used to execute the "bin/console.ts" file. This
24
+ * is required because we have to use "ts-node/esm" loader in order to run TypeScript
25
+ * files.
26
+ */
6
27
  export function aceShell(cwd) {
7
28
  return {
8
29
  async handle(argv) {
@@ -1 +1,9 @@
1
+ /*
2
+ * @adonisjs/core
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
1
9
  export * from '@adonisjs/application';
@@ -1,2 +1,6 @@
1
1
  import { BodyParserMiddleware } from '@adonisjs/bodyparser/bodyparser_middleware';
2
+ /**
3
+ * Default export allows lazy importing middleware with
4
+ * destructuring the named exports
5
+ */
2
6
  export default BodyParserMiddleware;
@@ -1,2 +1,14 @@
1
+ /*
2
+ * @adonisjs/core
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
1
9
  import { BodyParserMiddleware } from '@adonisjs/bodyparser/bodyparser_middleware';
10
+ /**
11
+ * Default export allows lazy importing middleware with
12
+ * destructuring the named exports
13
+ */
2
14
  export default BodyParserMiddleware;
@@ -1 +1,9 @@
1
+ /*
2
+ * @adonisjs/core
3
+ *
4
+ * (c) AdonisJS
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
1
9
  export * from '@adonisjs/bodyparser';