9
9
10
10
import { Architect , BuilderInfo , BuilderProgressState , Target } from '@angular-devkit/architect' ;
11
11
import { WorkspaceNodeModulesArchitectHost } from '@angular-devkit/architect/node' ;
12
- import { logging , schema , tags , workspaces } from '@angular-devkit/core' ;
12
+ import { json , logging , schema , tags , workspaces } from '@angular-devkit/core' ;
13
13
import { NodeJsSyncHost , createConsoleLogger } from '@angular-devkit/core/node' ;
14
14
import * as ansiColors from 'ansi-colors' ;
15
15
import { existsSync } from 'fs' ;
16
- import minimist from 'minimist' ;
17
16
import * as path from 'path' ;
18
17
import { tap } from 'rxjs/operators' ;
18
+ import yargsParser from 'yargs-parser' ;
19
19
import { MultiProgressBar } from '../src/progress' ;
20
20
21
21
function findUp ( names : string | string [ ] , from : string ) {
@@ -78,24 +78,43 @@ async function _executeTarget(
78
78
parentLogger: logging.Logger,
79
79
workspace: workspaces.WorkspaceDefinition,
80
80
root: string,
81
- argv: minimist.ParsedArgs ,
81
+ argv: yargsParser.Arguments ,
82
82
registry: schema.SchemaRegistry,
83
83
) {
84
84
const architectHost = new WorkspaceNodeModulesArchitectHost(workspace, root);
85
85
const architect = new Architect(architectHost, registry);
86
86
87
87
// Split a target into its parts.
88
- const targetStr = argv._.shift() || '';
88
+ const {
89
+ _: [targetStr = ''],
90
+ help,
91
+ ...options
92
+ } = argv;
89
93
const [project, target, configuration] = targetStr.split(':');
90
94
const targetSpec = { project, target, configuration };
91
95
92
- delete argv['help'];
93
96
const logger = new logging.Logger('jobs');
94
97
const logs: logging.LogEntry[] = [];
95
98
logger.subscribe((entry) => logs.push({ ...entry, message: ` $ { entry . name } : ` + entry.message }));
96
99
97
- const { _, ...options } = argv;
98
- const run = await architect.scheduleTarget(targetSpec, options, { logger });
100
+ // Camelize options as yargs will return the object in kebab-case when camel casing is disabled.
101
+
102
+ // Casting temporary until https://github.com/DefinitelyTyped/DefinitelyTyped/pull/59065 is merged and released.
103
+ const { camelCase, decamelize } = yargsParser as yargsParser.Parser & {
104
+ camelCase(str: string): string;
105
+ decamelize(str: string, joinString?: string): string;
106
+ };
107
+
108
+ const camelCasedOptions: json.JsonObject = {};
109
+ for (const [key, value] of Object.entries(options)) {
110
+ if (/[A-Z]/.test(key)) {
111
+ throw new Error(` Unknown argument ${key } . Did you mean ${decamelize ( key ) } ?`);
112
+ }
113
+
114
+ camelCasedOptions[camelCase(key)] = value;
115
+ }
116
+
117
+ const run = await architect.scheduleTarget(targetSpec, camelCasedOptions, { logger });
99
118
const bars = new MultiProgressBar<number, BarInfo>(':name :bar (:current/:total) :status');
100
119
101
120
run.progress.subscribe((update) => {
@@ -107,7 +126,7 @@ async function _executeTarget(
107
126
name: (
108
127
(update.target ? _targetStringFromTarget(update.target) : update.builder.name) +
109
128
' '.repeat(80)
110
- ).substr (0, 40),
129
+ ).substring (0, 40),
111
130
};
112
131
113
132
if (update.status !== undefined) {
@@ -175,7 +194,15 @@ async function _executeTarget(
175
194
176
195
async function main(args: string[]): Promise<number> {
177
196
/** Parse the command line. */
178
- const argv = minimist(args, { boolean: ['help'] });
197
+ const argv = yargsParser(args, {
198
+ boolean: ['help'],
199
+ configuration: {
200
+ 'dot-notation': false,
201
+ 'boolean-negation': true,
202
+ 'strip-aliased': true,
203
+ 'camel-case-expansion': false,
204
+ },
205
+ });
179
206
180
207
/** Create the DevKit Logger used through the CLI. */
181
208
const logger = createConsoleLogger(argv['verbose'], process.stdout, process.stderr, {
0 commit comments