@adonisjs/core 6.18.0 → 7.0.0-next.0
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.
- package/build/commands/add.d.ts +4 -5
- package/build/commands/add.js +7 -60
- package/build/commands/build.d.ts +1 -3
- package/build/commands/build.js +4 -36
- package/build/commands/commands.json +1 -1
- package/build/commands/configure.d.ts +3 -3
- package/build/commands/configure.js +3 -3
- package/build/commands/eject.d.ts +1 -1
- package/build/commands/eject.js +3 -3
- package/build/commands/env/add.d.ts +2 -2
- package/build/commands/env/add.js +2 -2
- package/build/commands/generate_key.d.ts +1 -1
- package/build/commands/generate_key.js +1 -1
- package/build/commands/inspect_rcfile.d.ts +1 -1
- package/build/commands/inspect_rcfile.js +1 -1
- package/build/commands/list/routes.d.ts +2 -2
- package/build/commands/list/routes.js +2 -2
- package/build/commands/make/command.d.ts +1 -1
- package/build/commands/make/command.js +3 -3
- package/build/commands/make/controller.d.ts +2 -2
- package/build/commands/make/controller.js +2 -2
- package/build/commands/make/event.d.ts +2 -2
- package/build/commands/make/event.js +2 -2
- package/build/commands/make/exception.d.ts +2 -2
- package/build/commands/make/exception.js +2 -2
- package/build/commands/make/listener.d.ts +2 -2
- package/build/commands/make/listener.js +2 -2
- package/build/commands/make/middleware.d.ts +2 -2
- package/build/commands/make/middleware.js +4 -4
- package/build/commands/make/preload.d.ts +1 -1
- package/build/commands/make/preload.js +4 -4
- package/build/commands/make/provider.d.ts +1 -1
- package/build/commands/make/provider.js +4 -4
- package/build/commands/make/service.d.ts +2 -2
- package/build/commands/make/service.js +2 -2
- package/build/commands/make/test.d.ts +1 -1
- package/build/commands/make/test.js +2 -2
- package/build/commands/make/validator.d.ts +2 -2
- package/build/commands/make/validator.js +2 -2
- package/build/commands/make/view.d.ts +1 -1
- package/build/commands/make/view.js +2 -2
- package/build/commands/repl.d.ts +2 -2
- package/build/commands/repl.js +1 -1
- package/build/commands/serve.d.ts +2 -4
- package/build/commands/serve.js +11 -43
- package/build/commands/test.d.ts +2 -4
- package/build/commands/test.js +4 -32
- package/build/factories/core/ace.d.ts +31 -4
- package/build/factories/core/ace.js +20 -4
- package/build/factories/core/ignitor.d.ts +80 -9
- package/build/factories/core/ignitor.js +84 -13
- package/build/factories/core/main.d.ts +3 -3
- package/build/factories/core/main.js +3 -3
- package/build/factories/core/test_utils.d.ts +32 -4
- package/build/factories/core/test_utils.js +21 -4
- package/build/factories/stubs.d.ts +54 -5
- package/build/factories/stubs.js +55 -6
- package/build/index.d.ts +5 -4
- package/build/index.js +13 -9
- package/build/modules/ace/codemods.d.ts +71 -11
- package/build/modules/ace/codemods.js +90 -22
- package/build/modules/ace/commands.d.ts +49 -13
- package/build/modules/ace/commands.js +48 -10
- package/build/modules/ace/create_kernel.d.ts +19 -8
- package/build/modules/ace/create_kernel.js +19 -8
- package/build/modules/ace/kernel.d.ts +18 -4
- package/build/modules/ace/kernel.js +17 -3
- package/build/modules/ace/main.d.ts +3 -3
- package/build/modules/ace/main.js +3 -3
- package/build/modules/dumper/define_config.d.ts +25 -4
- package/build/modules/dumper/define_config.js +23 -2
- package/build/modules/dumper/dumper.d.ts +82 -12
- package/build/modules/dumper/dumper.js +82 -12
- package/build/modules/dumper/errors.d.ts +31 -10
- package/build/modules/dumper/errors.js +28 -7
- package/build/modules/dumper/main.d.ts +3 -3
- package/build/modules/dumper/main.js +3 -3
- package/build/modules/dumper/plugins/edge.d.ts +1 -1
- package/build/modules/hash/define_config.d.ts +53 -8
- package/build/modules/hash/define_config.js +51 -6
- package/build/modules/hash/main.d.ts +1 -1
- package/build/modules/hash/main.js +1 -1
- package/build/modules/http/main.d.ts +1 -1
- package/build/modules/http/main.js +1 -1
- package/build/modules/http/request_validator.d.ts +36 -9
- package/build/modules/http/request_validator.js +32 -5
- package/build/modules/transformers/main.d.ts +1 -0
- package/build/modules/transformers/main.js +9 -0
- package/build/providers/app_provider.d.ts +173 -1
- package/build/providers/app_provider.js +204 -8
- package/build/providers/edge_provider.d.ts +31 -2
- package/build/providers/edge_provider.js +31 -2
- package/build/providers/hash_provider.d.ts +38 -1
- package/build/providers/hash_provider.js +40 -3
- package/build/providers/repl_provider.d.ts +40 -1
- package/build/providers/repl_provider.js +52 -2
- package/build/providers/vinejs_provider.d.ts +32 -23
- package/build/providers/vinejs_provider.js +32 -66
- package/build/services/ace.d.ts +1 -1
- package/build/services/ace.js +1 -1
- package/build/services/app.d.ts +1 -1
- package/build/services/config.d.ts +1 -1
- package/build/services/config.js +1 -1
- package/build/services/dumper.js +1 -1
- package/build/services/emitter.d.ts +1 -1
- package/build/services/emitter.js +1 -1
- package/build/services/encryption.d.ts +1 -1
- package/build/services/encryption.js +1 -1
- package/build/services/hash.d.ts +1 -1
- package/build/services/hash.js +1 -1
- package/build/services/logger.d.ts +1 -1
- package/build/services/logger.js +1 -1
- package/build/services/repl.d.ts +1 -1
- package/build/services/repl.js +1 -1
- package/build/services/router.d.ts +1 -1
- package/build/services/router.js +1 -1
- package/build/services/server.d.ts +1 -1
- package/build/services/server.js +1 -1
- package/build/services/test_utils.d.ts +1 -1
- package/build/services/test_utils.js +1 -1
- package/build/services/url_builder.d.ts +4 -0
- package/build/services/url_builder.js +21 -0
- package/build/src/assembler_hooks/index_entities.d.ts +51 -0
- package/build/src/assembler_hooks/index_entities.js +96 -0
- package/build/src/cli_formatters/routes_list.d.ts +24 -12
- package/build/src/cli_formatters/routes_list.js +43 -46
- package/build/src/config_provider.d.ts +48 -3
- package/build/src/config_provider.js +47 -2
- package/build/src/debug.d.ts +15 -0
- package/build/src/debug.js +15 -0
- package/build/src/exceptions.d.ts +41 -1
- package/build/src/exceptions.js +41 -1
- package/build/src/helpers/assert.d.ts +47 -1
- package/build/src/helpers/assert.js +47 -1
- package/build/src/helpers/is.d.ts +21 -0
- package/build/src/helpers/is.js +21 -0
- package/build/src/helpers/main.d.ts +48 -5
- package/build/src/helpers/main.js +48 -5
- package/build/src/helpers/string.d.ts +89 -9
- package/build/src/helpers/string.js +15 -2
- package/build/src/helpers/types.d.ts +96 -2
- package/build/src/helpers/types.js +96 -2
- package/build/src/helpers/verification_token.d.ts +22 -1
- package/build/src/helpers/verification_token.js +24 -2
- package/build/src/ignitor/ace.d.ts +23 -3
- package/build/src/ignitor/ace.js +21 -1
- package/build/src/ignitor/http.d.ts +16 -3
- package/build/src/ignitor/http.js +16 -3
- package/build/src/ignitor/main.d.ts +29 -6
- package/build/src/ignitor/main.js +30 -7
- package/build/src/ignitor/test.d.ts +26 -3
- package/build/src/ignitor/test.js +24 -1
- package/build/src/test_utils/http.d.ts +19 -3
- package/build/src/test_utils/http.js +24 -3
- package/build/src/test_utils/main.d.ts +22 -4
- package/build/src/test_utils/main.js +21 -3
- package/build/src/types.d.ts +277 -26
- package/build/src/utils.d.ts +34 -0
- package/build/src/utils.js +49 -0
- package/build/src/vine.d.ts +42 -0
- package/build/src/vine.js +97 -0
- package/build/stubs/main.js +1 -2
- package/build/toolkit/main.js +1 -1
- package/build/types/helpers.d.ts +2 -1
- package/build/types/transformers.d.ts +1 -0
- package/build/types/transformers.js +9 -0
- package/package.json +57 -55
- package/build/src/helpers/parse_binding_reference.d.ts +0 -45
- package/build/src/helpers/parse_binding_reference.js +0 -83
- package/build/src/internal_helpers.d.ts +0 -15
- package/build/src/internal_helpers.js +0 -63
|
@@ -6,14 +6,30 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
import { Ignitor } from
|
|
10
|
-
import { drivers } from
|
|
11
|
-
import { defineConfig as defineHttpConfig } from
|
|
12
|
-
import { defineConfig as defineLoggerConfig } from
|
|
13
|
-
import { defineConfig as defineHashConfig } from
|
|
14
|
-
import { defineConfig as defineBodyParserConfig } from
|
|
9
|
+
import { Ignitor } from "../../src/ignitor/main.js";
|
|
10
|
+
import { drivers } from "../../modules/hash/define_config.js";
|
|
11
|
+
import { defineConfig as defineHttpConfig } from "../../modules/http/main.js";
|
|
12
|
+
import { defineConfig as defineLoggerConfig } from "../../modules/logger.js";
|
|
13
|
+
import { defineConfig as defineHashConfig } from "../../modules/hash/main.js";
|
|
14
|
+
import { defineConfig as defineBodyParserConfig } from "../../modules/bodyparser/main.js";
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Factory for creating and configuring AdonisJS Ignitor instances.
|
|
17
|
+
* This factory provides a fluent API to set up applications with core providers,
|
|
18
|
+
* configurations, and preload actions for testing and development scenarios.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const ignitor = new IgnitorFactory()
|
|
23
|
+
* .withCoreProviders()
|
|
24
|
+
* .withCoreConfig()
|
|
25
|
+
* .preload((app) => {
|
|
26
|
+
* // Custom initialization logic
|
|
27
|
+
* })
|
|
28
|
+
* .create(new URL('../', import.meta.url))
|
|
29
|
+
*
|
|
30
|
+
* const app = ignitor.createApp('web')
|
|
31
|
+
* await app.boot()
|
|
32
|
+
* ```
|
|
17
33
|
*/
|
|
18
34
|
export class IgnitorFactory {
|
|
19
35
|
#preloadActions = [];
|
|
@@ -23,7 +39,18 @@ export class IgnitorFactory {
|
|
|
23
39
|
*/
|
|
24
40
|
#loadCoreProviders = false;
|
|
25
41
|
/**
|
|
26
|
-
* Define preload actions to run.
|
|
42
|
+
* Define preload actions to run during application initialization.
|
|
43
|
+
* These actions are executed after the application is booted.
|
|
44
|
+
*
|
|
45
|
+
* @param action - Function to execute during preload phase
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* factory.preload((app) => {
|
|
50
|
+
* // Register custom bindings
|
|
51
|
+
* app.container.bind('customService', () => new CustomService())
|
|
52
|
+
* })
|
|
53
|
+
* ```
|
|
27
54
|
*/
|
|
28
55
|
preload(action) {
|
|
29
56
|
this.#preloadActions.push(action);
|
|
@@ -41,7 +68,24 @@ export class IgnitorFactory {
|
|
|
41
68
|
return coreProviders.concat(providers || []);
|
|
42
69
|
}
|
|
43
70
|
/**
|
|
44
|
-
* Merge custom factory parameters
|
|
71
|
+
* Merge custom factory parameters with existing ones.
|
|
72
|
+
* This allows you to customize RC file contents and application configuration.
|
|
73
|
+
*
|
|
74
|
+
* @param params - Parameters to merge
|
|
75
|
+
* @param params.config - Application configuration to merge
|
|
76
|
+
* @param params.rcFileContents - RC file contents to merge
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* factory.merge({
|
|
81
|
+
* config: {
|
|
82
|
+
* database: { connection: 'mysql' }
|
|
83
|
+
* },
|
|
84
|
+
* rcFileContents: {
|
|
85
|
+
* commands: ['./commands/CustomCommand']
|
|
86
|
+
* }
|
|
87
|
+
* })
|
|
88
|
+
* ```
|
|
45
89
|
*/
|
|
46
90
|
merge(params) {
|
|
47
91
|
if (params.config) {
|
|
@@ -53,15 +97,31 @@ export class IgnitorFactory {
|
|
|
53
97
|
return this;
|
|
54
98
|
}
|
|
55
99
|
/**
|
|
56
|
-
*
|
|
100
|
+
* Include core AdonisJS providers when booting the application.
|
|
101
|
+
* This adds essential providers like app, hash, and REPL providers.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* const ignitor = new IgnitorFactory()
|
|
106
|
+
* .withCoreProviders()
|
|
107
|
+
* .create(appRoot)
|
|
108
|
+
* ```
|
|
57
109
|
*/
|
|
58
110
|
withCoreProviders() {
|
|
59
111
|
this.#loadCoreProviders = true;
|
|
60
112
|
return this;
|
|
61
113
|
}
|
|
62
114
|
/**
|
|
63
|
-
* Merge default
|
|
64
|
-
*
|
|
115
|
+
* Merge default configuration for core AdonisJS features.
|
|
116
|
+
* This includes configurations for HTTP, hash, logger, and bodyparser.
|
|
117
|
+
* A shallow merge is performed with existing config.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* const ignitor = new IgnitorFactory()
|
|
122
|
+
* .withCoreConfig()
|
|
123
|
+
* .create(appRoot)
|
|
124
|
+
* ```
|
|
65
125
|
*/
|
|
66
126
|
withCoreConfig() {
|
|
67
127
|
this.merge({
|
|
@@ -89,7 +149,18 @@ export class IgnitorFactory {
|
|
|
89
149
|
return this;
|
|
90
150
|
}
|
|
91
151
|
/**
|
|
92
|
-
* Create
|
|
152
|
+
* Create a configured Ignitor instance with all specified parameters.
|
|
153
|
+
*
|
|
154
|
+
* @param appRoot - Application root directory URL
|
|
155
|
+
* @param options - Optional Ignitor configuration options
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* const ignitor = new IgnitorFactory()
|
|
160
|
+
* .withCoreConfig()
|
|
161
|
+
* .withCoreProviders()
|
|
162
|
+
* .create(new URL('../', import.meta.url))
|
|
163
|
+
* ```
|
|
93
164
|
*/
|
|
94
165
|
create(appRoot, options) {
|
|
95
166
|
return new Ignitor(appRoot, options).tap((app) => {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { AceFactory } from './ace.
|
|
2
|
-
export { IgnitorFactory } from './ignitor.
|
|
3
|
-
export { TestUtilsFactory } from './test_utils.
|
|
1
|
+
export { AceFactory } from './ace.ts';
|
|
2
|
+
export { IgnitorFactory } from './ignitor.ts';
|
|
3
|
+
export { TestUtilsFactory } from './test_utils.ts';
|
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
export { AceFactory } from
|
|
10
|
-
export { IgnitorFactory } from
|
|
11
|
-
export { TestUtilsFactory } from
|
|
9
|
+
export { AceFactory } from "./ace.js";
|
|
10
|
+
export { IgnitorFactory } from "./ignitor.js";
|
|
11
|
+
export { TestUtilsFactory } from "./test_utils.js";
|
|
@@ -1,10 +1,38 @@
|
|
|
1
|
-
import { Ignitor } from '../../index.
|
|
2
|
-
import type { IgnitorOptions } from '../../src/types.
|
|
3
|
-
import { TestUtils } from '../../src/test_utils/main.
|
|
1
|
+
import { Ignitor } from '../../index.ts';
|
|
2
|
+
import type { IgnitorOptions } from '../../src/types.ts';
|
|
3
|
+
import { TestUtils } from '../../src/test_utils/main.ts';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Factory for creating TestUtils instances used in AdonisJS testing scenarios.
|
|
6
|
+
* This factory provides convenient methods to set up test utilities either from
|
|
7
|
+
* an existing Ignitor instance or by creating a new configured one.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* // Create from URL for testing
|
|
12
|
+
* const factory = new TestUtilsFactory()
|
|
13
|
+
* const testUtils = factory.create(new URL('../', import.meta.url))
|
|
14
|
+
*
|
|
15
|
+
* // Use in tests
|
|
16
|
+
* const app = testUtils.app()
|
|
17
|
+
* await app.boot()
|
|
18
|
+
*
|
|
19
|
+
* // Create HTTP client
|
|
20
|
+
* const client = testUtils.httpClient()
|
|
21
|
+
* const response = await client.get('/users')
|
|
22
|
+
* ```
|
|
6
23
|
*/
|
|
7
24
|
export declare class TestUtilsFactory {
|
|
25
|
+
/**
|
|
26
|
+
* Create TestUtils from an existing Ignitor instance
|
|
27
|
+
*
|
|
28
|
+
* @param ignitor - Existing Ignitor instance configured for testing
|
|
29
|
+
*/
|
|
8
30
|
create(ignitor: Ignitor): TestUtils;
|
|
31
|
+
/**
|
|
32
|
+
* Create TestUtils from application root URL with optional configuration
|
|
33
|
+
*
|
|
34
|
+
* @param appRoot - Application root directory URL
|
|
35
|
+
* @param options - Optional Ignitor configuration options
|
|
36
|
+
*/
|
|
9
37
|
create(appRoot: URL, options?: IgnitorOptions): TestUtils;
|
|
10
38
|
}
|
|
@@ -6,11 +6,28 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
import { Ignitor } from
|
|
10
|
-
import { IgnitorFactory } from
|
|
11
|
-
import { TestUtils } from
|
|
9
|
+
import { Ignitor } from "../../index.js";
|
|
10
|
+
import { IgnitorFactory } from "./ignitor.js";
|
|
11
|
+
import { TestUtils } from "../../src/test_utils/main.js";
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Factory for creating TestUtils instances used in AdonisJS testing scenarios.
|
|
14
|
+
* This factory provides convenient methods to set up test utilities either from
|
|
15
|
+
* an existing Ignitor instance or by creating a new configured one.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* // Create from URL for testing
|
|
20
|
+
* const factory = new TestUtilsFactory()
|
|
21
|
+
* const testUtils = factory.create(new URL('../', import.meta.url))
|
|
22
|
+
*
|
|
23
|
+
* // Use in tests
|
|
24
|
+
* const app = testUtils.app()
|
|
25
|
+
* await app.boot()
|
|
26
|
+
*
|
|
27
|
+
* // Create HTTP client
|
|
28
|
+
* const client = testUtils.httpClient()
|
|
29
|
+
* const response = await client.get('/users')
|
|
30
|
+
* ```
|
|
14
31
|
*/
|
|
15
32
|
export class TestUtilsFactory {
|
|
16
33
|
create(ignitorOrAppRoot, options) {
|
|
@@ -1,19 +1,68 @@
|
|
|
1
|
-
import type { ApplicationService } from '../src/types.
|
|
1
|
+
import type { ApplicationService } from '../src/types.ts';
|
|
2
2
|
type FactoryParameters = {
|
|
3
3
|
app: ApplicationService;
|
|
4
4
|
};
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* is for internal testing
|
|
6
|
+
* Factory for preparing and processing stub templates from the "@adonisjs/core" package.
|
|
7
|
+
* This factory is designed for internal testing and development purposes, utilizing
|
|
8
|
+
* the core package's stub root directory.
|
|
9
|
+
*
|
|
10
|
+
* Note: This class is not published as it's intended for internal testing only.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const stubsFactory = new StubsFactory()
|
|
15
|
+
*
|
|
16
|
+
* // Prepare a controller stub
|
|
17
|
+
* const preparedStub = await stubsFactory.prepare('controller.stub', {
|
|
18
|
+
* filename: 'UserController',
|
|
19
|
+
* entity: { name: 'User' },
|
|
20
|
+
* resourceful: true
|
|
21
|
+
* })
|
|
22
|
+
*
|
|
23
|
+
* console.log(preparedStub.contents)
|
|
24
|
+
* ```
|
|
8
25
|
*/
|
|
9
26
|
export declare class StubsFactory {
|
|
10
27
|
#private;
|
|
11
28
|
/**
|
|
12
|
-
* Merge custom factory parameters
|
|
29
|
+
* Merge custom factory parameters to override defaults.
|
|
30
|
+
* This allows you to provide a custom application instance.
|
|
31
|
+
*
|
|
32
|
+
* @param params - Parameters to merge
|
|
33
|
+
* @param params.app - Custom application service instance
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* const customApp = new AppFactory().create(appRoot)
|
|
38
|
+
* const stubsFactory = new StubsFactory().merge({ app: customApp })
|
|
39
|
+
* ```
|
|
13
40
|
*/
|
|
14
41
|
merge(params: Partial<FactoryParameters>): this;
|
|
15
42
|
/**
|
|
16
|
-
*
|
|
43
|
+
* Prepare a stub template with the provided data and return the processed content.
|
|
44
|
+
* This method initializes the application, loads the stub, and processes it with
|
|
45
|
+
* the given template variables.
|
|
46
|
+
*
|
|
47
|
+
* @param stubPath - Path to the stub file relative to the stubs root
|
|
48
|
+
* @param data - Template data to populate the stub placeholders
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const stubsFactory = new StubsFactory()
|
|
53
|
+
* const preparedStub = await stubsFactory.prepare('controller.stub', {
|
|
54
|
+
* filename: 'UserController',
|
|
55
|
+
* entity: {
|
|
56
|
+
* name: 'User',
|
|
57
|
+
* modelName: 'User',
|
|
58
|
+
* pluralName: 'users'
|
|
59
|
+
* },
|
|
60
|
+
* resourceful: true
|
|
61
|
+
* })
|
|
62
|
+
*
|
|
63
|
+
* // Access the processed stub content
|
|
64
|
+
* console.log(preparedStub.contents)
|
|
65
|
+
* ```
|
|
17
66
|
*/
|
|
18
67
|
prepare(stubPath: string, data: Record<string, any>): Promise<{
|
|
19
68
|
contents: string;
|
package/build/factories/stubs.js
CHANGED
|
@@ -7,28 +7,77 @@
|
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
9
|
import { AppFactory } from '@adonisjs/application/factories';
|
|
10
|
-
import { stubsRoot } from
|
|
10
|
+
import { stubsRoot } from "../index.js";
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
* is for internal testing
|
|
12
|
+
* Factory for preparing and processing stub templates from the "@adonisjs/core" package.
|
|
13
|
+
* This factory is designed for internal testing and development purposes, utilizing
|
|
14
|
+
* the core package's stub root directory.
|
|
15
|
+
*
|
|
16
|
+
* Note: This class is not published as it's intended for internal testing only.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const stubsFactory = new StubsFactory()
|
|
21
|
+
*
|
|
22
|
+
* // Prepare a controller stub
|
|
23
|
+
* const preparedStub = await stubsFactory.prepare('controller.stub', {
|
|
24
|
+
* filename: 'UserController',
|
|
25
|
+
* entity: { name: 'User' },
|
|
26
|
+
* resourceful: true
|
|
27
|
+
* })
|
|
28
|
+
*
|
|
29
|
+
* console.log(preparedStub.contents)
|
|
30
|
+
* ```
|
|
14
31
|
*/
|
|
15
32
|
export class StubsFactory {
|
|
16
33
|
#parameters = {};
|
|
17
34
|
/**
|
|
18
|
-
* Returns an instance of application
|
|
35
|
+
* Returns an instance of application, either from parameters or creates a default one
|
|
19
36
|
*/
|
|
20
37
|
#getApp() {
|
|
21
38
|
return this.#parameters.app || new AppFactory().create(new URL('./', import.meta.url));
|
|
22
39
|
}
|
|
23
40
|
/**
|
|
24
|
-
* Merge custom factory parameters
|
|
41
|
+
* Merge custom factory parameters to override defaults.
|
|
42
|
+
* This allows you to provide a custom application instance.
|
|
43
|
+
*
|
|
44
|
+
* @param params - Parameters to merge
|
|
45
|
+
* @param params.app - Custom application service instance
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* const customApp = new AppFactory().create(appRoot)
|
|
50
|
+
* const stubsFactory = new StubsFactory().merge({ app: customApp })
|
|
51
|
+
* ```
|
|
25
52
|
*/
|
|
26
53
|
merge(params) {
|
|
27
54
|
this.#parameters = Object.assign(this.#parameters, params);
|
|
28
55
|
return this;
|
|
29
56
|
}
|
|
30
57
|
/**
|
|
31
|
-
*
|
|
58
|
+
* Prepare a stub template with the provided data and return the processed content.
|
|
59
|
+
* This method initializes the application, loads the stub, and processes it with
|
|
60
|
+
* the given template variables.
|
|
61
|
+
*
|
|
62
|
+
* @param stubPath - Path to the stub file relative to the stubs root
|
|
63
|
+
* @param data - Template data to populate the stub placeholders
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* const stubsFactory = new StubsFactory()
|
|
68
|
+
* const preparedStub = await stubsFactory.prepare('controller.stub', {
|
|
69
|
+
* filename: 'UserController',
|
|
70
|
+
* entity: {
|
|
71
|
+
* name: 'User',
|
|
72
|
+
* modelName: 'User',
|
|
73
|
+
* pluralName: 'users'
|
|
74
|
+
* },
|
|
75
|
+
* resourceful: true
|
|
76
|
+
* })
|
|
77
|
+
*
|
|
78
|
+
* // Access the processed stub content
|
|
79
|
+
* console.log(preparedStub.contents)
|
|
80
|
+
* ```
|
|
32
81
|
*/
|
|
33
82
|
async prepare(stubPath, data) {
|
|
34
83
|
const app = this.#getApp();
|
package/build/index.d.ts
CHANGED
|
@@ -3,10 +3,11 @@ import { errors as envErrors } from '@adonisjs/env';
|
|
|
3
3
|
import { errors as appErrors } from '@adonisjs/application';
|
|
4
4
|
import { errors as encryptionErrors } from '@adonisjs/encryption';
|
|
5
5
|
import { errors as httpServerErrors } from '@adonisjs/http-server';
|
|
6
|
-
export { stubsRoot } from './stubs/main.
|
|
7
|
-
export { inject } from './modules/container.
|
|
8
|
-
export { Ignitor } from './src/ignitor/main.
|
|
9
|
-
export { configProvider } from './src/config_provider.
|
|
6
|
+
export { stubsRoot } from './stubs/main.ts';
|
|
7
|
+
export { inject } from './modules/container.ts';
|
|
8
|
+
export { Ignitor } from './src/ignitor/main.ts';
|
|
9
|
+
export { configProvider } from './src/config_provider.ts';
|
|
10
|
+
export { indexEntities } from './src/assembler_hooks/index_entities.ts';
|
|
10
11
|
/**
|
|
11
12
|
* Aggregated errors from all modules.
|
|
12
13
|
*/
|
package/build/index.js
CHANGED
|
@@ -11,10 +11,11 @@ import { errors as envErrors } from '@adonisjs/env';
|
|
|
11
11
|
import { errors as appErrors } from '@adonisjs/application';
|
|
12
12
|
import { errors as encryptionErrors } from '@adonisjs/encryption';
|
|
13
13
|
import { errors as httpServerErrors } from '@adonisjs/http-server';
|
|
14
|
-
export { stubsRoot } from
|
|
15
|
-
export { inject } from
|
|
16
|
-
export { Ignitor } from
|
|
17
|
-
export { configProvider } from
|
|
14
|
+
export { stubsRoot } from "./stubs/main.js";
|
|
15
|
+
export { inject } from "./modules/container.js";
|
|
16
|
+
export { Ignitor } from "./src/ignitor/main.js";
|
|
17
|
+
export { configProvider } from "./src/config_provider.js";
|
|
18
|
+
export { indexEntities } from "./src/assembler_hooks/index_entities.js";
|
|
18
19
|
/**
|
|
19
20
|
* Aggregated errors from all modules.
|
|
20
21
|
*/
|
|
@@ -34,9 +35,12 @@ export async function prettyPrintError(error) {
|
|
|
34
35
|
console.error(error);
|
|
35
36
|
return;
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
try {
|
|
39
|
+
const { Youch } = await import('youch');
|
|
40
|
+
const youch = new Youch();
|
|
41
|
+
console.error(await youch.toANSI(error));
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
console.error(error);
|
|
45
|
+
}
|
|
42
46
|
}
|
|
@@ -1,12 +1,31 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
2
|
import type { UIPrimitives } from '@adonisjs/ace/types';
|
|
3
3
|
import type { CodeTransformer } from '@adonisjs/assembler/code_transformer';
|
|
4
|
-
import type { MiddlewareNode, EnvValidationNode, BouncerPolicyNode } from '@adonisjs/assembler/types';
|
|
5
|
-
import type { Application } from '../app.
|
|
4
|
+
import type { MiddlewareNode, EnvValidationNode, BouncerPolicyNode, SupportedPackageManager } from '@adonisjs/assembler/types';
|
|
5
|
+
import type { Application } from '../app.ts';
|
|
6
6
|
/**
|
|
7
|
-
* Codemods
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Codemods class for programmatically modifying AdonisJS source files.
|
|
8
|
+
* This class provides APIs to modify configuration files, register middleware,
|
|
9
|
+
* generate stubs, and install packages.
|
|
10
|
+
*
|
|
11
|
+
* The codemod APIs rely on the "@adonisjs/assembler" package, which must be
|
|
12
|
+
* installed as a dependency in the user application.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const codemods = new Codemods(app, logger)
|
|
17
|
+
*
|
|
18
|
+
* // Generate a controller from a stub
|
|
19
|
+
* await codemods.makeUsingStub(stubsRoot, 'controller.stub', {
|
|
20
|
+
* filename: 'UserController',
|
|
21
|
+
* entity: { name: 'User' }
|
|
22
|
+
* })
|
|
23
|
+
*
|
|
24
|
+
* // Install packages
|
|
25
|
+
* await codemods.installPackages([
|
|
26
|
+
* { name: '@adonisjs/lucid', isDevDependency: false }
|
|
27
|
+
* ])
|
|
28
|
+
* ```
|
|
10
29
|
*/
|
|
11
30
|
export declare class Codemods extends EventEmitter {
|
|
12
31
|
#private;
|
|
@@ -21,16 +40,40 @@ export declare class Codemods extends EventEmitter {
|
|
|
21
40
|
verboseInstallOutput: boolean;
|
|
22
41
|
constructor(app: Application<any>, cliLogger: UIPrimitives['logger']);
|
|
23
42
|
/**
|
|
24
|
-
* Define one or more environment variables
|
|
43
|
+
* Define one or more environment variables in the .env file
|
|
44
|
+
*
|
|
45
|
+
* @param environmentVariables - Key-value pairs of environment variables
|
|
46
|
+
* @param options - Configuration options
|
|
47
|
+
* @param options.omitFromExample - Keys to exclude from .env.example file
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* await codemods.defineEnvVariables({
|
|
52
|
+
* DB_CONNECTION: 'mysql',
|
|
53
|
+
* DB_HOST: 'localhost',
|
|
54
|
+
* SECRET_KEY: 'abc123'
|
|
55
|
+
* }, {
|
|
56
|
+
* omitFromExample: ['SECRET_KEY']
|
|
57
|
+
* })
|
|
58
|
+
* ```
|
|
25
59
|
*/
|
|
26
60
|
defineEnvVariables<T extends Record<string, number | string | boolean>>(environmentVariables: T, options?: {
|
|
27
61
|
omitFromExample?: Array<keyof T>;
|
|
28
62
|
}): Promise<void>;
|
|
29
63
|
/**
|
|
30
|
-
* Returns the TsMorph project instance
|
|
31
|
-
* See https://ts-morph.com/
|
|
64
|
+
* Returns the TsMorph project instance for advanced AST manipulations.
|
|
65
|
+
* See https://ts-morph.com/ for documentation.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* const project = await codemods.getTsMorphProject()
|
|
70
|
+
* if (project) {
|
|
71
|
+
* const sourceFile = project.getSourceFile('app/controllers/user_controller.ts')
|
|
72
|
+
* // Perform advanced AST operations
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
32
75
|
*/
|
|
33
|
-
getTsMorphProject(): Promise<
|
|
76
|
+
getTsMorphProject(): Promise<CodeTransformer['project'] | undefined>;
|
|
34
77
|
/**
|
|
35
78
|
* Define validations for the environment variables
|
|
36
79
|
*/
|
|
@@ -58,7 +101,24 @@ export declare class Codemods extends EventEmitter {
|
|
|
58
101
|
*/
|
|
59
102
|
registerJapaPlugin(...params: Parameters<CodeTransformer['addJapaPlugin']>): Promise<void>;
|
|
60
103
|
/**
|
|
61
|
-
* Generate
|
|
104
|
+
* Generate a file using a stub template
|
|
105
|
+
*
|
|
106
|
+
* @param stubsRoot - Root directory containing stub files
|
|
107
|
+
* @param stubPath - Path to the specific stub file
|
|
108
|
+
* @param stubState - Template variables for stub generation
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* const result = await codemods.makeUsingStub(
|
|
113
|
+
* './stubs',
|
|
114
|
+
* 'controller.stub',
|
|
115
|
+
* {
|
|
116
|
+
* filename: 'UserController',
|
|
117
|
+
* entity: { name: 'User', modelName: 'User' },
|
|
118
|
+
* resourceful: true
|
|
119
|
+
* }
|
|
120
|
+
* )
|
|
121
|
+
* ```
|
|
62
122
|
*/
|
|
63
123
|
makeUsingStub(stubsRoot: string, stubPath: string, stubState: Record<string, any>): Promise<{
|
|
64
124
|
relativeFileName: string;
|
|
@@ -94,7 +154,7 @@ export declare class Codemods extends EventEmitter {
|
|
|
94
154
|
installPackages(packages: {
|
|
95
155
|
name: string;
|
|
96
156
|
isDevDependency: boolean;
|
|
97
|
-
}[]): Promise<
|
|
157
|
+
}[], packageManager?: SupportedPackageManager | 'pnpm@6' | 'deno'): Promise<boolean>;
|
|
98
158
|
/**
|
|
99
159
|
* List the packages one should install before using the packages
|
|
100
160
|
*/
|