@twin.org/cli-core 0.0.1-next.9 → 0.0.2-next.10
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/cjs/index.cjs +45 -9
- package/dist/esm/index.mjs +45 -9
- package/dist/types/cliDisplay.d.ts +5 -0
- package/dist/types/cliParam.d.ts +12 -2
- package/dist/types/cliUtils.d.ts +9 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/models/ICliOptions.d.ts +4 -0
- package/docs/changelog.md +588 -1
- package/docs/reference/classes/CLIBase.md +19 -9
- package/docs/reference/classes/CLIDisplay.md +75 -21
- package/docs/reference/classes/CLIOptions.md +22 -10
- package/docs/reference/classes/CLIParam.md +175 -47
- package/docs/reference/classes/CLIUtils.md +101 -25
- package/docs/reference/functions/addGlobalOptions.md +9 -3
- package/docs/reference/functions/initGlobalOptions.md +3 -1
- package/docs/reference/interfaces/ICliOptions.md +8 -0
- package/docs/reference/type-aliases/CliOutputOptions.md +1 -1
- package/locales/en.json +5 -0
- package/package.json +9 -9
package/dist/cjs/index.cjs
CHANGED
|
@@ -81,7 +81,7 @@ class CLIDisplay {
|
|
|
81
81
|
if (lineBreaks) {
|
|
82
82
|
CLIDisplay.writeError("\n");
|
|
83
83
|
}
|
|
84
|
-
const formatted = core.ErrorHelper.formatErrors(error);
|
|
84
|
+
const formatted = core.ErrorHelper.formatErrors(error, true);
|
|
85
85
|
CLIDisplay.writeError(chalk.red(formatted.map(e => `\t${e}`).join("\n")));
|
|
86
86
|
if (lineBreaks) {
|
|
87
87
|
CLIDisplay.writeError("\n");
|
|
@@ -139,6 +139,15 @@ class CLIDisplay {
|
|
|
139
139
|
CLIDisplay.write(node_util.inspect(obj, false, undefined, true));
|
|
140
140
|
CLIDisplay.write("\n");
|
|
141
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Display a warning.
|
|
144
|
+
* @param label The label for the warning.
|
|
145
|
+
*/
|
|
146
|
+
static warning(label) {
|
|
147
|
+
CLIDisplay.write("⚠️ ");
|
|
148
|
+
CLIDisplay.write(chalk.hex("#FFA500").bold(label));
|
|
149
|
+
CLIDisplay.write("\n\n");
|
|
150
|
+
}
|
|
142
151
|
/**
|
|
143
152
|
* Display the processing is done.
|
|
144
153
|
*/
|
|
@@ -298,6 +307,17 @@ class CLIUtils {
|
|
|
298
307
|
});
|
|
299
308
|
});
|
|
300
309
|
}
|
|
310
|
+
/**
|
|
311
|
+
* Run a shell command.
|
|
312
|
+
* @param command The app to run in the shell.
|
|
313
|
+
* @param args The args for the app.
|
|
314
|
+
* @param cwd The working directory to execute the command in.
|
|
315
|
+
* @returns Promise to wait for command execution to complete.
|
|
316
|
+
*/
|
|
317
|
+
static async runShellCmd(command, args, cwd) {
|
|
318
|
+
const osCommand = process.platform.startsWith("win") ? `${command}.cmd` : command;
|
|
319
|
+
return CLIUtils.runShellApp(osCommand, args, cwd);
|
|
320
|
+
}
|
|
301
321
|
/**
|
|
302
322
|
* Run a shell app.
|
|
303
323
|
* @param app The app to run in the shell.
|
|
@@ -305,10 +325,9 @@ class CLIUtils {
|
|
|
305
325
|
* @param cwd The working directory to execute the command in.
|
|
306
326
|
* @returns Promise to wait for command execution to complete.
|
|
307
327
|
*/
|
|
308
|
-
static async
|
|
328
|
+
static async runShellApp(app, args, cwd) {
|
|
309
329
|
return new Promise((resolve, reject) => {
|
|
310
|
-
const
|
|
311
|
-
const sp = node_child_process.spawn(osCommand, args, {
|
|
330
|
+
const sp = node_child_process.spawn(app, args, {
|
|
312
331
|
shell: true,
|
|
313
332
|
cwd
|
|
314
333
|
});
|
|
@@ -346,7 +365,7 @@ class CLIUtils {
|
|
|
346
365
|
CLIDisplay.task(core.I18n.formatMessage("cli.progress.writingJsonFile"), filename);
|
|
347
366
|
CLIDisplay.break();
|
|
348
367
|
await promises.mkdir(path.dirname(filename), { recursive: true });
|
|
349
|
-
await promises.writeFile(filename, JSON.stringify(core.ObjectHelper.merge(currentJson, data), undefined, "\t"));
|
|
368
|
+
await promises.writeFile(filename, `${JSON.stringify(core.ObjectHelper.merge(currentJson, data), undefined, "\t")}\n`);
|
|
350
369
|
}
|
|
351
370
|
}
|
|
352
371
|
/**
|
|
@@ -377,7 +396,7 @@ class CLIUtils {
|
|
|
377
396
|
for (const line of data) {
|
|
378
397
|
const parts = line.split("=");
|
|
379
398
|
const currentIndex = outputKeys.indexOf(parts[0]);
|
|
380
|
-
if (currentIndex
|
|
399
|
+
if (currentIndex !== -1) {
|
|
381
400
|
outputKeys.splice(currentIndex, 1);
|
|
382
401
|
}
|
|
383
402
|
outputKeys.push(parts[0]);
|
|
@@ -433,7 +452,7 @@ function handleGlobalOptions(command) {
|
|
|
433
452
|
const resolvedEnv = loadEnv.map(e => path.resolve(e));
|
|
434
453
|
CLIDisplay.task(core.I18n.formatMessage("cli.progress.loadingEnvFiles"), resolvedEnv.join(", "));
|
|
435
454
|
CLIDisplay.break();
|
|
436
|
-
dotenv__namespace.config({ path: resolvedEnv });
|
|
455
|
+
dotenv__namespace.config({ path: resolvedEnv, quiet: true });
|
|
437
456
|
}
|
|
438
457
|
}
|
|
439
458
|
/**
|
|
@@ -500,6 +519,9 @@ class CLIBase {
|
|
|
500
519
|
// eslint-disable-next-line no-restricted-syntax
|
|
501
520
|
throw new Error(err.code === "commander.help" ? "0" : err.exitCode.toString());
|
|
502
521
|
});
|
|
522
|
+
if (options.showDevToolWarning ?? false) {
|
|
523
|
+
program.hook("preAction", () => CLIDisplay.warning(core.I18n.formatMessage("warn.common.devOnlyTool")));
|
|
524
|
+
}
|
|
503
525
|
this.configureRoot(program);
|
|
504
526
|
addGlobalOptions(program, options.supportsLang ?? true, options.supportsEnvFiles ?? false);
|
|
505
527
|
// We parse the options before building the command
|
|
@@ -627,7 +649,7 @@ class CLIParam {
|
|
|
627
649
|
return optionValue;
|
|
628
650
|
}
|
|
629
651
|
/**
|
|
630
|
-
* Check the option to see if
|
|
652
|
+
* Check the option to see if the String exists.
|
|
631
653
|
* @param optionName The name of the option.
|
|
632
654
|
* @param optionValue The option value.
|
|
633
655
|
* @param allowEnvVar Allow the option to be read from an env var.
|
|
@@ -640,7 +662,21 @@ class CLIParam {
|
|
|
640
662
|
return optionValue;
|
|
641
663
|
}
|
|
642
664
|
/**
|
|
643
|
-
* Check the option to see if
|
|
665
|
+
* Check the option to see if the value exists in the specific array.
|
|
666
|
+
* @param optionName The name of the option.
|
|
667
|
+
* @param optionValue The option value.
|
|
668
|
+
* @param validValues The valid values.
|
|
669
|
+
* @param allowEnvVar Allow the option to be read from an env var.
|
|
670
|
+
* @returns The final option value.
|
|
671
|
+
* @throws An error if the option is invalid.
|
|
672
|
+
*/
|
|
673
|
+
static arrayOneOf(optionName, optionValue, validValues, allowEnvVar = true) {
|
|
674
|
+
optionValue = CLIParam.env(optionName, optionValue, allowEnvVar);
|
|
675
|
+
core.Guards.arrayOneOf("commands", optionName, optionValue, validValues);
|
|
676
|
+
return optionValue;
|
|
677
|
+
}
|
|
678
|
+
/**
|
|
679
|
+
* Check the option to see if it is a url.
|
|
644
680
|
* @param optionName The name of the option.
|
|
645
681
|
* @param optionValue The option value.
|
|
646
682
|
* @param allowEnvVar Allow the option to be read from an env var.
|
package/dist/esm/index.mjs
CHANGED
|
@@ -60,7 +60,7 @@ class CLIDisplay {
|
|
|
60
60
|
if (lineBreaks) {
|
|
61
61
|
CLIDisplay.writeError("\n");
|
|
62
62
|
}
|
|
63
|
-
const formatted = ErrorHelper.formatErrors(error);
|
|
63
|
+
const formatted = ErrorHelper.formatErrors(error, true);
|
|
64
64
|
CLIDisplay.writeError(chalk.red(formatted.map(e => `\t${e}`).join("\n")));
|
|
65
65
|
if (lineBreaks) {
|
|
66
66
|
CLIDisplay.writeError("\n");
|
|
@@ -118,6 +118,15 @@ class CLIDisplay {
|
|
|
118
118
|
CLIDisplay.write(inspect(obj, false, undefined, true));
|
|
119
119
|
CLIDisplay.write("\n");
|
|
120
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Display a warning.
|
|
123
|
+
* @param label The label for the warning.
|
|
124
|
+
*/
|
|
125
|
+
static warning(label) {
|
|
126
|
+
CLIDisplay.write("⚠️ ");
|
|
127
|
+
CLIDisplay.write(chalk.hex("#FFA500").bold(label));
|
|
128
|
+
CLIDisplay.write("\n\n");
|
|
129
|
+
}
|
|
121
130
|
/**
|
|
122
131
|
* Display the processing is done.
|
|
123
132
|
*/
|
|
@@ -277,6 +286,17 @@ class CLIUtils {
|
|
|
277
286
|
});
|
|
278
287
|
});
|
|
279
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* Run a shell command.
|
|
291
|
+
* @param command The app to run in the shell.
|
|
292
|
+
* @param args The args for the app.
|
|
293
|
+
* @param cwd The working directory to execute the command in.
|
|
294
|
+
* @returns Promise to wait for command execution to complete.
|
|
295
|
+
*/
|
|
296
|
+
static async runShellCmd(command, args, cwd) {
|
|
297
|
+
const osCommand = process.platform.startsWith("win") ? `${command}.cmd` : command;
|
|
298
|
+
return CLIUtils.runShellApp(osCommand, args, cwd);
|
|
299
|
+
}
|
|
280
300
|
/**
|
|
281
301
|
* Run a shell app.
|
|
282
302
|
* @param app The app to run in the shell.
|
|
@@ -284,10 +304,9 @@ class CLIUtils {
|
|
|
284
304
|
* @param cwd The working directory to execute the command in.
|
|
285
305
|
* @returns Promise to wait for command execution to complete.
|
|
286
306
|
*/
|
|
287
|
-
static async
|
|
307
|
+
static async runShellApp(app, args, cwd) {
|
|
288
308
|
return new Promise((resolve, reject) => {
|
|
289
|
-
const
|
|
290
|
-
const sp = spawn(osCommand, args, {
|
|
309
|
+
const sp = spawn(app, args, {
|
|
291
310
|
shell: true,
|
|
292
311
|
cwd
|
|
293
312
|
});
|
|
@@ -325,7 +344,7 @@ class CLIUtils {
|
|
|
325
344
|
CLIDisplay.task(I18n.formatMessage("cli.progress.writingJsonFile"), filename);
|
|
326
345
|
CLIDisplay.break();
|
|
327
346
|
await mkdir(path.dirname(filename), { recursive: true });
|
|
328
|
-
await writeFile(filename, JSON.stringify(ObjectHelper.merge(currentJson, data), undefined, "\t"));
|
|
347
|
+
await writeFile(filename, `${JSON.stringify(ObjectHelper.merge(currentJson, data), undefined, "\t")}\n`);
|
|
329
348
|
}
|
|
330
349
|
}
|
|
331
350
|
/**
|
|
@@ -356,7 +375,7 @@ class CLIUtils {
|
|
|
356
375
|
for (const line of data) {
|
|
357
376
|
const parts = line.split("=");
|
|
358
377
|
const currentIndex = outputKeys.indexOf(parts[0]);
|
|
359
|
-
if (currentIndex
|
|
378
|
+
if (currentIndex !== -1) {
|
|
360
379
|
outputKeys.splice(currentIndex, 1);
|
|
361
380
|
}
|
|
362
381
|
outputKeys.push(parts[0]);
|
|
@@ -412,7 +431,7 @@ function handleGlobalOptions(command) {
|
|
|
412
431
|
const resolvedEnv = loadEnv.map(e => path.resolve(e));
|
|
413
432
|
CLIDisplay.task(I18n.formatMessage("cli.progress.loadingEnvFiles"), resolvedEnv.join(", "));
|
|
414
433
|
CLIDisplay.break();
|
|
415
|
-
dotenv.config({ path: resolvedEnv });
|
|
434
|
+
dotenv.config({ path: resolvedEnv, quiet: true });
|
|
416
435
|
}
|
|
417
436
|
}
|
|
418
437
|
/**
|
|
@@ -479,6 +498,9 @@ class CLIBase {
|
|
|
479
498
|
// eslint-disable-next-line no-restricted-syntax
|
|
480
499
|
throw new Error(err.code === "commander.help" ? "0" : err.exitCode.toString());
|
|
481
500
|
});
|
|
501
|
+
if (options.showDevToolWarning ?? false) {
|
|
502
|
+
program.hook("preAction", () => CLIDisplay.warning(I18n.formatMessage("warn.common.devOnlyTool")));
|
|
503
|
+
}
|
|
482
504
|
this.configureRoot(program);
|
|
483
505
|
addGlobalOptions(program, options.supportsLang ?? true, options.supportsEnvFiles ?? false);
|
|
484
506
|
// We parse the options before building the command
|
|
@@ -606,7 +628,7 @@ class CLIParam {
|
|
|
606
628
|
return optionValue;
|
|
607
629
|
}
|
|
608
630
|
/**
|
|
609
|
-
* Check the option to see if
|
|
631
|
+
* Check the option to see if the String exists.
|
|
610
632
|
* @param optionName The name of the option.
|
|
611
633
|
* @param optionValue The option value.
|
|
612
634
|
* @param allowEnvVar Allow the option to be read from an env var.
|
|
@@ -619,7 +641,21 @@ class CLIParam {
|
|
|
619
641
|
return optionValue;
|
|
620
642
|
}
|
|
621
643
|
/**
|
|
622
|
-
* Check the option to see if
|
|
644
|
+
* Check the option to see if the value exists in the specific array.
|
|
645
|
+
* @param optionName The name of the option.
|
|
646
|
+
* @param optionValue The option value.
|
|
647
|
+
* @param validValues The valid values.
|
|
648
|
+
* @param allowEnvVar Allow the option to be read from an env var.
|
|
649
|
+
* @returns The final option value.
|
|
650
|
+
* @throws An error if the option is invalid.
|
|
651
|
+
*/
|
|
652
|
+
static arrayOneOf(optionName, optionValue, validValues, allowEnvVar = true) {
|
|
653
|
+
optionValue = CLIParam.env(optionName, optionValue, allowEnvVar);
|
|
654
|
+
Guards.arrayOneOf("commands", optionName, optionValue, validValues);
|
|
655
|
+
return optionValue;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Check the option to see if it is a url.
|
|
623
659
|
* @param optionName The name of the option.
|
|
624
660
|
* @param optionValue The option value.
|
|
625
661
|
* @param allowEnvVar Allow the option to be read from an env var.
|
|
@@ -56,6 +56,11 @@ export declare class CLIDisplay {
|
|
|
56
56
|
* @param obj The object to display.
|
|
57
57
|
*/
|
|
58
58
|
static json(obj: unknown): void;
|
|
59
|
+
/**
|
|
60
|
+
* Display a warning.
|
|
61
|
+
* @param label The label for the warning.
|
|
62
|
+
*/
|
|
63
|
+
static warning(label: string): void;
|
|
59
64
|
/**
|
|
60
65
|
* Display the processing is done.
|
|
61
66
|
*/
|
package/dist/types/cliParam.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare class CLIParam {
|
|
|
12
12
|
*/
|
|
13
13
|
static env(optionName: string, optionValue: string | undefined, allowEnvVar: boolean): string | undefined;
|
|
14
14
|
/**
|
|
15
|
-
* Check the option to see if
|
|
15
|
+
* Check the option to see if the String exists.
|
|
16
16
|
* @param optionName The name of the option.
|
|
17
17
|
* @param optionValue The option value.
|
|
18
18
|
* @param allowEnvVar Allow the option to be read from an env var.
|
|
@@ -21,7 +21,17 @@ export declare class CLIParam {
|
|
|
21
21
|
*/
|
|
22
22
|
static stringValue(optionName: string, optionValue: string | undefined, allowEnvVar?: boolean): string;
|
|
23
23
|
/**
|
|
24
|
-
* Check the option to see if
|
|
24
|
+
* Check the option to see if the value exists in the specific array.
|
|
25
|
+
* @param optionName The name of the option.
|
|
26
|
+
* @param optionValue The option value.
|
|
27
|
+
* @param validValues The valid values.
|
|
28
|
+
* @param allowEnvVar Allow the option to be read from an env var.
|
|
29
|
+
* @returns The final option value.
|
|
30
|
+
* @throws An error if the option is invalid.
|
|
31
|
+
*/
|
|
32
|
+
static arrayOneOf<T = string>(optionName: string, optionValue: string | undefined, validValues: T[], allowEnvVar?: boolean): T;
|
|
33
|
+
/**
|
|
34
|
+
* Check the option to see if it is a url.
|
|
25
35
|
* @param optionName The name of the option.
|
|
26
36
|
* @param optionValue The option value.
|
|
27
37
|
* @param allowEnvVar Allow the option to be read from an env var.
|
package/dist/types/cliUtils.d.ts
CHANGED
|
@@ -56,6 +56,14 @@ export declare class CLIUtils {
|
|
|
56
56
|
* @returns The root path.
|
|
57
57
|
*/
|
|
58
58
|
static findNpmRoot(rootFolder: string): Promise<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Run a shell command.
|
|
61
|
+
* @param command The app to run in the shell.
|
|
62
|
+
* @param args The args for the app.
|
|
63
|
+
* @param cwd The working directory to execute the command in.
|
|
64
|
+
* @returns Promise to wait for command execution to complete.
|
|
65
|
+
*/
|
|
66
|
+
static runShellCmd(command: string, args: string[], cwd: string): Promise<void>;
|
|
59
67
|
/**
|
|
60
68
|
* Run a shell app.
|
|
61
69
|
* @param app The app to run in the shell.
|
|
@@ -63,7 +71,7 @@ export declare class CLIUtils {
|
|
|
63
71
|
* @param cwd The working directory to execute the command in.
|
|
64
72
|
* @returns Promise to wait for command execution to complete.
|
|
65
73
|
*/
|
|
66
|
-
static
|
|
74
|
+
static runShellApp(app: string, args: string[], cwd: string): Promise<void>;
|
|
67
75
|
/**
|
|
68
76
|
* Write a JSON file.
|
|
69
77
|
* @param jsonFilename The filename to write.
|
package/dist/types/index.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ export * from "./cliOptions";
|
|
|
4
4
|
export * from "./cliParam";
|
|
5
5
|
export * from "./cliUtils";
|
|
6
6
|
export * from "./commands/global";
|
|
7
|
+
export * from "./models/cliOutputOptions";
|
|
7
8
|
export * from "./models/ICliOptions";
|
|
8
9
|
export * from "./models/ICliOutputOptionsConsole";
|
|
9
10
|
export * from "./models/ICliOutputOptionsEnv";
|
|
10
11
|
export * from "./models/ICliOutputOptionsJson";
|
|
11
|
-
export * from "./models/cliOutputOptions";
|