@m2c2kit/cli 0.3.14 → 0.3.16
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 +78 -93
- package/package.json +8 -8
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/f5c250ab48e22c5aff31d8ebd35fb9a88e380fd7/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
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* The code in this file is adapted from a reference CLI implementation from
|
|
5
5
|
* the Angular devkit repository:
|
|
6
|
-
* https://github.com/angular/angular-cli/blob/
|
|
6
|
+
* https://github.com/angular/angular-cli/blob/f5c250ab48e22c5aff31d8ebd35fb9a88e380fd7/packages/angular_devkit/schematics_cli/bin/schematics.ts
|
|
7
7
|
* The license for that code is as follows:
|
|
8
8
|
* @license
|
|
9
9
|
* Copyright Google LLC All Rights Reserved.
|
|
10
10
|
*
|
|
11
11
|
* Use of this source code is governed by an MIT-style license that can be
|
|
12
|
-
* found in the LICENSE file at https://angular.
|
|
12
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
13
13
|
*/
|
|
14
14
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
15
|
if (k2 === undefined) k2 = k;
|
|
@@ -38,7 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
39
39
|
};
|
|
40
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
exports.
|
|
41
|
+
exports.main = main;
|
|
42
42
|
// symbol polyfill must go first
|
|
43
43
|
require("symbol-observable");
|
|
44
44
|
const node_1 = require("@angular-devkit/core/node");
|
|
@@ -75,6 +75,9 @@ function parseSchematicName(str) {
|
|
|
75
75
|
}
|
|
76
76
|
return { collection, schematic };
|
|
77
77
|
}
|
|
78
|
+
function removeLeadingSlash(value) {
|
|
79
|
+
return value[0] === "/" ? value.slice(1) : value;
|
|
80
|
+
}
|
|
78
81
|
function _listSchematics(workflow, collectionName, logger) {
|
|
79
82
|
try {
|
|
80
83
|
const collection = workflow.engine.createCollection(collectionName);
|
|
@@ -88,66 +91,80 @@ function _listSchematics(workflow, collectionName, logger) {
|
|
|
88
91
|
}
|
|
89
92
|
function _createPromptProvider() {
|
|
90
93
|
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
|
-
}
|
|
94
|
+
let prompts;
|
|
95
|
+
const answers = {};
|
|
96
|
+
for (const definition of definitions) {
|
|
97
|
+
// Only load prompt package if needed
|
|
98
|
+
prompts ?? (prompts = await Promise.resolve().then(() => __importStar(require("@inquirer/prompts"))));
|
|
125
99
|
switch (definition.type) {
|
|
126
100
|
case "confirmation":
|
|
127
|
-
|
|
101
|
+
answers[definition.id] = await prompts.confirm({
|
|
102
|
+
message: definition.message,
|
|
103
|
+
default: definition.default,
|
|
104
|
+
});
|
|
105
|
+
break;
|
|
128
106
|
case "list":
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
107
|
+
if (!definition.items?.length) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
answers[definition.id] = await (definition.multiselect ? prompts.checkbox : prompts.select)({
|
|
111
|
+
message: definition.message,
|
|
112
|
+
default: definition.default,
|
|
113
|
+
choices: definition.items.map((item) => typeof item == "string"
|
|
114
|
+
? {
|
|
115
|
+
name: item,
|
|
116
|
+
value: item,
|
|
117
|
+
}
|
|
118
|
+
: {
|
|
119
|
+
name: item.label,
|
|
120
|
+
value: item.value,
|
|
121
|
+
}),
|
|
122
|
+
});
|
|
123
|
+
break;
|
|
124
|
+
case "input": {
|
|
125
|
+
let finalValue;
|
|
126
|
+
answers[definition.id] = await prompts.input({
|
|
127
|
+
message: definition.message,
|
|
128
|
+
default: definition.default,
|
|
129
|
+
async validate(value) {
|
|
130
|
+
if (definition.validator === undefined) {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
let lastValidation = false;
|
|
134
|
+
for (const type of definition.propertyTypes) {
|
|
135
|
+
let potential;
|
|
136
|
+
switch (type) {
|
|
137
|
+
case "string":
|
|
138
|
+
potential = String(value);
|
|
139
|
+
break;
|
|
140
|
+
case "integer":
|
|
141
|
+
case "number":
|
|
142
|
+
potential = Number(value);
|
|
143
|
+
break;
|
|
144
|
+
default:
|
|
145
|
+
potential = value;
|
|
146
|
+
break;
|
|
136
147
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
148
|
+
lastValidation = await definition.validator(potential);
|
|
149
|
+
// Can be a string if validation fails
|
|
150
|
+
if (lastValidation === true) {
|
|
151
|
+
finalValue = potential;
|
|
152
|
+
return true;
|
|
142
153
|
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
154
|
+
}
|
|
155
|
+
return lastValidation;
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
// Use validated value if present.
|
|
159
|
+
// This ensures the correct type is inserted into the final schema options.
|
|
160
|
+
if (finalValue !== undefined) {
|
|
161
|
+
answers[definition.id] = finalValue;
|
|
162
|
+
}
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
147
165
|
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return inquirer.prompt(questions);
|
|
166
|
+
}
|
|
167
|
+
return answers;
|
|
151
168
|
};
|
|
152
169
|
}
|
|
153
170
|
function findUp(names, from) {
|
|
@@ -249,17 +266,11 @@ async function main({ args, stdout = process.stdout, stderr = process.stderr, })
|
|
|
249
266
|
workflow.reporter.subscribe((event) => {
|
|
250
267
|
nothingDone = false;
|
|
251
268
|
// Strip leading slash to prevent confusion.
|
|
252
|
-
const eventPath = event.path
|
|
253
|
-
? event.path.slice(1)
|
|
254
|
-
: event.path;
|
|
269
|
+
const eventPath = removeLeadingSlash(event.path);
|
|
255
270
|
switch (event.kind) {
|
|
256
271
|
case "error":
|
|
257
272
|
error = true;
|
|
258
|
-
|
|
259
|
-
const desc = event.description == "alreadyExist"
|
|
260
|
-
? "already exists"
|
|
261
|
-
: "does not exist";
|
|
262
|
-
logger.error(`ERROR! ${eventPath} ${desc}.`);
|
|
273
|
+
logger.error(`ERROR! ${eventPath} ${event.description == "alreadyExist" ? "already exists" : "does not exist"}.`);
|
|
263
274
|
break;
|
|
264
275
|
case "update":
|
|
265
276
|
loggingQueue.push(`${colors.cyan("UPDATE")} ${eventPath} (${event.content.length} bytes)`);
|
|
@@ -271,11 +282,7 @@ async function main({ args, stdout = process.stdout, stderr = process.stderr, })
|
|
|
271
282
|
loggingQueue.push(`${colors.yellow("DELETE")} ${eventPath}`);
|
|
272
283
|
break;
|
|
273
284
|
case "rename":
|
|
274
|
-
|
|
275
|
-
const eventToPath = event.to.startsWith("/")
|
|
276
|
-
? event.to.slice(1)
|
|
277
|
-
: event.to;
|
|
278
|
-
loggingQueue.push(`${colors.blue("RENAME")} ${eventPath} => ${eventToPath}`);
|
|
285
|
+
loggingQueue.push(`${colors.blue("RENAME")} ${eventPath} => ${removeLeadingSlash(event.to)}`);
|
|
279
286
|
break;
|
|
280
287
|
}
|
|
281
288
|
});
|
|
@@ -333,7 +340,7 @@ async function main({ args, stdout = process.stdout, stderr = process.stderr, })
|
|
|
333
340
|
logger.fatal("The Schematic workflow failed. See above.");
|
|
334
341
|
}
|
|
335
342
|
else if (debug && err instanceof Error) {
|
|
336
|
-
logger.fatal(`An error
|
|
343
|
+
logger.fatal(`An error occured:\n${err.stack}`);
|
|
337
344
|
}
|
|
338
345
|
else {
|
|
339
346
|
logger.fatal(`Error: ${err instanceof Error ? err.message : err}`);
|
|
@@ -341,7 +348,6 @@ async function main({ args, stdout = process.stdout, stderr = process.stderr, })
|
|
|
341
348
|
return 1;
|
|
342
349
|
}
|
|
343
350
|
}
|
|
344
|
-
exports.main = main;
|
|
345
351
|
/**
|
|
346
352
|
* Get usage of the CLI tool.
|
|
347
353
|
*/
|
|
@@ -431,24 +437,3 @@ if (require.main === module) {
|
|
|
431
437
|
throw e;
|
|
432
438
|
});
|
|
433
439
|
}
|
|
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.16",
|
|
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": "^
|
|
30
|
-
"@
|
|
31
|
-
"@schematics
|
|
28
|
+
"@angular-devkit/core": "^18.1.0",
|
|
29
|
+
"@angular-devkit/schematics": "^18.1.0",
|
|
30
|
+
"@inquirer/prompts": "5.1.3",
|
|
31
|
+
"@m2c2kit/schematics": "0.1.16",
|
|
32
|
+
"@schematics/angular": "^18.1.0",
|
|
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": "
|
|
40
|
-
"typescript": "5.
|
|
39
|
+
"rimraf": "6.0.1",
|
|
40
|
+
"typescript": "5.5.3"
|
|
41
41
|
},
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=18"
|