@adonisjs/core 6.1.5-8 → 6.2.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/README.md +3 -5
- package/build/commands/build.d.ts +3 -5
- package/build/commands/build.js +5 -9
- package/build/commands/commands.json +1 -1
- package/build/commands/configure.d.ts +21 -28
- package/build/commands/configure.js +60 -118
- package/build/commands/eject.js +2 -1
- package/build/commands/generate_key.js +2 -2
- package/build/commands/inspect_rcfile.js +19 -2
- package/build/commands/main.d.ts +4 -0
- package/build/commands/make/command.d.ts +1 -1
- package/build/commands/make/command.js +5 -2
- package/build/commands/make/controller.d.ts +2 -1
- package/build/commands/make/controller.js +33 -10
- package/build/commands/make/event.d.ts +1 -1
- package/build/commands/make/event.js +5 -3
- package/build/commands/make/exception.d.ts +1 -1
- package/build/commands/make/exception.js +6 -4
- package/build/commands/make/listener.d.ts +1 -1
- package/build/commands/make/listener.js +9 -6
- package/build/commands/make/middleware.d.ts +2 -1
- package/build/commands/make/middleware.js +50 -4
- package/build/commands/make/preload.d.ts +4 -3
- package/build/commands/make/preload.js +34 -35
- package/build/commands/make/provider.d.ts +7 -1
- package/build/commands/make/provider.js +57 -7
- package/build/commands/make/service.d.ts +1 -1
- package/build/commands/make/service.js +5 -3
- package/build/commands/make/test.d.ts +1 -1
- package/build/commands/make/test.js +7 -5
- package/build/commands/make/validator.d.ts +19 -0
- package/build/commands/make/validator.js +53 -0
- package/build/commands/make/view.d.ts +14 -0
- package/build/commands/make/view.js +37 -0
- package/build/commands/serve.js +7 -4
- package/build/commands/test.js +2 -2
- package/build/factories/core/ace.d.ts +2 -2
- package/build/factories/core/ignitor.d.ts +2 -2
- package/build/factories/core/ignitor.js +9 -10
- package/build/factories/core/main.d.ts +0 -1
- package/build/factories/core/main.js +0 -1
- package/build/factories/core/test_utils.d.ts +2 -2
- package/build/factories/stubs.d.ts +2 -2
- package/build/factories/stubs.js +3 -2
- package/build/index.d.ts +11 -140
- package/build/index.js +5 -1
- package/build/modules/ace/codemods.d.ts +93 -0
- package/build/modules/ace/codemods.js +259 -0
- package/build/modules/ace/commands.d.ts +6 -81
- package/build/modules/ace/commands.js +12 -33
- package/build/modules/ace/create_kernel.d.ts +1 -1
- package/build/modules/ace/create_kernel.js +19 -3
- package/build/modules/env/editor.d.ts +1 -0
- package/build/modules/{http.js → env/editor.js} +1 -1
- package/build/modules/hash/define_config.d.ts +29 -12
- package/build/modules/hash/define_config.js +52 -11
- package/build/modules/hash/drivers/argon.d.ts +1 -0
- package/build/modules/hash/drivers/argon.js +9 -0
- package/build/modules/hash/drivers/bcrypt.d.ts +1 -0
- package/build/modules/hash/drivers/bcrypt.js +9 -0
- package/build/modules/hash/drivers/scrypt.d.ts +1 -0
- package/build/modules/hash/drivers/scrypt.js +9 -0
- package/build/modules/hash/main.d.ts +1 -2
- package/build/modules/hash/main.js +1 -2
- package/build/modules/hash/phc_formatter.d.ts +1 -0
- package/build/modules/hash/phc_formatter.js +9 -0
- package/build/modules/http/main.d.ts +7 -0
- package/build/modules/http/main.js +15 -0
- package/build/modules/http/request_validator.d.ts +34 -0
- package/build/modules/http/request_validator.js +66 -0
- package/build/providers/app_provider.d.ts +14 -0
- package/build/providers/app_provider.js +47 -3
- package/build/providers/edge_provider.d.ts +31 -0
- package/build/providers/edge_provider.js +70 -0
- package/build/providers/hash_provider.d.ts +0 -4
- package/build/providers/hash_provider.js +11 -11
- package/build/providers/repl_provider.js +83 -8
- package/build/providers/vinejs_provider.d.ts +43 -0
- package/build/providers/vinejs_provider.js +97 -0
- package/build/src/cli_formatters/routes_list.d.ts +1 -1
- package/build/src/config_provider.d.ts +9 -0
- package/build/src/config_provider.js +26 -0
- package/build/src/debug.d.ts +1 -1
- package/build/src/helpers/assert.d.ts +1 -0
- package/build/src/helpers/assert.js +9 -0
- package/build/src/helpers/main.d.ts +2 -2
- package/build/src/helpers/main.js +2 -2
- package/build/src/helpers/types.d.ts +109 -16
- package/build/src/helpers/types.js +3 -3
- package/build/src/ignitor/ace.js +3 -1
- package/build/src/ignitor/http.d.ts +2 -2
- package/build/src/ignitor/http.js +5 -1
- package/build/src/ignitor/main.d.ts +2 -2
- package/build/src/ignitor/main.js +1 -1
- package/build/src/test_utils/http.d.ts +2 -2
- package/build/src/test_utils/main.d.ts +3 -3
- package/build/src/test_utils/main.js +1 -1
- package/build/src/types.d.ts +18 -18
- package/build/stubs/make/command/main.stub +6 -4
- package/build/stubs/make/controller/actions.stub +14 -0
- package/build/stubs/make/controller/api.stub +6 -4
- package/build/stubs/make/controller/main.stub +6 -4
- package/build/stubs/make/controller/resource.stub +6 -4
- package/build/stubs/make/event/main.stub +5 -3
- package/build/stubs/make/exception/main.stub +5 -3
- package/build/stubs/make/listener/for_event.stub +6 -4
- package/build/stubs/make/listener/main.stub +5 -3
- package/build/stubs/make/middleware/main.stub +7 -5
- package/build/stubs/make/{preload_file → preload}/main.stub +5 -3
- package/build/stubs/make/provider/main.stub +6 -4
- package/build/stubs/make/service/main.stub +5 -3
- package/build/stubs/make/test/main.stub +5 -3
- package/build/stubs/make/validator/main.stub +7 -0
- package/build/stubs/make/validator/resource.stub +26 -0
- package/build/stubs/make/view/main.stub +6 -0
- package/build/types/bodyparser.js +1 -1
- package/build/types/helpers.d.ts +1 -0
- package/build/types/helpers.js +9 -0
- package/build/types/http.d.ts +7 -0
- package/package.json +71 -56
- package/build/commands/make/_base.d.ts +0 -36
- package/build/commands/make/_base.js +0 -27
- package/build/modules/ace/shell.d.ts +0 -12
- package/build/modules/ace/shell.js +0 -49
- package/build/modules/hash/drivers_collection.d.ts +0 -21
- package/build/modules/hash/drivers_collection.js +0 -45
- package/build/modules/http.d.ts +0 -1
- package/build/providers/http_provider.d.ts +0 -26
- package/build/providers/http_provider.js +0 -61
- package/build/src/bindings/repl.d.ts +0 -6
- package/build/src/bindings/repl.js +0 -78
- /package/build/modules/{env.d.ts → env/main.d.ts} +0 -0
- /package/build/modules/{env.js → env/main.js} +0 -0
- /package/build/stubs/{index.d.ts → main.d.ts} +0 -0
- /package/build/stubs/{index.js → main.js} +0 -0
|
@@ -0,0 +1,259 @@
|
|
|
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 { EventEmitter } from 'node:events';
|
|
11
|
+
import { EnvEditor } from '@adonisjs/env/editor';
|
|
12
|
+
/**
|
|
13
|
+
* Codemods to modify AdonisJS source files. The codemod APIs relies on
|
|
14
|
+
* "@adonisjs/assembler" package and it must be installed as a dependency
|
|
15
|
+
* inside user application.
|
|
16
|
+
*/
|
|
17
|
+
export class Codemods extends EventEmitter {
|
|
18
|
+
/**
|
|
19
|
+
* Flag to know if assembler is installed as a
|
|
20
|
+
* peer dependency or not.
|
|
21
|
+
*/
|
|
22
|
+
#isAssemblerInstalled;
|
|
23
|
+
/**
|
|
24
|
+
* Reference to lazily imported assembler code transformer
|
|
25
|
+
*/
|
|
26
|
+
#codeTransformer;
|
|
27
|
+
/**
|
|
28
|
+
* Reference to AdonisJS application
|
|
29
|
+
*/
|
|
30
|
+
#app;
|
|
31
|
+
/**
|
|
32
|
+
* Reference to CLI logger to write logs
|
|
33
|
+
*/
|
|
34
|
+
#cliLogger;
|
|
35
|
+
/**
|
|
36
|
+
* Overwrite existing files when generating files
|
|
37
|
+
* from stubs
|
|
38
|
+
*/
|
|
39
|
+
overwriteExisting = false;
|
|
40
|
+
/**
|
|
41
|
+
* Display verbose logs for package installation
|
|
42
|
+
*/
|
|
43
|
+
verboseInstallOutput = false;
|
|
44
|
+
constructor(app, cliLogger) {
|
|
45
|
+
super();
|
|
46
|
+
this.#app = app;
|
|
47
|
+
this.#cliLogger = cliLogger;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Lazily imports assembler
|
|
51
|
+
*/
|
|
52
|
+
async #importAssembler() {
|
|
53
|
+
if (this.#isAssemblerInstalled === undefined) {
|
|
54
|
+
this.#codeTransformer = await import('@adonisjs/assembler/code_transformer');
|
|
55
|
+
this.#isAssemblerInstalled = !!this.#codeTransformer;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Returns the installation command for different
|
|
60
|
+
* package managers
|
|
61
|
+
*/
|
|
62
|
+
#getInstallationCommands(packages, packageManager, isDev) {
|
|
63
|
+
if (!packages.length) {
|
|
64
|
+
return '';
|
|
65
|
+
}
|
|
66
|
+
const colors = this.#cliLogger.getColors();
|
|
67
|
+
const devFlag = isDev ? ' -D' : '';
|
|
68
|
+
switch (packageManager) {
|
|
69
|
+
case 'yarn':
|
|
70
|
+
return `${colors.yellow(`yarn add${devFlag}`)} ${packages.join(' ')}`;
|
|
71
|
+
case 'pnpm':
|
|
72
|
+
return `${colors.yellow(`pnpm add${devFlag}`)} ${packages.join(' ')}`;
|
|
73
|
+
case 'npm':
|
|
74
|
+
default:
|
|
75
|
+
return `${colors.yellow(`npm i${devFlag}`)} ${packages.join(' ')}`;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Define one or more environment variables
|
|
80
|
+
*/
|
|
81
|
+
async defineEnvVariables(environmentVariables) {
|
|
82
|
+
const editor = new EnvEditor(this.#app.appRoot);
|
|
83
|
+
await editor.load();
|
|
84
|
+
Object.keys(environmentVariables).forEach((key) => {
|
|
85
|
+
const value = environmentVariables[key];
|
|
86
|
+
editor.add(key, value);
|
|
87
|
+
});
|
|
88
|
+
await editor.save();
|
|
89
|
+
this.#cliLogger.action('update .env file').succeeded();
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Define validations for the environment variables
|
|
93
|
+
*/
|
|
94
|
+
async defineEnvValidations(validations) {
|
|
95
|
+
await this.#importAssembler();
|
|
96
|
+
if (!this.#codeTransformer) {
|
|
97
|
+
this.#cliLogger.warning('Cannot update "start/env.ts" file. Install "@adonisjs/assembler" to modify source files');
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const transformer = new this.#codeTransformer.CodeTransformer(this.#app.appRoot);
|
|
101
|
+
const action = this.#cliLogger.action('update start/env.ts file');
|
|
102
|
+
try {
|
|
103
|
+
await transformer.defineEnvValidations(validations);
|
|
104
|
+
action.succeeded();
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
this.emit('error', error);
|
|
108
|
+
action.failed(error.message);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Define validations for the environment variables
|
|
113
|
+
*/
|
|
114
|
+
async registerMiddleware(stack, middleware) {
|
|
115
|
+
await this.#importAssembler();
|
|
116
|
+
if (!this.#codeTransformer) {
|
|
117
|
+
this.#cliLogger.warning('Cannot update "start/kernel.ts" file. Install "@adonisjs/assembler" to modify source files');
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const transformer = new this.#codeTransformer.CodeTransformer(this.#app.appRoot);
|
|
121
|
+
const action = this.#cliLogger.action('update start/kernel.ts file');
|
|
122
|
+
try {
|
|
123
|
+
await transformer.addMiddlewareToStack(stack, middleware);
|
|
124
|
+
action.succeeded();
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
this.emit('error', error);
|
|
128
|
+
action.failed(error.message);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Register bouncer policies to the list of policies
|
|
133
|
+
* collection exported from the "app/policies/main.ts"
|
|
134
|
+
* file.
|
|
135
|
+
*/
|
|
136
|
+
async registerPolicies(policies) {
|
|
137
|
+
await this.#importAssembler();
|
|
138
|
+
if (!this.#codeTransformer) {
|
|
139
|
+
this.#cliLogger.warning('Cannot update "app/policies/main.ts" file. Install "@adonisjs/assembler" to modify source files');
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const transformer = new this.#codeTransformer.CodeTransformer(this.#app.appRoot);
|
|
143
|
+
const action = this.#cliLogger.action('update app/policies/main.ts file');
|
|
144
|
+
try {
|
|
145
|
+
await transformer.addPolicies(policies);
|
|
146
|
+
action.succeeded();
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
this.emit('error', error);
|
|
150
|
+
action.failed(error.message);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Update RCFile
|
|
155
|
+
*/
|
|
156
|
+
async updateRcFile(...params) {
|
|
157
|
+
await this.#importAssembler();
|
|
158
|
+
if (!this.#codeTransformer) {
|
|
159
|
+
this.#cliLogger.warning('Cannot update "adonisrc.ts" file. Install "@adonisjs/assembler" to modify source files');
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const transformer = new this.#codeTransformer.CodeTransformer(this.#app.appRoot);
|
|
163
|
+
const action = this.#cliLogger.action('update adonisrc.ts file');
|
|
164
|
+
try {
|
|
165
|
+
await transformer.updateRcFile(...params);
|
|
166
|
+
action.succeeded();
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
this.emit('error', error);
|
|
170
|
+
action.failed(error.message);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Generats the stub
|
|
175
|
+
*/
|
|
176
|
+
async makeUsingStub(stubsRoot, stubPath, stubState) {
|
|
177
|
+
const stubs = await this.#app.stubs.create();
|
|
178
|
+
const stub = await stubs.build(stubPath, { source: stubsRoot });
|
|
179
|
+
const output = await stub.generate({ force: this.overwriteExisting, ...stubState });
|
|
180
|
+
const entityFileName = slash(this.#app.relativePath(output.destination));
|
|
181
|
+
const result = { ...output, relativeFileName: entityFileName };
|
|
182
|
+
if (output.status === 'skipped') {
|
|
183
|
+
this.#cliLogger.action(`create ${entityFileName}`).skipped(output.skipReason);
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
this.#cliLogger.action(`create ${entityFileName}`).succeeded();
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Install packages using the correct package manager
|
|
191
|
+
* You can specify version of each package by setting it in the
|
|
192
|
+
* name like :
|
|
193
|
+
*
|
|
194
|
+
* ```
|
|
195
|
+
* this.installPackages(['@adonisjs/lucid@next', '@adonisjs/auth@3.0.0'])
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
async installPackages(packages) {
|
|
199
|
+
await this.#importAssembler();
|
|
200
|
+
const appPath = this.#app.makePath();
|
|
201
|
+
const colors = this.#cliLogger.getColors();
|
|
202
|
+
const devDependencies = packages.filter((pkg) => pkg.isDevDependency).map(({ name }) => name);
|
|
203
|
+
const dependencies = packages.filter((pkg) => !pkg.isDevDependency).map(({ name }) => name);
|
|
204
|
+
if (!this.#codeTransformer) {
|
|
205
|
+
this.#cliLogger.warning('Cannot install packages. Install "@adonisjs/assembler" or manually install following packages');
|
|
206
|
+
this.#cliLogger.log(`devDependencies: ${devDependencies.join(',')}`);
|
|
207
|
+
this.#cliLogger.log(`dependencies: ${dependencies.join(',')}`);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const transformer = new this.#codeTransformer.CodeTransformer(this.#app.appRoot);
|
|
211
|
+
const packageManager = await transformer.detectPackageManager(appPath);
|
|
212
|
+
const spinner = this.#cliLogger.await(`installing dependencies using ${packageManager || 'npm'} `);
|
|
213
|
+
const silentLogs = !this.verboseInstallOutput;
|
|
214
|
+
if (silentLogs) {
|
|
215
|
+
spinner.start();
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
await transformer.installPackage(dependencies, {
|
|
219
|
+
cwd: appPath,
|
|
220
|
+
silent: silentLogs,
|
|
221
|
+
});
|
|
222
|
+
await transformer.installPackage(devDependencies, {
|
|
223
|
+
dev: true,
|
|
224
|
+
cwd: appPath,
|
|
225
|
+
silent: silentLogs,
|
|
226
|
+
});
|
|
227
|
+
if (silentLogs) {
|
|
228
|
+
spinner.stop();
|
|
229
|
+
}
|
|
230
|
+
this.#cliLogger.success('Packages installed');
|
|
231
|
+
this.#cliLogger.log(devDependencies.map((dependency) => ` ${colors.dim('dev')} ${dependency} `).join('\n'));
|
|
232
|
+
this.#cliLogger.log(dependencies.map((dependency) => ` ${colors.dim('prod')} ${dependency} `).join('\n'));
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
if (silentLogs) {
|
|
236
|
+
spinner.update('unable to install dependencies');
|
|
237
|
+
spinner.stop();
|
|
238
|
+
}
|
|
239
|
+
this.#cliLogger.fatal(error);
|
|
240
|
+
this.emit('error', error);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* List the packages one should install before using the packages
|
|
245
|
+
*/
|
|
246
|
+
async listPackagesToInstall(packages) {
|
|
247
|
+
const appPath = this.#app.makePath();
|
|
248
|
+
const devDependencies = packages.filter((pkg) => pkg.isDevDependency).map(({ name }) => name);
|
|
249
|
+
const dependencies = packages.filter((pkg) => !pkg.isDevDependency).map(({ name }) => name);
|
|
250
|
+
let packageManager = null;
|
|
251
|
+
if (this.#codeTransformer) {
|
|
252
|
+
const transformer = new this.#codeTransformer.CodeTransformer(this.#app.appRoot);
|
|
253
|
+
packageManager = await transformer.detectPackageManager(appPath);
|
|
254
|
+
}
|
|
255
|
+
this.#cliLogger.log('Please install following packages');
|
|
256
|
+
this.#cliLogger.log(this.#getInstallationCommands(devDependencies, packageManager || 'npm', true));
|
|
257
|
+
this.#cliLogger.log(this.#getInstallationCommands(dependencies, packageManager || 'npm', false));
|
|
258
|
+
}
|
|
259
|
+
}
|
|
@@ -2,36 +2,6 @@ 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
|
-
* Wrapper around the stub generation logic.
|
|
7
|
-
* Allow commands to easily generate files from given stubs
|
|
8
|
-
*/
|
|
9
|
-
declare class StubGenerator {
|
|
10
|
-
#private;
|
|
11
|
-
constructor(command: BaseCommand, flags: Record<string, any>);
|
|
12
|
-
generate(stubsRoot: string, stubPath: string, stubState: Record<string, any>): Promise<{
|
|
13
|
-
relativeFileName: string;
|
|
14
|
-
contents: any;
|
|
15
|
-
destination: any;
|
|
16
|
-
attributes: any;
|
|
17
|
-
status: "created";
|
|
18
|
-
skipReason: null;
|
|
19
|
-
} | {
|
|
20
|
-
relativeFileName: string;
|
|
21
|
-
contents: any;
|
|
22
|
-
destination: any;
|
|
23
|
-
attributes: any;
|
|
24
|
-
status: "force_created";
|
|
25
|
-
skipReason: null;
|
|
26
|
-
} | {
|
|
27
|
-
relativeFileName: string;
|
|
28
|
-
contents: any;
|
|
29
|
-
destination: any;
|
|
30
|
-
attributes: any;
|
|
31
|
-
status: "skipped";
|
|
32
|
-
skipReason: string;
|
|
33
|
-
}>;
|
|
34
|
-
}
|
|
35
5
|
/**
|
|
36
6
|
* The base command to create custom ace commands. The AdonisJS base commands
|
|
37
7
|
* receives the application instance
|
|
@@ -39,11 +9,14 @@ declare class StubGenerator {
|
|
|
39
9
|
export declare class BaseCommand extends AceBaseCommand {
|
|
40
10
|
app: ApplicationService;
|
|
41
11
|
kernel: Kernel;
|
|
42
|
-
stubGenerator: StubGenerator;
|
|
43
12
|
static options: CommandOptions;
|
|
44
13
|
get staysAlive(): boolean | undefined;
|
|
45
14
|
get startApp(): boolean | undefined;
|
|
46
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>;
|
|
47
20
|
/**
|
|
48
21
|
* The prepare template method is used to prepare the
|
|
49
22
|
* state for the command. This is the first method
|
|
@@ -65,31 +38,6 @@ export declare class BaseCommand extends AceBaseCommand {
|
|
|
65
38
|
* reporting to the kernel layer.
|
|
66
39
|
*/
|
|
67
40
|
completed?(..._: any[]): any;
|
|
68
|
-
/**
|
|
69
|
-
* Make a new file using the given stub
|
|
70
|
-
*/
|
|
71
|
-
makeUsingStub(stubPath: string, stubState: Record<string, any>, stubsRoot: string): Promise<{
|
|
72
|
-
relativeFileName: string;
|
|
73
|
-
contents: any;
|
|
74
|
-
destination: any;
|
|
75
|
-
attributes: any;
|
|
76
|
-
status: "created";
|
|
77
|
-
skipReason: null;
|
|
78
|
-
} | {
|
|
79
|
-
relativeFileName: string;
|
|
80
|
-
contents: any;
|
|
81
|
-
destination: any;
|
|
82
|
-
attributes: any;
|
|
83
|
-
status: "force_created";
|
|
84
|
-
skipReason: null;
|
|
85
|
-
} | {
|
|
86
|
-
relativeFileName: string;
|
|
87
|
-
contents: any;
|
|
88
|
-
destination: any;
|
|
89
|
-
attributes: any;
|
|
90
|
-
status: "skipped";
|
|
91
|
-
skipReason: string;
|
|
92
|
-
}>;
|
|
93
41
|
/**
|
|
94
42
|
* Executes the command
|
|
95
43
|
*/
|
|
@@ -108,36 +56,14 @@ export declare class BaseCommand extends AceBaseCommand {
|
|
|
108
56
|
export declare class ListCommand extends AceListCommand implements BaseCommand {
|
|
109
57
|
app: ApplicationService;
|
|
110
58
|
kernel: Kernel;
|
|
111
|
-
stubGenerator: StubGenerator;
|
|
112
59
|
static options: CommandOptions;
|
|
113
60
|
get staysAlive(): boolean | undefined;
|
|
114
61
|
get startApp(): boolean | undefined;
|
|
115
62
|
constructor(app: ApplicationService, kernel: Kernel, parsed: ParsedOutput, ui: UIPrimitives, prompt: Kernel['prompt']);
|
|
116
63
|
/**
|
|
117
|
-
*
|
|
64
|
+
* Creates the codemods module to modify source files
|
|
118
65
|
*/
|
|
119
|
-
|
|
120
|
-
relativeFileName: string;
|
|
121
|
-
contents: any;
|
|
122
|
-
destination: any;
|
|
123
|
-
attributes: any;
|
|
124
|
-
status: "created";
|
|
125
|
-
skipReason: null;
|
|
126
|
-
} | {
|
|
127
|
-
relativeFileName: string;
|
|
128
|
-
contents: any;
|
|
129
|
-
destination: any;
|
|
130
|
-
attributes: any;
|
|
131
|
-
status: "force_created";
|
|
132
|
-
skipReason: null;
|
|
133
|
-
} | {
|
|
134
|
-
relativeFileName: string;
|
|
135
|
-
contents: any;
|
|
136
|
-
destination: any;
|
|
137
|
-
attributes: any;
|
|
138
|
-
status: "skipped";
|
|
139
|
-
skipReason: string;
|
|
140
|
-
}>;
|
|
66
|
+
createCodemods(): Promise<import("./codemods.js").Codemods>;
|
|
141
67
|
/**
|
|
142
68
|
* Terminate the app. A command should prefer calling this method
|
|
143
69
|
* over the "app.terminate", because this method only triggers
|
|
@@ -146,4 +72,3 @@ export declare class ListCommand extends AceListCommand implements BaseCommand {
|
|
|
146
72
|
*/
|
|
147
73
|
terminate(): Promise<void>;
|
|
148
74
|
}
|
|
149
|
-
export {};
|
|
@@ -6,32 +6,7 @@
|
|
|
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 { slash } from '@poppinss/utils';
|
|
10
9
|
import { BaseCommand as AceBaseCommand, ListCommand as AceListCommand } from '@adonisjs/ace';
|
|
11
|
-
/**
|
|
12
|
-
* Wrapper around the stub generation logic.
|
|
13
|
-
* Allow commands to easily generate files from given stubs
|
|
14
|
-
*/
|
|
15
|
-
class StubGenerator {
|
|
16
|
-
#command;
|
|
17
|
-
#flags;
|
|
18
|
-
constructor(command, flags) {
|
|
19
|
-
this.#command = command;
|
|
20
|
-
this.#flags = flags;
|
|
21
|
-
}
|
|
22
|
-
async generate(stubsRoot, stubPath, stubState) {
|
|
23
|
-
const stub = await this.#command.app.stubs.build(stubPath, { source: stubsRoot });
|
|
24
|
-
const output = await stub.generate(Object.assign({ flags: this.#flags }, stubState));
|
|
25
|
-
const entityFileName = slash(this.#command.app.relativePath(output.destination));
|
|
26
|
-
const result = { ...output, relativeFileName: entityFileName };
|
|
27
|
-
if (output.status === 'skipped') {
|
|
28
|
-
this.#command.logger.action(`create ${entityFileName}`).skipped(output.skipReason);
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
31
|
-
this.#command.logger.action(`create ${entityFileName}`).succeeded();
|
|
32
|
-
return result;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
10
|
/**
|
|
36
11
|
* The base command to create custom ace commands. The AdonisJS base commands
|
|
37
12
|
* receives the application instance
|
|
@@ -39,7 +14,6 @@ class StubGenerator {
|
|
|
39
14
|
export class BaseCommand extends AceBaseCommand {
|
|
40
15
|
app;
|
|
41
16
|
kernel;
|
|
42
|
-
stubGenerator = new StubGenerator(this, this.parsed?.flags || {});
|
|
43
17
|
static options = {};
|
|
44
18
|
get staysAlive() {
|
|
45
19
|
return this.constructor.options.staysAlive;
|
|
@@ -53,10 +27,15 @@ export class BaseCommand extends AceBaseCommand {
|
|
|
53
27
|
this.kernel = kernel;
|
|
54
28
|
}
|
|
55
29
|
/**
|
|
56
|
-
*
|
|
30
|
+
* Creates the codemods module to modify source files
|
|
57
31
|
*/
|
|
58
|
-
async
|
|
59
|
-
|
|
32
|
+
async createCodemods() {
|
|
33
|
+
const { Codemods } = await import('./codemods.js');
|
|
34
|
+
const codemods = new Codemods(this.app, this.logger);
|
|
35
|
+
codemods.on('error', () => {
|
|
36
|
+
this.exitCode = 1;
|
|
37
|
+
});
|
|
38
|
+
return codemods;
|
|
60
39
|
}
|
|
61
40
|
/**
|
|
62
41
|
* Executes the command
|
|
@@ -110,7 +89,6 @@ export class BaseCommand extends AceBaseCommand {
|
|
|
110
89
|
export class ListCommand extends AceListCommand {
|
|
111
90
|
app;
|
|
112
91
|
kernel;
|
|
113
|
-
stubGenerator = new StubGenerator(this, this.parsed?.flags || {});
|
|
114
92
|
static options = {};
|
|
115
93
|
get staysAlive() {
|
|
116
94
|
return this.constructor.options.staysAlive;
|
|
@@ -124,10 +102,11 @@ export class ListCommand extends AceListCommand {
|
|
|
124
102
|
this.kernel = kernel;
|
|
125
103
|
}
|
|
126
104
|
/**
|
|
127
|
-
*
|
|
105
|
+
* Creates the codemods module to modify source files
|
|
128
106
|
*/
|
|
129
|
-
async
|
|
130
|
-
|
|
107
|
+
async createCodemods() {
|
|
108
|
+
const { Codemods } = await import('./codemods.js');
|
|
109
|
+
return new Codemods(this.app, this.logger);
|
|
131
110
|
}
|
|
132
111
|
/**
|
|
133
112
|
* Terminate the app. A command should prefer calling this method
|
|
@@ -9,4 +9,4 @@ import type { ApplicationService } from '../../src/types.js';
|
|
|
9
9
|
* - In other environments, ace can be pulled from the container to
|
|
10
10
|
* run commands
|
|
11
11
|
*/
|
|
12
|
-
export declare function createAceKernel(app: ApplicationService): Kernel;
|
|
12
|
+
export declare function createAceKernel(app: ApplicationService, commandName?: string): Kernel;
|
|
@@ -17,16 +17,32 @@ import { FsLoader, HelpCommand } from '../../modules/ace/main.js';
|
|
|
17
17
|
* - In other environments, ace can be pulled from the container to
|
|
18
18
|
* run commands
|
|
19
19
|
*/
|
|
20
|
-
export function createAceKernel(app) {
|
|
20
|
+
export function createAceKernel(app, commandName) {
|
|
21
21
|
const kernel = new Kernel(app);
|
|
22
|
-
kernel.addLoader(new FsLoader(app.commandsPath()));
|
|
23
22
|
kernel.info.set('binary', 'node ace');
|
|
24
23
|
/**
|
|
25
24
|
* Lazy import commands mentioned in the "commands" array
|
|
26
25
|
* of rcFile
|
|
27
26
|
*/
|
|
28
27
|
app.rcFile.commands.forEach((commandModule) => {
|
|
29
|
-
kernel.addLoader(() => app.import(commandModule));
|
|
28
|
+
kernel.addLoader(() => typeof commandModule === 'function' ? commandModule() : app.import(commandModule));
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* When we know the command we are running ahead of time, then we
|
|
32
|
+
* defer loading the application commands if the command has
|
|
33
|
+
* already been registered by other loaders.
|
|
34
|
+
*/
|
|
35
|
+
const fsLoader = new FsLoader(app.commandsPath());
|
|
36
|
+
kernel.addLoader({
|
|
37
|
+
async getMetaData() {
|
|
38
|
+
if (!commandName || !kernel.getCommand(commandName)) {
|
|
39
|
+
return fsLoader.getMetaData();
|
|
40
|
+
}
|
|
41
|
+
return [];
|
|
42
|
+
},
|
|
43
|
+
getCommand(command) {
|
|
44
|
+
return fsLoader.getCommand(command);
|
|
45
|
+
},
|
|
30
46
|
});
|
|
31
47
|
/**
|
|
32
48
|
* Custom global flags
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@adonisjs/env/editor';
|
|
@@ -1,18 +1,35 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { Argon } from './drivers/argon.js';
|
|
2
|
+
import type { Scrypt } from './drivers/scrypt.js';
|
|
3
|
+
import type { Bcrypt } from './drivers/bcrypt.js';
|
|
4
|
+
import type { ConfigProvider } from '../../src/types.js';
|
|
5
|
+
import type { ArgonConfig, BcryptConfig, ScryptConfig, ManagerDriverFactory } from '../../types/hash.js';
|
|
3
6
|
/**
|
|
4
|
-
*
|
|
7
|
+
* Resolved config from the config provider will be
|
|
8
|
+
* the config accepted by the hash manager
|
|
5
9
|
*/
|
|
6
|
-
|
|
7
|
-
[K in keyof HashDriversList]: {
|
|
8
|
-
driver: K;
|
|
9
|
-
} & Parameters<HashDriversList[K]>[0];
|
|
10
|
-
}[keyof HashDriversList]>>(config: {
|
|
11
|
-
default?: keyof KnownHashers;
|
|
12
|
-
list: KnownHashers;
|
|
13
|
-
}): {
|
|
10
|
+
type ResolvedConfig<KnownHashers extends Record<string, ManagerDriverFactory | ConfigProvider<ManagerDriverFactory>>> = {
|
|
14
11
|
default?: keyof KnownHashers;
|
|
15
12
|
list: {
|
|
16
|
-
[K in keyof KnownHashers]:
|
|
13
|
+
[K in keyof KnownHashers]: KnownHashers[K] extends ConfigProvider<infer A> ? A : KnownHashers[K];
|
|
17
14
|
};
|
|
18
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Define config for the hash service.
|
|
18
|
+
*/
|
|
19
|
+
export declare function defineConfig<KnownHashers extends Record<string, ManagerDriverFactory | ConfigProvider<ManagerDriverFactory>>>(config: {
|
|
20
|
+
default?: keyof KnownHashers;
|
|
21
|
+
list: KnownHashers;
|
|
22
|
+
}): ConfigProvider<ResolvedConfig<KnownHashers>>;
|
|
23
|
+
/**
|
|
24
|
+
* Helpers to configure drivers inside the config file. The
|
|
25
|
+
* drivers will be imported and constructed lazily.
|
|
26
|
+
*
|
|
27
|
+
* - Import happens when you first use the hash module
|
|
28
|
+
* - Construction of drivers happens when you first use a driver
|
|
29
|
+
*/
|
|
30
|
+
export declare const drivers: {
|
|
31
|
+
argon2: (config: ArgonConfig) => ConfigProvider<() => Argon>;
|
|
32
|
+
bcrypt: (config: BcryptConfig) => ConfigProvider<() => Bcrypt>;
|
|
33
|
+
scrypt: (config: ScryptConfig) => ConfigProvider<() => Scrypt>;
|
|
34
|
+
};
|
|
35
|
+
export {};
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
9
|
import { InvalidArgumentsException } from '@poppinss/utils';
|
|
10
|
-
import
|
|
10
|
+
import debug from '../../src/debug.js';
|
|
11
|
+
import { configProvider } from '../../src/config_provider.js';
|
|
11
12
|
/**
|
|
12
13
|
* Define config for the hash service.
|
|
13
14
|
*/
|
|
@@ -25,15 +26,55 @@ export function defineConfig(config) {
|
|
|
25
26
|
throw new InvalidArgumentsException(`Missing "list.${String(config.default)}" in hash config. It is referenced by the "default" property`);
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
28
|
-
*
|
|
29
|
+
* Config provider to lazily import drivers as they are used inside
|
|
30
|
+
* the user application
|
|
29
31
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
return configProvider.create(async (app) => {
|
|
33
|
+
debug('resolving hash config');
|
|
34
|
+
const hashersList = Object.keys(config.list);
|
|
35
|
+
const hashers = {};
|
|
36
|
+
for (let hasherName of hashersList) {
|
|
37
|
+
const hasher = config.list[hasherName];
|
|
38
|
+
if (typeof hasher === 'function') {
|
|
39
|
+
hashers[hasherName] = hasher;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
hashers[hasherName] = await hasher.resolver(app);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
default: config.default,
|
|
47
|
+
list: hashers,
|
|
48
|
+
};
|
|
49
|
+
});
|
|
39
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Helpers to configure drivers inside the config file. The
|
|
53
|
+
* drivers will be imported and constructed lazily.
|
|
54
|
+
*
|
|
55
|
+
* - Import happens when you first use the hash module
|
|
56
|
+
* - Construction of drivers happens when you first use a driver
|
|
57
|
+
*/
|
|
58
|
+
export const drivers = {
|
|
59
|
+
argon2: (config) => {
|
|
60
|
+
return configProvider.create(async () => {
|
|
61
|
+
const { Argon } = await import('./drivers/argon.js');
|
|
62
|
+
debug('configuring argon driver');
|
|
63
|
+
return () => new Argon(config);
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
bcrypt: (config) => {
|
|
67
|
+
return configProvider.create(async () => {
|
|
68
|
+
const { Bcrypt } = await import('./drivers/bcrypt.js');
|
|
69
|
+
debug('configuring bcrypt driver');
|
|
70
|
+
return () => new Bcrypt(config);
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
scrypt: (config) => {
|
|
74
|
+
return configProvider.create(async () => {
|
|
75
|
+
const { Scrypt } = await import('./drivers/scrypt.js');
|
|
76
|
+
debug('configuring scrypt driver');
|
|
77
|
+
return () => new Scrypt(config);
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@adonisjs/hash/drivers/argon';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@adonisjs/hash/drivers/bcrypt';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@adonisjs/hash/drivers/scrypt';
|