@m2c2kit/cli 0.3.14 → 0.3.15
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/dist/index.d.ts +2 -15
- package/dist/index.js +75 -81
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* The code in this file is adapted from a reference CLI implementation from
|
|
4
4
|
* the Angular devkit repository:
|
|
5
|
-
* https://github.com/angular/angular-cli/blob/
|
|
5
|
+
* https://github.com/angular/angular-cli/blob/1f9278fa8cb8cdaf7775962165c042b9f382a89b/packages/angular_devkit/schematics_cli/bin/schematics.ts
|
|
6
6
|
* The license for that code is as follows:
|
|
7
7
|
* @license
|
|
8
8
|
* Copyright Google LLC All Rights Reserved.
|
|
9
9
|
*
|
|
10
10
|
* Use of this source code is governed by an MIT-style license that can be
|
|
11
|
-
* found in the LICENSE file at https://angular.
|
|
11
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
12
12
|
*/
|
|
13
13
|
import "symbol-observable";
|
|
14
14
|
import { ProcessOutput } from "@angular-devkit/core/node";
|
|
@@ -18,16 +18,3 @@ export interface MainOptions {
|
|
|
18
18
|
stderr?: ProcessOutput;
|
|
19
19
|
}
|
|
20
20
|
export declare function main({ args, stdout, stderr, }: MainOptions): Promise<0 | 1>;
|
|
21
|
-
/**
|
|
22
|
-
* This uses a dynamic import to load a module which may be ESM.
|
|
23
|
-
* CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript
|
|
24
|
-
* will currently, unconditionally downlevel dynamic import into a require call.
|
|
25
|
-
* require calls cannot load ESM code and will result in a runtime error. To workaround
|
|
26
|
-
* this, a Function constructor is used to prevent TypeScript from changing the dynamic import.
|
|
27
|
-
* Once TypeScript provides support for keeping the dynamic import this workaround can
|
|
28
|
-
* be dropped.
|
|
29
|
-
*
|
|
30
|
-
* @param modulePath The path of the module to load.
|
|
31
|
-
* @returns A Promise that resolves to the dynamically imported module.
|
|
32
|
-
*/
|
|
33
|
-
export declare function loadEsmModule<T>(modulePath: string | URL): Promise<T>;
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
/* eslint-disable no-case-declarations */
|
|
3
4
|
/**
|
|
4
5
|
* The code in this file is adapted from a reference CLI implementation from
|
|
5
6
|
* the Angular devkit repository:
|
|
6
|
-
* https://github.com/angular/angular-cli/blob/
|
|
7
|
+
* https://github.com/angular/angular-cli/blob/1f9278fa8cb8cdaf7775962165c042b9f382a89b/packages/angular_devkit/schematics_cli/bin/schematics.ts
|
|
7
8
|
* The license for that code is as follows:
|
|
8
9
|
* @license
|
|
9
10
|
* Copyright Google LLC All Rights Reserved.
|
|
10
11
|
*
|
|
11
12
|
* Use of this source code is governed by an MIT-style license that can be
|
|
12
|
-
* found in the LICENSE file at https://angular.
|
|
13
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
13
14
|
*/
|
|
14
15
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
16
|
if (k2 === undefined) k2 = k;
|
|
@@ -38,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
39
40
|
};
|
|
40
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
exports.
|
|
42
|
+
exports.main = void 0;
|
|
42
43
|
// symbol polyfill must go first
|
|
43
44
|
require("symbol-observable");
|
|
44
45
|
const node_1 = require("@angular-devkit/core/node");
|
|
@@ -88,66 +89,82 @@ function _listSchematics(workflow, collectionName, logger) {
|
|
|
88
89
|
}
|
|
89
90
|
function _createPromptProvider() {
|
|
90
91
|
return async (definitions) => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
};
|
|
97
|
-
const validator = definition.validator;
|
|
98
|
-
if (validator) {
|
|
99
|
-
question.validate = (input) => validator(input);
|
|
100
|
-
// Filter allows transformation of the value prior to validation
|
|
101
|
-
question.filter = async (input) => {
|
|
102
|
-
for (const type of definition.propertyTypes) {
|
|
103
|
-
let value;
|
|
104
|
-
switch (type) {
|
|
105
|
-
case "string":
|
|
106
|
-
value = String(input);
|
|
107
|
-
break;
|
|
108
|
-
case "integer":
|
|
109
|
-
case "number":
|
|
110
|
-
value = Number(input);
|
|
111
|
-
break;
|
|
112
|
-
default:
|
|
113
|
-
value = input;
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
// Can be a string if validation fails
|
|
117
|
-
const isValid = (await validator(value)) === true;
|
|
118
|
-
if (isValid) {
|
|
119
|
-
return value;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return input;
|
|
123
|
-
};
|
|
124
|
-
}
|
|
92
|
+
let prompts;
|
|
93
|
+
const answers = {};
|
|
94
|
+
for (const definition of definitions) {
|
|
95
|
+
// Only load prompt package if needed
|
|
96
|
+
prompts ?? (prompts = await Promise.resolve().then(() => __importStar(require("@inquirer/prompts"))));
|
|
125
97
|
switch (definition.type) {
|
|
126
98
|
case "confirmation":
|
|
127
|
-
|
|
99
|
+
answers[definition.id] = await prompts.confirm({
|
|
100
|
+
message: definition.message,
|
|
101
|
+
default: definition.default,
|
|
102
|
+
});
|
|
103
|
+
break;
|
|
128
104
|
case "list":
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
105
|
+
if (!definition.items?.length) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
const choices = definition.items?.map((item) => {
|
|
109
|
+
return typeof item == "string"
|
|
110
|
+
? {
|
|
111
|
+
name: item,
|
|
112
|
+
value: item,
|
|
113
|
+
}
|
|
114
|
+
: {
|
|
115
|
+
name: item.label,
|
|
116
|
+
value: item.value,
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
answers[definition.id] = await (definition.multiselect ? prompts.checkbox : prompts.select)({
|
|
120
|
+
message: definition.message,
|
|
121
|
+
default: definition.default,
|
|
122
|
+
choices,
|
|
123
|
+
});
|
|
124
|
+
break;
|
|
125
|
+
case "input":
|
|
126
|
+
let finalValue;
|
|
127
|
+
answers[definition.id] = await prompts.input({
|
|
128
|
+
message: definition.message,
|
|
129
|
+
default: definition.default,
|
|
130
|
+
async validate(value) {
|
|
131
|
+
if (definition.validator === undefined) {
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
let lastValidation = false;
|
|
135
|
+
for (const type of definition.propertyTypes) {
|
|
136
|
+
let potential;
|
|
137
|
+
switch (type) {
|
|
138
|
+
case "string":
|
|
139
|
+
potential = String(value);
|
|
140
|
+
break;
|
|
141
|
+
case "integer":
|
|
142
|
+
case "number":
|
|
143
|
+
potential = Number(value);
|
|
144
|
+
break;
|
|
145
|
+
default:
|
|
146
|
+
potential = value;
|
|
147
|
+
break;
|
|
136
148
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
149
|
+
lastValidation = await definition.validator(potential);
|
|
150
|
+
// Can be a string if validation fails
|
|
151
|
+
if (lastValidation === true) {
|
|
152
|
+
finalValue = potential;
|
|
153
|
+
return true;
|
|
142
154
|
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
155
|
+
}
|
|
156
|
+
return lastValidation;
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
// Use validated value if present.
|
|
160
|
+
// This ensures the correct type is inserted into the final schema options.
|
|
161
|
+
if (finalValue !== undefined) {
|
|
162
|
+
answers[definition.id] = finalValue;
|
|
163
|
+
}
|
|
164
|
+
break;
|
|
147
165
|
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return inquirer.prompt(questions);
|
|
166
|
+
}
|
|
167
|
+
return answers;
|
|
151
168
|
};
|
|
152
169
|
}
|
|
153
170
|
function findUp(names, from) {
|
|
@@ -255,7 +272,6 @@ async function main({ args, stdout = process.stdout, stderr = process.stderr, })
|
|
|
255
272
|
switch (event.kind) {
|
|
256
273
|
case "error":
|
|
257
274
|
error = true;
|
|
258
|
-
// eslint-disable-next-line no-case-declarations
|
|
259
275
|
const desc = event.description == "alreadyExist"
|
|
260
276
|
? "already exists"
|
|
261
277
|
: "does not exist";
|
|
@@ -271,7 +287,6 @@ async function main({ args, stdout = process.stdout, stderr = process.stderr, })
|
|
|
271
287
|
loggingQueue.push(`${colors.yellow("DELETE")} ${eventPath}`);
|
|
272
288
|
break;
|
|
273
289
|
case "rename":
|
|
274
|
-
// eslint-disable-next-line no-case-declarations
|
|
275
290
|
const eventToPath = event.to.startsWith("/")
|
|
276
291
|
? event.to.slice(1)
|
|
277
292
|
: event.to;
|
|
@@ -333,7 +348,7 @@ async function main({ args, stdout = process.stdout, stderr = process.stderr, })
|
|
|
333
348
|
logger.fatal("The Schematic workflow failed. See above.");
|
|
334
349
|
}
|
|
335
350
|
else if (debug && err instanceof Error) {
|
|
336
|
-
logger.fatal(`An error
|
|
351
|
+
logger.fatal(`An error occured:\n${err.stack}`);
|
|
337
352
|
}
|
|
338
353
|
else {
|
|
339
354
|
logger.fatal(`Error: ${err instanceof Error ? err.message : err}`);
|
|
@@ -431,24 +446,3 @@ if (require.main === module) {
|
|
|
431
446
|
throw e;
|
|
432
447
|
});
|
|
433
448
|
}
|
|
434
|
-
/**
|
|
435
|
-
* Lazily compiled dynamic import loader function.
|
|
436
|
-
*/
|
|
437
|
-
let load;
|
|
438
|
-
/**
|
|
439
|
-
* This uses a dynamic import to load a module which may be ESM.
|
|
440
|
-
* CommonJS code can load ESM code via a dynamic import. Unfortunately, TypeScript
|
|
441
|
-
* will currently, unconditionally downlevel dynamic import into a require call.
|
|
442
|
-
* require calls cannot load ESM code and will result in a runtime error. To workaround
|
|
443
|
-
* this, a Function constructor is used to prevent TypeScript from changing the dynamic import.
|
|
444
|
-
* Once TypeScript provides support for keeping the dynamic import this workaround can
|
|
445
|
-
* be dropped.
|
|
446
|
-
*
|
|
447
|
-
* @param modulePath The path of the module to load.
|
|
448
|
-
* @returns A Promise that resolves to the dynamically imported module.
|
|
449
|
-
*/
|
|
450
|
-
function loadEsmModule(modulePath) {
|
|
451
|
-
load ?? (load = new Function("modulePath", `return import(modulePath);`));
|
|
452
|
-
return load(modulePath);
|
|
453
|
-
}
|
|
454
|
-
exports.loadEsmModule = loadEsmModule;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@m2c2kit/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.15",
|
|
4
4
|
"description": "Command line interface to create new m2c2kit apps",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/**"
|
|
@@ -25,19 +25,19 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://m2c2-project.github.io/m2c2kit",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@angular-devkit/core": "^
|
|
29
|
-
"@angular-devkit/schematics": "^
|
|
28
|
+
"@angular-devkit/core": "^18.0.4",
|
|
29
|
+
"@angular-devkit/schematics": "^18.0.4",
|
|
30
|
+
"@inquirer/prompts": "5.0.0",
|
|
30
31
|
"@m2c2kit/schematics": "^0.1.13",
|
|
31
|
-
"@schematics/angular": "^
|
|
32
|
+
"@schematics/angular": "^18.0.4",
|
|
32
33
|
"ansi-colors": "4.1.3",
|
|
33
|
-
"inquirer": "9.2.14",
|
|
34
34
|
"symbol-observable": "4.0.0",
|
|
35
35
|
"yargs-parser": "21.1.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/inquirer": "9.0.7",
|
|
39
|
-
"rimraf": "5.0.
|
|
40
|
-
"typescript": "5.4.
|
|
39
|
+
"rimraf": "5.0.7",
|
|
40
|
+
"typescript": "5.4.5"
|
|
41
41
|
},
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=18"
|