@adonisjs/core 6.1.5-33 → 6.1.5-35
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/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 +18 -23
- package/build/commands/configure.js +35 -108
- package/build/commands/generate_key.js +1 -1
- package/build/commands/make/controller.js +5 -5
- package/build/commands/make/exception.js +1 -1
- package/build/commands/make/listener.js +1 -1
- package/build/commands/make/middleware.js +16 -9
- package/build/commands/make/preload.d.ts +2 -1
- package/build/commands/make/preload.js +27 -33
- package/build/commands/make/provider.d.ts +6 -0
- package/build/commands/make/provider.js +51 -6
- package/build/commands/make/test.js +1 -1
- package/build/commands/make/validator.d.ts +5 -0
- package/build/commands/make/validator.js +19 -3
- package/build/commands/serve.js +7 -4
- package/build/commands/test.js +2 -2
- package/build/modules/ace/codemods.d.ts +44 -4
- package/build/modules/ace/codemods.js +122 -2
- package/build/modules/ace/commands.js +5 -1
- package/build/providers/app_provider.js +6 -4
- package/build/providers/repl_provider.js +11 -2
- package/build/src/helpers/main.d.ts +1 -1
- package/build/src/helpers/main.js +1 -1
- package/build/src/types.d.ts +3 -4
- package/build/stubs/make/validator/resource.stub +26 -0
- package/package.json +32 -32
- /package/build/stubs/make/{preload_file → preload}/main.stub +0 -0
|
@@ -12,6 +12,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
12
12
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
13
13
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
14
14
|
};
|
|
15
|
+
import { extname, relative } from 'node:path';
|
|
15
16
|
import { stubsRoot } from '../../stubs/main.js';
|
|
16
17
|
import { args, flags, BaseCommand } from '../../modules/ace/main.js';
|
|
17
18
|
const ALLOWED_ENVIRONMENTS = ['web', 'console', 'test', 'repl'];
|
|
@@ -24,13 +25,7 @@ export default class MakePreload extends BaseCommand {
|
|
|
24
25
|
/**
|
|
25
26
|
* The stub to use for generating the preload file
|
|
26
27
|
*/
|
|
27
|
-
stubPath = 'make/
|
|
28
|
-
/**
|
|
29
|
-
* Check if the mentioned environments are valid
|
|
30
|
-
*/
|
|
31
|
-
#isValidEnvironment(environment) {
|
|
32
|
-
return !environment.find((one) => !ALLOWED_ENVIRONMENTS.includes(one));
|
|
33
|
-
}
|
|
28
|
+
stubPath = 'make/preload/main.stub';
|
|
34
29
|
/**
|
|
35
30
|
* Validate the environments flag passed by the user
|
|
36
31
|
*/
|
|
@@ -38,29 +33,12 @@ export default class MakePreload extends BaseCommand {
|
|
|
38
33
|
if (!this.environments || !this.environments.length) {
|
|
39
34
|
return true;
|
|
40
35
|
}
|
|
41
|
-
return this
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Prompt for the environments
|
|
45
|
-
*/
|
|
46
|
-
async #promptForEnvironments() {
|
|
47
|
-
const selectedEnvironments = await this.prompt.multiple('Select the environment(s) in which you want to load this file', [
|
|
48
|
-
{ name: 'all', message: 'Load file in all environments' },
|
|
49
|
-
{ name: 'console', message: 'Environment for ace commands' },
|
|
50
|
-
{ name: 'repl', message: 'Environment for the REPL session' },
|
|
51
|
-
{ name: 'web', message: 'Environment for HTTP requests' },
|
|
52
|
-
{ name: 'test', message: 'Environment for the test process' },
|
|
53
|
-
]);
|
|
54
|
-
if (selectedEnvironments.includes('all')) {
|
|
55
|
-
return ['web', 'console', 'test', 'repl'];
|
|
56
|
-
}
|
|
57
|
-
return selectedEnvironments;
|
|
36
|
+
return this.environments.every((one) => ALLOWED_ENVIRONMENTS.includes(one));
|
|
58
37
|
}
|
|
59
38
|
/**
|
|
60
39
|
* Run command
|
|
61
40
|
*/
|
|
62
41
|
async run() {
|
|
63
|
-
let environments = this.environments;
|
|
64
42
|
/**
|
|
65
43
|
* Ensure the environments are valid when provided via flag
|
|
66
44
|
*/
|
|
@@ -69,31 +47,47 @@ export default class MakePreload extends BaseCommand {
|
|
|
69
47
|
return;
|
|
70
48
|
}
|
|
71
49
|
/**
|
|
72
|
-
*
|
|
50
|
+
* Display prompt to know if we should register the preload
|
|
51
|
+
* file inside the ".adonisrc.ts" file.
|
|
73
52
|
*/
|
|
74
|
-
if (
|
|
75
|
-
|
|
53
|
+
if (this.register === undefined) {
|
|
54
|
+
this.register = await this.prompt.confirm('Do you want to register the preload file in .adonisrc.ts file?');
|
|
76
55
|
}
|
|
77
56
|
const codemods = await this.createCodemods();
|
|
78
|
-
const
|
|
57
|
+
const { destination } = await codemods.makeUsingStub(stubsRoot, this.stubPath, {
|
|
79
58
|
flags: this.parsed.flags,
|
|
80
59
|
entity: this.app.generators.createEntity(this.name),
|
|
81
60
|
});
|
|
82
61
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
62
|
+
* Do not register when prompt has been denied or "--no-register"
|
|
63
|
+
* flag was used
|
|
85
64
|
*/
|
|
86
|
-
|
|
65
|
+
if (!this.register) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Creative relative path for the preload file from
|
|
70
|
+
* the "./start" directory
|
|
71
|
+
*/
|
|
72
|
+
const preloadFileRelativePath = relative(this.app.startPath(), destination).replace(extname(destination), '');
|
|
87
73
|
await codemods.updateRcFile((rcFile) => {
|
|
88
|
-
rcFile.addPreloadFile(
|
|
74
|
+
rcFile.addPreloadFile(`#start/${preloadFileRelativePath}`, this.environments);
|
|
89
75
|
});
|
|
90
76
|
}
|
|
91
77
|
}
|
|
92
78
|
__decorate([
|
|
93
79
|
args.string({ description: 'Name of the preload file' })
|
|
94
80
|
], MakePreload.prototype, "name", void 0);
|
|
81
|
+
__decorate([
|
|
82
|
+
flags.boolean({
|
|
83
|
+
description: 'Auto register the preload file inside the .adonisrc.ts file',
|
|
84
|
+
showNegatedVariantInHelp: true,
|
|
85
|
+
alias: 'r',
|
|
86
|
+
})
|
|
87
|
+
], MakePreload.prototype, "register", void 0);
|
|
95
88
|
__decorate([
|
|
96
89
|
flags.array({
|
|
97
90
|
description: `Define the preload file's environment. Accepted values are "${ALLOWED_ENVIRONMENTS}"`,
|
|
91
|
+
alias: 'e',
|
|
98
92
|
})
|
|
99
93
|
], MakePreload.prototype, "environments", void 0);
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import { BaseCommand } from '../../modules/ace/main.js';
|
|
2
|
+
declare const ALLOWED_ENVIRONMENTS: ("web" | "console" | "test" | "repl")[];
|
|
3
|
+
type AllowedAppEnvironments = typeof ALLOWED_ENVIRONMENTS;
|
|
2
4
|
/**
|
|
3
5
|
* Make a new provider class
|
|
4
6
|
*/
|
|
5
7
|
export default class MakeProvider extends BaseCommand {
|
|
8
|
+
#private;
|
|
6
9
|
static commandName: string;
|
|
7
10
|
static description: string;
|
|
8
11
|
name: string;
|
|
12
|
+
register?: boolean;
|
|
13
|
+
environments?: AllowedAppEnvironments;
|
|
9
14
|
/**
|
|
10
15
|
* The stub to use for generating the provider class
|
|
11
16
|
*/
|
|
12
17
|
protected stubPath: string;
|
|
13
18
|
run(): Promise<void>;
|
|
14
19
|
}
|
|
20
|
+
export {};
|
|
@@ -12,8 +12,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
12
12
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
13
13
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
14
14
|
};
|
|
15
|
+
import { extname, relative } from 'node:path';
|
|
15
16
|
import { stubsRoot } from '../../stubs/main.js';
|
|
16
|
-
import { args, BaseCommand } from '../../modules/ace/main.js';
|
|
17
|
+
import { args, BaseCommand, flags } from '../../modules/ace/main.js';
|
|
18
|
+
const ALLOWED_ENVIRONMENTS = ['web', 'console', 'test', 'repl'];
|
|
17
19
|
/**
|
|
18
20
|
* Make a new provider class
|
|
19
21
|
*/
|
|
@@ -24,22 +26,65 @@ export default class MakeProvider extends BaseCommand {
|
|
|
24
26
|
* The stub to use for generating the provider class
|
|
25
27
|
*/
|
|
26
28
|
stubPath = 'make/provider/main.stub';
|
|
29
|
+
/**
|
|
30
|
+
* Validate the environments flag passed by the user
|
|
31
|
+
*/
|
|
32
|
+
#isEnvironmentsFlagValid() {
|
|
33
|
+
if (!this.environments || !this.environments.length) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return this.environments.every((one) => ALLOWED_ENVIRONMENTS.includes(one));
|
|
37
|
+
}
|
|
27
38
|
async run() {
|
|
39
|
+
/**
|
|
40
|
+
* Ensure the environments are valid when provided via flag
|
|
41
|
+
*/
|
|
42
|
+
if (!this.#isEnvironmentsFlagValid()) {
|
|
43
|
+
this.logger.error(`Invalid environment(s) "${this.environments}". Only "${ALLOWED_ENVIRONMENTS}" are allowed`);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Display prompt to know if we should register the provider
|
|
48
|
+
* file inside the ".adonisrc.ts" file.
|
|
49
|
+
*/
|
|
50
|
+
if (this.register === undefined) {
|
|
51
|
+
this.register = await this.prompt.confirm('Do you want to register the provider in .adonisrc.ts file?');
|
|
52
|
+
}
|
|
28
53
|
const codemods = await this.createCodemods();
|
|
29
|
-
const
|
|
54
|
+
const { destination } = await codemods.makeUsingStub(stubsRoot, this.stubPath, {
|
|
30
55
|
flags: this.parsed.flags,
|
|
31
56
|
entity: this.app.generators.createEntity(this.name),
|
|
32
57
|
});
|
|
33
58
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
59
|
+
* Do not register when prompt has been denied or "--no-register"
|
|
60
|
+
* flag was used
|
|
61
|
+
*/
|
|
62
|
+
if (!this.register) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Creative relative path for the provider file from
|
|
67
|
+
* the "./start" directory
|
|
36
68
|
*/
|
|
37
|
-
const
|
|
69
|
+
const providerRelativePath = relative(this.app.providersPath(), destination).replace(extname(destination), '');
|
|
38
70
|
await codemods.updateRcFile((rcFile) => {
|
|
39
|
-
rcFile.addProvider(
|
|
71
|
+
rcFile.addProvider(`#providers/${providerRelativePath}`, this.environments);
|
|
40
72
|
});
|
|
41
73
|
}
|
|
42
74
|
}
|
|
43
75
|
__decorate([
|
|
44
76
|
args.string({ description: 'Name of the provider' })
|
|
45
77
|
], MakeProvider.prototype, "name", void 0);
|
|
78
|
+
__decorate([
|
|
79
|
+
flags.boolean({
|
|
80
|
+
description: 'Auto register the provider inside the .adonisrc.ts file',
|
|
81
|
+
showNegatedVariantInHelp: true,
|
|
82
|
+
alias: 'r',
|
|
83
|
+
})
|
|
84
|
+
], MakeProvider.prototype, "register", void 0);
|
|
85
|
+
__decorate([
|
|
86
|
+
flags.array({
|
|
87
|
+
description: `Define the provider environment. Accepted values are "${ALLOWED_ENVIRONMENTS}"`,
|
|
88
|
+
alias: 'e',
|
|
89
|
+
})
|
|
90
|
+
], MakeProvider.prototype, "environments", void 0);
|
|
@@ -101,5 +101,5 @@ __decorate([
|
|
|
101
101
|
args.string({ description: 'Name of the test file' })
|
|
102
102
|
], MakeTest.prototype, "name", void 0);
|
|
103
103
|
__decorate([
|
|
104
|
-
flags.string({ description: 'The suite for which to create the test file' })
|
|
104
|
+
flags.string({ description: 'The suite for which to create the test file', alias: 's' })
|
|
105
105
|
], MakeTest.prototype, "suite", void 0);
|
|
@@ -6,9 +6,14 @@ export default class MakeValidator extends BaseCommand {
|
|
|
6
6
|
static commandName: string;
|
|
7
7
|
static description: string;
|
|
8
8
|
name: string;
|
|
9
|
+
resource: boolean;
|
|
9
10
|
/**
|
|
10
11
|
* The stub to use for generating the validator
|
|
11
12
|
*/
|
|
12
13
|
protected stubPath: string;
|
|
14
|
+
/**
|
|
15
|
+
* Preparing the command state
|
|
16
|
+
*/
|
|
17
|
+
prepare(): Promise<void>;
|
|
13
18
|
run(): Promise<void>;
|
|
14
19
|
}
|
|
@@ -13,17 +13,28 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
13
13
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
14
14
|
};
|
|
15
15
|
import { stubsRoot } from '../../stubs/main.js';
|
|
16
|
-
import { args, BaseCommand } from '../../modules/ace/main.js';
|
|
16
|
+
import { args, flags, BaseCommand } from '../../modules/ace/main.js';
|
|
17
17
|
/**
|
|
18
18
|
* Make a new VineJS validator
|
|
19
19
|
*/
|
|
20
20
|
export default class MakeValidator extends BaseCommand {
|
|
21
21
|
static commandName = 'make:validator';
|
|
22
|
-
static description = 'Create a new VineJS
|
|
22
|
+
static description = 'Create a new file to define VineJS validators';
|
|
23
23
|
/**
|
|
24
24
|
* The stub to use for generating the validator
|
|
25
25
|
*/
|
|
26
26
|
stubPath = 'make/validator/main.stub';
|
|
27
|
+
/**
|
|
28
|
+
* Preparing the command state
|
|
29
|
+
*/
|
|
30
|
+
async prepare() {
|
|
31
|
+
/**
|
|
32
|
+
* Use resource stub
|
|
33
|
+
*/
|
|
34
|
+
if (this.resource) {
|
|
35
|
+
this.stubPath = 'make/validator/resource.stub';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
27
38
|
async run() {
|
|
28
39
|
const codemods = await this.createCodemods();
|
|
29
40
|
await codemods.makeUsingStub(stubsRoot, this.stubPath, {
|
|
@@ -33,5 +44,10 @@ export default class MakeValidator extends BaseCommand {
|
|
|
33
44
|
}
|
|
34
45
|
}
|
|
35
46
|
__decorate([
|
|
36
|
-
args.string({ description: 'Name of the validator' })
|
|
47
|
+
args.string({ description: 'Name of the validator file' })
|
|
37
48
|
], MakeValidator.prototype, "name", void 0);
|
|
49
|
+
__decorate([
|
|
50
|
+
flags.boolean({
|
|
51
|
+
description: 'Create a file with pre-defined validators for create and update actions',
|
|
52
|
+
})
|
|
53
|
+
], MakeValidator.prototype, "resource", void 0);
|
package/build/commands/serve.js
CHANGED
|
@@ -56,13 +56,13 @@ export default class Serve extends BaseCommand {
|
|
|
56
56
|
const assetsBundler = await detectAssetsBundler(this.app);
|
|
57
57
|
return assetsBundler
|
|
58
58
|
? {
|
|
59
|
-
|
|
59
|
+
enabled: this.assets === false ? false : true,
|
|
60
60
|
driver: assetsBundler.name,
|
|
61
61
|
cmd: assetsBundler.devServer.command,
|
|
62
62
|
args: (assetsBundler.devServer.args || []).concat(this.assetsArgs || []),
|
|
63
63
|
}
|
|
64
64
|
: {
|
|
65
|
-
|
|
65
|
+
enabled: false,
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
@@ -119,10 +119,13 @@ export default class Serve extends BaseCommand {
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
__decorate([
|
|
122
|
-
flags.boolean({
|
|
122
|
+
flags.boolean({
|
|
123
|
+
description: 'Watch filesystem and restart the HTTP server on file change',
|
|
124
|
+
alias: 'w',
|
|
125
|
+
})
|
|
123
126
|
], Serve.prototype, "watch", void 0);
|
|
124
127
|
__decorate([
|
|
125
|
-
flags.boolean({ description: 'Use polling to detect filesystem changes' })
|
|
128
|
+
flags.boolean({ description: 'Use polling to detect filesystem changes', alias: 'p' })
|
|
126
129
|
], Serve.prototype, "poll", void 0);
|
|
127
130
|
__decorate([
|
|
128
131
|
flags.boolean({
|
package/build/commands/test.js
CHANGED
|
@@ -67,13 +67,13 @@ export default class Test extends BaseCommand {
|
|
|
67
67
|
const assetsBundler = await detectAssetsBundler(this.app);
|
|
68
68
|
return assetsBundler
|
|
69
69
|
? {
|
|
70
|
-
|
|
70
|
+
enabled: this.assets === false ? false : true,
|
|
71
71
|
driver: assetsBundler.name,
|
|
72
72
|
cmd: assetsBundler.devServer.command,
|
|
73
73
|
args: (assetsBundler.devServer.args || []).concat(this.assetsArgs || []),
|
|
74
74
|
}
|
|
75
75
|
: {
|
|
76
|
-
|
|
76
|
+
enabled: false,
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
@@ -1,14 +1,25 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
1
3
|
import type { Logger } from '@poppinss/cliui';
|
|
2
4
|
import type { CodeTransformer } from '@adonisjs/assembler/code_transformer';
|
|
3
|
-
import type {
|
|
5
|
+
import type { MiddlewareNode, EnvValidationNode, BouncerPolicyNode } from '@adonisjs/assembler/types';
|
|
4
6
|
import type { Application } from '../app.js';
|
|
5
7
|
/**
|
|
6
8
|
* Codemods to modify AdonisJS source files. The codemod APIs relies on
|
|
7
9
|
* "@adonisjs/assembler" package and it must be installed as a dependency
|
|
8
10
|
* inside user application.
|
|
9
11
|
*/
|
|
10
|
-
export declare class Codemods {
|
|
12
|
+
export declare class Codemods extends EventEmitter {
|
|
11
13
|
#private;
|
|
14
|
+
/**
|
|
15
|
+
* Overwrite existing files when generating files
|
|
16
|
+
* from stubs
|
|
17
|
+
*/
|
|
18
|
+
overwriteExisting: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Display verbose logs for package installation
|
|
21
|
+
*/
|
|
22
|
+
verboseInstallOutput: boolean;
|
|
12
23
|
constructor(app: Application<any>, cliLogger: Logger);
|
|
13
24
|
/**
|
|
14
25
|
* Define one or more environment variables
|
|
@@ -17,11 +28,17 @@ export declare class Codemods {
|
|
|
17
28
|
/**
|
|
18
29
|
* Define validations for the environment variables
|
|
19
30
|
*/
|
|
20
|
-
defineEnvValidations(validations:
|
|
31
|
+
defineEnvValidations(validations: EnvValidationNode): Promise<void>;
|
|
21
32
|
/**
|
|
22
33
|
* Define validations for the environment variables
|
|
23
34
|
*/
|
|
24
|
-
registerMiddleware(stack: 'server' | 'router' | 'named', middleware:
|
|
35
|
+
registerMiddleware(stack: 'server' | 'router' | 'named', middleware: MiddlewareNode[]): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Register bouncer policies to the list of policies
|
|
38
|
+
* collection exported from the "app/policies/main.ts"
|
|
39
|
+
* file.
|
|
40
|
+
*/
|
|
41
|
+
registerPolicies(policies: BouncerPolicyNode[]): Promise<void>;
|
|
25
42
|
/**
|
|
26
43
|
* Update RCFile
|
|
27
44
|
*/
|
|
@@ -46,9 +63,32 @@ export declare class Codemods {
|
|
|
46
63
|
} | {
|
|
47
64
|
relativeFileName: string;
|
|
48
65
|
contents: string;
|
|
66
|
+
/**
|
|
67
|
+
* Reference to AdonisJS application
|
|
68
|
+
*/
|
|
49
69
|
destination: any;
|
|
50
70
|
attributes: Record<string, any>;
|
|
51
71
|
status: "skipped";
|
|
52
72
|
skipReason: string;
|
|
53
73
|
}>;
|
|
74
|
+
/**
|
|
75
|
+
* Install packages using the correct package manager
|
|
76
|
+
* You can specify version of each package by setting it in the
|
|
77
|
+
* name like :
|
|
78
|
+
*
|
|
79
|
+
* ```
|
|
80
|
+
* this.installPackages(['@adonisjs/lucid@next', '@adonisjs/auth@3.0.0'])
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
installPackages(packages: {
|
|
84
|
+
name: string;
|
|
85
|
+
isDevDependency: boolean;
|
|
86
|
+
}[]): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* List the packages one should install before using the packages
|
|
89
|
+
*/
|
|
90
|
+
listPackagesToInstall(packages: {
|
|
91
|
+
name: string;
|
|
92
|
+
isDevDependency: boolean;
|
|
93
|
+
}[]): Promise<void>;
|
|
54
94
|
}
|
|
@@ -7,13 +7,14 @@
|
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
9
|
import { slash } from '@poppinss/utils';
|
|
10
|
+
import { EventEmitter } from 'node:events';
|
|
10
11
|
import { EnvEditor } from '@adonisjs/env/editor';
|
|
11
12
|
/**
|
|
12
13
|
* Codemods to modify AdonisJS source files. The codemod APIs relies on
|
|
13
14
|
* "@adonisjs/assembler" package and it must be installed as a dependency
|
|
14
15
|
* inside user application.
|
|
15
16
|
*/
|
|
16
|
-
export class Codemods {
|
|
17
|
+
export class Codemods extends EventEmitter {
|
|
17
18
|
/**
|
|
18
19
|
* Flag to know if assembler is installed as a
|
|
19
20
|
* peer dependency or not.
|
|
@@ -31,7 +32,17 @@ export class Codemods {
|
|
|
31
32
|
* Reference to CLI logger to write logs
|
|
32
33
|
*/
|
|
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;
|
|
34
44
|
constructor(app, cliLogger) {
|
|
45
|
+
super();
|
|
35
46
|
this.#app = app;
|
|
36
47
|
this.#cliLogger = cliLogger;
|
|
37
48
|
}
|
|
@@ -44,6 +55,26 @@ export class Codemods {
|
|
|
44
55
|
this.#isAssemblerInstalled = !!this.#codeTransformer;
|
|
45
56
|
}
|
|
46
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
|
+
}
|
|
47
78
|
/**
|
|
48
79
|
* Define one or more environment variables
|
|
49
80
|
*/
|
|
@@ -73,6 +104,7 @@ export class Codemods {
|
|
|
73
104
|
action.succeeded();
|
|
74
105
|
}
|
|
75
106
|
catch (error) {
|
|
107
|
+
this.emit('error', error);
|
|
76
108
|
action.failed(error.message);
|
|
77
109
|
}
|
|
78
110
|
}
|
|
@@ -92,6 +124,29 @@ export class Codemods {
|
|
|
92
124
|
action.succeeded();
|
|
93
125
|
}
|
|
94
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);
|
|
95
150
|
action.failed(error.message);
|
|
96
151
|
}
|
|
97
152
|
}
|
|
@@ -111,6 +166,7 @@ export class Codemods {
|
|
|
111
166
|
action.succeeded();
|
|
112
167
|
}
|
|
113
168
|
catch (error) {
|
|
169
|
+
this.emit('error', error);
|
|
114
170
|
action.failed(error.message);
|
|
115
171
|
}
|
|
116
172
|
}
|
|
@@ -120,7 +176,7 @@ export class Codemods {
|
|
|
120
176
|
async makeUsingStub(stubsRoot, stubPath, stubState) {
|
|
121
177
|
const stubs = await this.#app.stubs.create();
|
|
122
178
|
const stub = await stubs.build(stubPath, { source: stubsRoot });
|
|
123
|
-
const output = await stub.generate(stubState);
|
|
179
|
+
const output = await stub.generate({ force: this.overwriteExisting, ...stubState });
|
|
124
180
|
const entityFileName = slash(this.#app.relativePath(output.destination));
|
|
125
181
|
const result = { ...output, relativeFileName: entityFileName };
|
|
126
182
|
if (output.status === 'skipped') {
|
|
@@ -130,4 +186,68 @@ export class Codemods {
|
|
|
130
186
|
this.#cliLogger.action(`create ${entityFileName}`).succeeded();
|
|
131
187
|
return result;
|
|
132
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
|
+
let spinner = this.#cliLogger
|
|
213
|
+
.await(`installing dependencies using ${packageManager || 'npm'} `)
|
|
214
|
+
.start();
|
|
215
|
+
try {
|
|
216
|
+
await transformer.installPackage(dependencies, {
|
|
217
|
+
cwd: appPath,
|
|
218
|
+
silent: !this.verboseInstallOutput,
|
|
219
|
+
});
|
|
220
|
+
await transformer.installPackage(devDependencies, {
|
|
221
|
+
dev: true,
|
|
222
|
+
cwd: appPath,
|
|
223
|
+
silent: !this.verboseInstallOutput,
|
|
224
|
+
});
|
|
225
|
+
spinner.stop();
|
|
226
|
+
this.#cliLogger.success('Packages installed');
|
|
227
|
+
this.#cliLogger.log(devDependencies.map((dependency) => ` ${colors.dim('dev')} ${dependency} `).join('\n'));
|
|
228
|
+
this.#cliLogger.log(dependencies.map((dependency) => ` ${colors.dim('prod')} ${dependency} `).join('\n'));
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
spinner.update('unable to install dependencies');
|
|
232
|
+
spinner.stop();
|
|
233
|
+
this.#cliLogger.fatal(error);
|
|
234
|
+
this.emit('error', error);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* List the packages one should install before using the packages
|
|
239
|
+
*/
|
|
240
|
+
async listPackagesToInstall(packages) {
|
|
241
|
+
const appPath = this.#app.makePath();
|
|
242
|
+
const devDependencies = packages.filter((pkg) => pkg.isDevDependency).map(({ name }) => name);
|
|
243
|
+
const dependencies = packages.filter((pkg) => !pkg.isDevDependency).map(({ name }) => name);
|
|
244
|
+
let packageManager = null;
|
|
245
|
+
if (this.#codeTransformer) {
|
|
246
|
+
const transformer = new this.#codeTransformer.CodeTransformer(this.#app.appRoot);
|
|
247
|
+
packageManager = await transformer.detectPackageManager(appPath);
|
|
248
|
+
}
|
|
249
|
+
this.#cliLogger.log('Please install following packages');
|
|
250
|
+
this.#cliLogger.log(this.#getInstallationCommands(devDependencies, packageManager || 'npm', true));
|
|
251
|
+
this.#cliLogger.log(this.#getInstallationCommands(dependencies, packageManager || 'npm', false));
|
|
252
|
+
}
|
|
133
253
|
}
|
|
@@ -31,7 +31,11 @@ export class BaseCommand extends AceBaseCommand {
|
|
|
31
31
|
*/
|
|
32
32
|
async createCodemods() {
|
|
33
33
|
const { Codemods } = await import('./codemods.js');
|
|
34
|
-
|
|
34
|
+
const codemods = new Codemods(this.app, this.logger);
|
|
35
|
+
codemods.on('error', () => {
|
|
36
|
+
this.exitCode = 1;
|
|
37
|
+
});
|
|
38
|
+
return codemods;
|
|
35
39
|
}
|
|
36
40
|
/**
|
|
37
41
|
* Executes the command
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { Config } from '../modules/config.js';
|
|
10
10
|
import { Logger } from '../modules/logger.js';
|
|
11
|
-
import {
|
|
11
|
+
import { Application } from '../modules/app.js';
|
|
12
|
+
import { BaseEvent, Emitter } from '../modules/events.js';
|
|
12
13
|
import { Encryption } from '../modules/encryption.js';
|
|
13
14
|
import { Router, Server } from '../modules/http/main.js';
|
|
14
15
|
import BodyParserMiddleware from '../modules/bodyparser/bodyparser_middleware.js';
|
|
@@ -43,7 +44,8 @@ export default class AppServiceProvider {
|
|
|
43
44
|
* Registers the application to the container
|
|
44
45
|
*/
|
|
45
46
|
registerApp() {
|
|
46
|
-
this.app.container.singleton(
|
|
47
|
+
this.app.container.singleton(Application, () => this.app);
|
|
48
|
+
this.app.container.alias('app', Application);
|
|
47
49
|
}
|
|
48
50
|
/**
|
|
49
51
|
* Registers the logger class to resolve the default logger
|
|
@@ -75,10 +77,10 @@ export default class AppServiceProvider {
|
|
|
75
77
|
* Registers emitter service to the container
|
|
76
78
|
*/
|
|
77
79
|
registerEmitter() {
|
|
78
|
-
this.app.container.singleton(
|
|
79
|
-
const { Emitter } = await import('../modules/events.js');
|
|
80
|
+
this.app.container.singleton(Emitter, async () => {
|
|
80
81
|
return new Emitter(this.app);
|
|
81
82
|
});
|
|
83
|
+
this.app.container.alias('emitter', Emitter);
|
|
82
84
|
}
|
|
83
85
|
/**
|
|
84
86
|
* Register the encryption service to the container
|