@adonisjs/assembler 5.7.0 → 5.8.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.
@@ -223,8 +223,8 @@
223
223
  {
224
224
  "name": "environment",
225
225
  "propertyName": "environment",
226
- "type": "string",
227
- "description": "Define the environment in which you want to load this file"
226
+ "type": "array",
227
+ "description": "Define the preload file environment. Accepted values \"console,web,repl,test\""
228
228
  }
229
229
  ]
230
230
  },
@@ -1,4 +1,5 @@
1
1
  import { BaseGenerator } from './Base';
2
+ import type { AppEnvironments } from '@ioc:Adonis/Core/Application';
2
3
  /**
3
4
  * Command to make a new preloaded file
4
5
  */
@@ -8,10 +9,6 @@ export default class MakePreloadFile extends BaseGenerator {
8
9
  */
9
10
  protected resourceName: string;
10
11
  protected createExact: boolean;
11
- /**
12
- * List of allowed environments
13
- */
14
- private allowedEnvironments;
15
12
  /**
16
13
  * Command name
17
14
  */
@@ -21,12 +18,11 @@ export default class MakePreloadFile extends BaseGenerator {
21
18
  */
22
19
  static description: string;
23
20
  name: string;
24
- environment: ('console' | 'web' | 'repl')[];
21
+ environment: AppEnvironments[];
25
22
  /**
26
- * Validates environments to ensure they are allowed. Especially when
27
- * defined as a flag.
23
+ * Check if the mentioned environments are valid
28
24
  */
29
- private validateEnvironments;
25
+ private isValidEnviroment;
30
26
  /**
31
27
  * Returns the template stub path
32
28
  */
@@ -35,7 +31,6 @@ export default class MakePreloadFile extends BaseGenerator {
35
31
  * Path to the start directory
36
32
  */
37
33
  protected getDestinationPath(): string;
38
- prepare(): Promise<void>;
39
34
  /**
40
35
  * Run command
41
36
  */
@@ -47,6 +47,7 @@ const slash_1 = __importDefault(require("slash"));
47
47
  const path_1 = require("path");
48
48
  const standalone_1 = require("@adonisjs/core/build/standalone");
49
49
  const Base_1 = require("./Base");
50
+ const ALLOWED_ENVIRONMENTS = ['console', 'web', 'repl', 'test'];
50
51
  /**
51
52
  * Command to make a new preloaded file
52
53
  */
@@ -54,17 +55,12 @@ class MakePreloadFile extends Base_1.BaseGenerator {
54
55
  constructor() {
55
56
  super(...arguments);
56
57
  this.createExact = true;
57
- /**
58
- * List of allowed environments
59
- */
60
- this.allowedEnvironments = ['console', 'web', 'repl'];
61
58
  }
62
59
  /**
63
- * Validates environments to ensure they are allowed. Especially when
64
- * defined as a flag.
60
+ * Check if the mentioned environments are valid
65
61
  */
66
- validateEnvironments(environments) {
67
- return !environments.find((environment) => !this.allowedEnvironments.includes(environment));
62
+ isValidEnviroment(environment) {
63
+ return !environment.find((one) => !ALLOWED_ENVIRONMENTS.includes(one));
68
64
  }
69
65
  /**
70
66
  * Returns the template stub path
@@ -78,40 +74,45 @@ class MakePreloadFile extends Base_1.BaseGenerator {
78
74
  getDestinationPath() {
79
75
  return this.application.rcFile.directories.start || 'start';
80
76
  }
81
- async prepare() {
82
- this.environment = await this.prompt.multiple('Select the environment(s) in which you want to load this file', [
83
- {
84
- name: 'console',
85
- message: 'During ace commands',
86
- },
87
- {
88
- name: 'repl',
89
- message: 'During repl session',
90
- },
91
- {
92
- name: 'web',
93
- message: 'During HTTP server',
94
- },
95
- ], {
96
- validate(choices) {
97
- return choices && choices.length ? true : 'Use space to select the environment';
98
- },
99
- });
100
- }
101
77
  /**
102
78
  * Run command
103
79
  */
104
80
  async run() {
105
- const environments = typeof this.environment === 'string'
106
- ? this.environment.split(',')
107
- : this.environment;
108
81
  /**
109
- * Show error when defined environments are invalid
82
+ * Ensure the environments are valid when provided via flag
110
83
  */
111
- if (!this.validateEnvironments(environments)) {
112
- this.logger.error(`Invalid environments "${environments}". Only "${this.allowedEnvironments}" are allowed`);
84
+ if (this.environment && this.environment.length && !this.isValidEnviroment(this.environment)) {
85
+ this.logger.error(`Invalid environment(s) "${this.environment}". Only "${ALLOWED_ENVIRONMENTS}" are allowed`);
113
86
  return;
114
87
  }
88
+ let environments = this.environment;
89
+ /**
90
+ * Prompt user to select one or more environments
91
+ */
92
+ if (!environments) {
93
+ environments = await this.prompt.multiple('Select the environment(s) in which you want to load this file', [
94
+ {
95
+ name: 'all',
96
+ message: 'Load file in all environments',
97
+ },
98
+ {
99
+ name: 'console',
100
+ message: 'Environment for ace commands',
101
+ },
102
+ {
103
+ name: 'repl',
104
+ message: 'Environment for the REPL session',
105
+ },
106
+ {
107
+ name: 'web',
108
+ message: 'Environment for HTTP requests',
109
+ },
110
+ {
111
+ name: 'test',
112
+ message: 'Environment for the test process',
113
+ },
114
+ ]);
115
+ }
115
116
  /**
116
117
  * Generate resource file
117
118
  */
@@ -126,11 +127,11 @@ class MakePreloadFile extends Base_1.BaseGenerator {
126
127
  const { files } = await Promise.resolve().then(() => __importStar(require('@adonisjs/sink')));
127
128
  const relativePath = file.toJSON().relativepath;
128
129
  const rcFile = new files.AdonisRcFile(this.application.appRoot);
129
- if (environments && environments.length) {
130
- rcFile.setPreload(`./${(0, slash_1.default)(relativePath).replace((0, path_1.extname)(relativePath), '')}`, environments);
130
+ if (!environments || !environments.length || environments.includes('all')) {
131
+ rcFile.setPreload(`./${(0, slash_1.default)(relativePath).replace((0, path_1.extname)(relativePath), '')}`);
131
132
  }
132
133
  else {
133
- rcFile.setPreload(`./${(0, slash_1.default)(relativePath).replace((0, path_1.extname)(relativePath), '')}`);
134
+ rcFile.setPreload(`./${(0, slash_1.default)(relativePath).replace((0, path_1.extname)(relativePath), '')}`, environments);
134
135
  }
135
136
  rcFile.commit();
136
137
  }
@@ -148,8 +149,8 @@ __decorate([
148
149
  __metadata("design:type", String)
149
150
  ], MakePreloadFile.prototype, "name", void 0);
150
151
  __decorate([
151
- standalone_1.flags.string({
152
- description: 'Define the environment in which you want to load this file',
152
+ standalone_1.flags.array({
153
+ description: `Define the preload file environment. Accepted values "${ALLOWED_ENVIRONMENTS}"`,
153
154
  }),
154
155
  __metadata("design:type", Array)
155
156
  ], MakePreloadFile.prototype, "environment", void 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonisjs/assembler",
3
- "version": "5.7.0",
3
+ "version": "5.8.0",
4
4
  "description": "Core commands to compiler and build AdonisJs project",
5
5
  "main": "build/ace-manifest.json",
6
6
  "files": [
@@ -45,20 +45,20 @@
45
45
  "homepage": "https://github.com/adonisjs/assembler#readme",
46
46
  "devDependencies": {
47
47
  "@adonisjs/ace": "^11.3.1",
48
- "@adonisjs/core": "^5.8.2",
48
+ "@adonisjs/core": "^5.8.3",
49
49
  "@adonisjs/mrm-preset": "^5.0.3",
50
50
  "@japa/assert": "^1.3.4",
51
51
  "@japa/run-failed-tests": "^1.0.7",
52
- "@japa/runner": "^2.0.8",
52
+ "@japa/runner": "^2.0.9",
53
53
  "@japa/spec-reporter": "^1.1.12",
54
54
  "@poppinss/dev-utils": "^2.0.3",
55
- "@types/node": "^17.0.35",
55
+ "@types/node": "^18.0.0",
56
56
  "commitizen": "^4.2.4",
57
57
  "copyfiles": "^2.4.1",
58
58
  "cross-env": "^7.0.3",
59
59
  "cz-conventional-changelog": "^3.3.0",
60
60
  "del-cli": "^4.0.1",
61
- "eslint": "^8.16.0",
61
+ "eslint": "^8.17.0",
62
62
  "eslint-config-prettier": "^8.5.0",
63
63
  "eslint-plugin-adonis": "^2.1.0",
64
64
  "eslint-plugin-prettier": "^4.0.0",
@@ -66,8 +66,8 @@
66
66
  "husky": "^8.0.1",
67
67
  "mrm": "^4.0.0",
68
68
  "np": "^7.6.1",
69
- "prettier": "^2.6.2",
70
- "typescript": "^4.6.3"
69
+ "prettier": "^2.7.0",
70
+ "typescript": "^4.7.3"
71
71
  },
72
72
  "nyc": {
73
73
  "exclude": [
@@ -92,7 +92,7 @@
92
92
  "anyBranch": false
93
93
  },
94
94
  "dependencies": {
95
- "@adonisjs/application": "^5.2.4",
95
+ "@adonisjs/application": "^5.2.5",
96
96
  "@adonisjs/env": "^3.0.9",
97
97
  "@adonisjs/ioc-transformer": "^2.3.4",
98
98
  "@adonisjs/require-ts": "^2.0.12",