@angular/cli 14.0.0-next.1 → 14.0.0-next.12
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/bin/ng.js +3 -5
- package/lib/cli/index.d.ts +1 -2
- package/lib/cli/index.js +16 -45
- package/lib/config/schema.json +48 -15
- package/lib/config/workspace-schema.d.ts +18 -1
- package/lib/init.js +10 -9
- package/package.json +21 -23
- package/{models → src/analytics}/analytics-collector.d.ts +0 -0
- package/{models → src/analytics}/analytics-collector.js +8 -2
- package/src/analytics/analytics.d.ts +47 -0
- package/src/analytics/analytics.js +306 -0
- package/src/command-builder/architect-base-command-module.d.ts +30 -0
- package/src/command-builder/architect-base-command-module.js +165 -0
- package/src/command-builder/architect-command-module.d.ts +25 -0
- package/src/command-builder/architect-command-module.js +134 -0
- package/src/command-builder/command-module.d.ts +89 -0
- package/src/command-builder/command-module.js +198 -0
- package/{utilities/package-json.js → src/command-builder/command-runner.d.ts} +2 -2
- package/src/command-builder/command-runner.js +168 -0
- package/src/command-builder/schematics-command-module.d.ts +43 -0
- package/src/command-builder/schematics-command-module.js +333 -0
- package/src/command-builder/utilities/command.d.ts +13 -0
- package/src/command-builder/utilities/command.js +27 -0
- package/src/command-builder/utilities/json-help.d.ts +36 -0
- package/src/command-builder/utilities/json-help.js +94 -0
- package/src/command-builder/utilities/json-schema.d.ts +40 -0
- package/{utilities → src/command-builder/utilities}/json-schema.js +20 -121
- package/src/command-builder/utilities/normalize-options-middleware.d.ts +18 -0
- package/src/command-builder/utilities/normalize-options-middleware.js +59 -0
- package/{models → src/command-builder/utilities}/schematic-engine-host.d.ts +2 -2
- package/{models → src/command-builder/utilities}/schematic-engine-host.js +33 -18
- package/src/command-builder/utilities/schematic-workflow.d.ts +14 -0
- package/src/command-builder/utilities/schematic-workflow.js +68 -0
- package/src/commands/add/cli.d.ts +33 -0
- package/{commands/add-impl.js → src/commands/add/cli.js} +108 -80
- package/src/commands/add/long-description.md +7 -0
- package/src/commands/analytics/cli.d.ts +16 -0
- package/src/commands/analytics/cli.js +35 -0
- package/src/commands/analytics/info/cli.d.ts +16 -0
- package/src/commands/analytics/info/cli.js +26 -0
- package/src/commands/analytics/settings/cli.d.ts +35 -0
- package/src/commands/analytics/settings/cli.js +61 -0
- package/src/commands/build/cli.d.ts +16 -0
- package/src/commands/build/cli.js +23 -0
- package/{commands/build-long.md → src/commands/build/long-description.md} +0 -0
- package/src/commands/cache/clean/cli.d.ts +17 -0
- package/src/commands/cache/clean/cli.js +32 -0
- package/src/commands/cache/cli.d.ts +17 -0
- package/src/commands/cache/cli.js +38 -0
- package/src/commands/cache/info/cli.d.ts +20 -0
- package/src/commands/cache/info/cli.js +82 -0
- package/src/commands/cache/long-description.md +53 -0
- package/src/commands/cache/settings/cli.d.ts +27 -0
- package/src/commands/cache/settings/cli.js +42 -0
- package/src/commands/cache/utilities.d.ts +11 -0
- package/src/commands/cache/utilities.js +49 -0
- package/src/commands/completion/cli.d.ts +16 -0
- package/src/commands/completion/cli.js +31 -0
- package/src/commands/completion/long-description.md +1 -0
- package/src/commands/config/cli.d.ts +24 -0
- package/{commands/config-impl.js → src/commands/config/cli.js} +102 -89
- package/{commands/config-long.md → src/commands/config/long-description.md} +2 -2
- package/src/commands/deploy/cli.d.ts +17 -0
- package/src/commands/deploy/cli.js +49 -0
- package/{commands/deploy-long.md → src/commands/deploy/long-description.md} +0 -0
- package/src/commands/doc/cli.d.ts +23 -0
- package/{commands/doc-impl.js → src/commands/doc/cli.js} +41 -12
- package/src/commands/e2e/cli.d.ts +18 -0
- package/src/commands/e2e/cli.js +35 -0
- package/src/commands/extract-i18n/cli.d.ts +15 -0
- package/src/commands/extract-i18n/cli.js +20 -0
- package/src/commands/generate/cli.d.ts +39 -0
- package/src/commands/generate/cli.js +145 -0
- package/src/commands/lint/cli.d.ts +17 -0
- package/src/commands/lint/cli.js +28 -0
- package/{commands/lint-long.md → src/commands/lint/long-description.md} +0 -0
- package/src/commands/make-this-awesome/cli.d.ts +17 -0
- package/{commands/easter-egg-impl.js → src/commands/make-this-awesome/cli.js} +17 -10
- package/src/commands/new/cli.d.ts +27 -0
- package/src/commands/new/cli.js +82 -0
- package/src/commands/run/cli.d.ts +25 -0
- package/src/commands/run/cli.js +83 -0
- package/{commands/run-long.md → src/commands/run/long-description.md} +0 -0
- package/src/commands/serve/cli.d.ts +16 -0
- package/src/commands/serve/cli.js +21 -0
- package/src/commands/test/cli.d.ts +16 -0
- package/src/commands/test/cli.js +23 -0
- package/{commands/test-long.md → src/commands/test/long-description.md} +0 -0
- package/{commands/update-impl.d.ts → src/commands/update/cli.d.ts} +26 -9
- package/{commands/update-impl.js → src/commands/update/cli.js} +363 -316
- package/{commands/update-long.md → src/commands/update/long-description.md} +0 -0
- package/src/commands/update/schematic/index.js +33 -20
- package/src/commands/version/cli.d.ts +18 -0
- package/{commands/version-impl.js → src/commands/version/cli.js} +56 -74
- package/src/typings-bazel.d.ts +14 -0
- package/src/typings.d.ts +1 -14
- package/{utilities → src/utilities}/color.d.ts +0 -0
- package/{utilities → src/utilities}/color.js +5 -1
- package/{utilities → src/utilities}/config.d.ts +6 -5
- package/{utilities → src/utilities}/config.js +33 -19
- package/src/utilities/environment-options.d.ts +12 -0
- package/src/utilities/environment-options.js +24 -0
- package/{utilities → src/utilities}/find-up.d.ts +0 -0
- package/{utilities → src/utilities}/find-up.js +5 -1
- package/{utilities → src/utilities}/json-file.d.ts +0 -0
- package/{utilities → src/utilities}/json-file.js +1 -0
- package/{utilities → src/utilities}/log-file.d.ts +0 -0
- package/{utilities → src/utilities}/log-file.js +0 -0
- package/src/utilities/memoize.d.ts +15 -0
- package/src/utilities/memoize.js +69 -0
- package/src/utilities/package-manager.d.ts +41 -0
- package/src/utilities/package-manager.js +287 -0
- package/{utilities → src/utilities}/package-metadata.d.ts +15 -37
- package/{utilities → src/utilities}/package-metadata.js +15 -27
- package/{utilities → src/utilities}/package-tree.d.ts +2 -2
- package/{utilities → src/utilities}/package-tree.js +5 -1
- package/{utilities → src/utilities}/project.d.ts +0 -0
- package/{utilities → src/utilities}/project.js +5 -1
- package/{utilities → src/utilities}/prompt.d.ts +2 -0
- package/{utilities → src/utilities}/prompt.js +25 -4
- package/{utilities → src/utilities}/spinner.d.ts +0 -0
- package/{utilities → src/utilities}/spinner.js +0 -0
- package/{utilities → src/utilities}/tty.d.ts +0 -0
- package/{utilities → src/utilities}/tty.js +0 -0
- package/{models → src/utilities}/version.d.ts +2 -1
- package/{models → src/utilities}/version.js +6 -6
- package/bin/postinstall/analytics-prompt.js +0 -27
- package/bin/postinstall/script.js +0 -16
- package/commands/add-impl.d.ts +0 -21
- package/commands/add.d.ts +0 -42
- package/commands/add.js +0 -10
- package/commands/add.json +0 -54
- package/commands/add.md +0 -10
- package/commands/analytics-impl.d.ts +0 -13
- package/commands/analytics-impl.js +0 -80
- package/commands/analytics-long.md +0 -8
- package/commands/analytics.d.ts +0 -46
- package/commands/analytics.js +0 -31
- package/commands/analytics.json +0 -37
- package/commands/build-impl.d.ts +0 -14
- package/commands/build-impl.js +0 -21
- package/commands/build.d.ts +0 -30
- package/commands/build.js +0 -10
- package/commands/build.json +0 -16
- package/commands/config-impl.d.ts +0 -15
- package/commands/config.d.ts +0 -34
- package/commands/config.js +0 -10
- package/commands/config.json +0 -43
- package/commands/definitions.json +0 -66
- package/commands/deploy-impl.d.ts +0 -15
- package/commands/deploy-impl.js +0 -36
- package/commands/deploy.d.ts +0 -30
- package/commands/deploy.js +0 -10
- package/commands/deploy.json +0 -34
- package/commands/doc-impl.d.ts +0 -13
- package/commands/doc.d.ts +0 -39
- package/commands/doc.js +0 -14
- package/commands/doc.json +0 -46
- package/commands/e2e-impl.d.ts +0 -16
- package/commands/e2e-impl.js +0 -36
- package/commands/e2e-long.md +0 -4
- package/commands/e2e.d.ts +0 -29
- package/commands/e2e.js +0 -10
- package/commands/e2e.json +0 -17
- package/commands/easter-egg-impl.d.ts +0 -12
- package/commands/easter-egg.d.ts +0 -14
- package/commands/easter-egg.js +0 -10
- package/commands/easter-egg.json +0 -12
- package/commands/extract-i18n-impl.d.ts +0 -14
- package/commands/extract-i18n-impl.js +0 -32
- package/commands/extract-i18n.d.ts +0 -29
- package/commands/extract-i18n.js +0 -10
- package/commands/extract-i18n.json +0 -17
- package/commands/generate-impl.d.ts +0 -18
- package/commands/generate-impl.js +0 -89
- package/commands/generate.d.ts +0 -37
- package/commands/generate.js +0 -10
- package/commands/generate.json +0 -31
- package/commands/help-impl.d.ts +0 -12
- package/commands/help-impl.js +0 -26
- package/commands/help-long.md +0 -7
- package/commands/help.d.ts +0 -17
- package/commands/help.js +0 -10
- package/commands/help.json +0 -13
- package/commands/lint-impl.d.ts +0 -16
- package/commands/lint-impl.js +0 -69
- package/commands/lint.d.ts +0 -29
- package/commands/lint.js +0 -10
- package/commands/lint.json +0 -36
- package/commands/new-impl.d.ts +0 -16
- package/commands/new-impl.js +0 -37
- package/commands/new.d.ts +0 -41
- package/commands/new.js +0 -10
- package/commands/new.json +0 -34
- package/commands/new.md +0 -16
- package/commands/run-impl.d.ts +0 -13
- package/commands/run-impl.js +0 -22
- package/commands/run.d.ts +0 -30
- package/commands/run.js +0 -10
- package/commands/run.json +0 -36
- package/commands/serve-impl.d.ts +0 -15
- package/commands/serve-impl.js +0 -24
- package/commands/serve.d.ts +0 -29
- package/commands/serve.js +0 -10
- package/commands/serve.json +0 -17
- package/commands/test-impl.d.ts +0 -15
- package/commands/test-impl.js +0 -22
- package/commands/test.d.ts +0 -29
- package/commands/test.js +0 -10
- package/commands/test.json +0 -17
- package/commands/update.d.ts +0 -61
- package/commands/update.js +0 -10
- package/commands/update.json +0 -78
- package/commands/version-impl.d.ts +0 -17
- package/commands/version.d.ts +0 -17
- package/commands/version.js +0 -10
- package/commands/version.json +0 -13
- package/commands.json +0 -20
- package/models/analytics.d.ts +0 -58
- package/models/analytics.js +0 -358
- package/models/architect-command.d.ts +0 -35
- package/models/architect-command.js +0 -364
- package/models/command-runner.d.ts +0 -24
- package/models/command-runner.js +0 -241
- package/models/command.d.ts +0 -34
- package/models/command.js +0 -143
- package/models/interface.d.ts +0 -196
- package/models/interface.js +0 -31
- package/models/parser.d.ts +0 -39
- package/models/parser.js +0 -349
- package/models/schematic-command.d.ts +0 -55
- package/models/schematic-command.js +0 -485
- package/utilities/INITIAL_COMMIT_MESSAGE.txt +0 -8
- package/utilities/install-package.d.ts +0 -16
- package/utilities/install-package.js +0 -193
- package/utilities/json-schema.d.ts +0 -17
- package/utilities/package-json.d.ts +0 -249
- package/utilities/package-manager.d.ts +0 -13
- package/utilities/package-manager.js +0 -106
package/models/parser.js
DELETED
|
@@ -1,349 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @license
|
|
4
|
-
* Copyright Google LLC All Rights Reserved.
|
|
5
|
-
*
|
|
6
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
-
* found in the LICENSE file at https://angular.io/license
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.parseArguments = exports.parseFreeFormArguments = exports.ParseArgumentException = void 0;
|
|
11
|
-
const core_1 = require("@angular-devkit/core");
|
|
12
|
-
const interface_1 = require("./interface");
|
|
13
|
-
class ParseArgumentException extends core_1.BaseException {
|
|
14
|
-
constructor(comments, parsed, ignored) {
|
|
15
|
-
super(`One or more errors occurred while parsing arguments:\n ${comments.join('\n ')}`);
|
|
16
|
-
this.comments = comments;
|
|
17
|
-
this.parsed = parsed;
|
|
18
|
-
this.ignored = ignored;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.ParseArgumentException = ParseArgumentException;
|
|
22
|
-
function _coerceType(str, type, v) {
|
|
23
|
-
switch (type) {
|
|
24
|
-
case interface_1.OptionType.Any:
|
|
25
|
-
if (Array.isArray(v)) {
|
|
26
|
-
return v.concat(str || '');
|
|
27
|
-
}
|
|
28
|
-
return _coerceType(str, interface_1.OptionType.Boolean, v) !== undefined
|
|
29
|
-
? _coerceType(str, interface_1.OptionType.Boolean, v)
|
|
30
|
-
: _coerceType(str, interface_1.OptionType.Number, v) !== undefined
|
|
31
|
-
? _coerceType(str, interface_1.OptionType.Number, v)
|
|
32
|
-
: _coerceType(str, interface_1.OptionType.String, v);
|
|
33
|
-
case interface_1.OptionType.String:
|
|
34
|
-
return str || '';
|
|
35
|
-
case interface_1.OptionType.Boolean:
|
|
36
|
-
switch (str) {
|
|
37
|
-
case 'false':
|
|
38
|
-
return false;
|
|
39
|
-
case undefined:
|
|
40
|
-
case '':
|
|
41
|
-
case 'true':
|
|
42
|
-
return true;
|
|
43
|
-
default:
|
|
44
|
-
return undefined;
|
|
45
|
-
}
|
|
46
|
-
case interface_1.OptionType.Number:
|
|
47
|
-
if (str === undefined) {
|
|
48
|
-
return 0;
|
|
49
|
-
}
|
|
50
|
-
else if (str === '') {
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
else if (Number.isFinite(+str)) {
|
|
54
|
-
return +str;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
return undefined;
|
|
58
|
-
}
|
|
59
|
-
case interface_1.OptionType.Array:
|
|
60
|
-
return Array.isArray(v)
|
|
61
|
-
? v.concat(str || '')
|
|
62
|
-
: v === undefined
|
|
63
|
-
? [str || '']
|
|
64
|
-
: [v + '', str || ''];
|
|
65
|
-
default:
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
function _coerce(str, o, v) {
|
|
70
|
-
if (!o) {
|
|
71
|
-
return _coerceType(str, interface_1.OptionType.Any, v);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
const types = o.types || [o.type];
|
|
75
|
-
// Try all the types one by one and pick the first one that returns a value contained in the
|
|
76
|
-
// enum. If there's no enum, just return the first one that matches.
|
|
77
|
-
for (const type of types) {
|
|
78
|
-
const maybeResult = _coerceType(str, type, v);
|
|
79
|
-
if (maybeResult !== undefined && (!o.enum || o.enum.includes(maybeResult))) {
|
|
80
|
-
return maybeResult;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function _getOptionFromName(name, options) {
|
|
87
|
-
const camelName = /(-|_)/.test(name) ? core_1.strings.camelize(name) : name;
|
|
88
|
-
for (const option of options) {
|
|
89
|
-
if (option.name === name || option.name === camelName) {
|
|
90
|
-
return option;
|
|
91
|
-
}
|
|
92
|
-
if (option.aliases.some((x) => x === name || x === camelName)) {
|
|
93
|
-
return option;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return undefined;
|
|
97
|
-
}
|
|
98
|
-
function _removeLeadingDashes(key) {
|
|
99
|
-
const from = key.startsWith('--') ? 2 : key.startsWith('-') ? 1 : 0;
|
|
100
|
-
return key.substr(from);
|
|
101
|
-
}
|
|
102
|
-
function _assignOption(arg, nextArg, { options, parsedOptions, leftovers, ignored, errors, warnings, }) {
|
|
103
|
-
const from = arg.startsWith('--') ? 2 : 1;
|
|
104
|
-
let consumedNextArg = false;
|
|
105
|
-
let key = arg.substr(from);
|
|
106
|
-
let option = null;
|
|
107
|
-
let value = '';
|
|
108
|
-
const i = arg.indexOf('=');
|
|
109
|
-
// If flag is --no-abc AND there's no equal sign.
|
|
110
|
-
if (i == -1) {
|
|
111
|
-
if (key.startsWith('no')) {
|
|
112
|
-
// Only use this key if the option matching the rest is a boolean.
|
|
113
|
-
const from = key.startsWith('no-') ? 3 : 2;
|
|
114
|
-
const maybeOption = _getOptionFromName(core_1.strings.camelize(key.substr(from)), options);
|
|
115
|
-
if (maybeOption && maybeOption.type == 'boolean') {
|
|
116
|
-
value = 'false';
|
|
117
|
-
option = maybeOption;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
if (option === null) {
|
|
121
|
-
// Set it to true if it's a boolean and the next argument doesn't match true/false.
|
|
122
|
-
const maybeOption = _getOptionFromName(key, options);
|
|
123
|
-
if (maybeOption) {
|
|
124
|
-
value = nextArg;
|
|
125
|
-
let shouldShift = true;
|
|
126
|
-
if (value && value.startsWith('-') && _coerce(undefined, maybeOption) !== undefined) {
|
|
127
|
-
// Verify if not having a value results in a correct parse, if so don't shift.
|
|
128
|
-
shouldShift = false;
|
|
129
|
-
}
|
|
130
|
-
// Only absorb it if it leads to a better value.
|
|
131
|
-
if (shouldShift && _coerce(value, maybeOption) !== undefined) {
|
|
132
|
-
consumedNextArg = true;
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
value = '';
|
|
136
|
-
}
|
|
137
|
-
option = maybeOption;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
key = arg.substring(0, i);
|
|
143
|
-
option = _getOptionFromName(_removeLeadingDashes(key), options) || null;
|
|
144
|
-
if (option) {
|
|
145
|
-
value = arg.substring(i + 1);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (option === null) {
|
|
149
|
-
if (nextArg && !nextArg.startsWith('-')) {
|
|
150
|
-
leftovers.push(arg, nextArg);
|
|
151
|
-
consumedNextArg = true;
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
leftovers.push(arg);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
const v = _coerce(value, option, parsedOptions[option.name]);
|
|
159
|
-
if (v !== undefined) {
|
|
160
|
-
if (parsedOptions[option.name] !== v) {
|
|
161
|
-
if (parsedOptions[option.name] !== undefined && option.type !== interface_1.OptionType.Array) {
|
|
162
|
-
warnings.push(`Option ${JSON.stringify(option.name)} was already specified with value ` +
|
|
163
|
-
`${JSON.stringify(parsedOptions[option.name])}. The new value ${JSON.stringify(v)} ` +
|
|
164
|
-
`will override it.`);
|
|
165
|
-
}
|
|
166
|
-
parsedOptions[option.name] = v;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
let error = `Argument ${key} could not be parsed using value ${JSON.stringify(value)}.`;
|
|
171
|
-
if (option.enum) {
|
|
172
|
-
error += ` Valid values are: ${option.enum.map((x) => JSON.stringify(x)).join(', ')}.`;
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
error += `Valid type(s) is: ${(option.types || [option.type]).join(', ')}`;
|
|
176
|
-
}
|
|
177
|
-
errors.push(error);
|
|
178
|
-
ignored.push(arg);
|
|
179
|
-
}
|
|
180
|
-
if (/^[a-z]+[A-Z]/.test(key)) {
|
|
181
|
-
warnings.push('Support for camel case arguments has been deprecated and will be removed in a future major version.\n' +
|
|
182
|
-
`Use '--${core_1.strings.dasherize(key)}' instead of '--${key}'.`);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return consumedNextArg;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Parse the arguments in a consistent way, but without having any option definition. This tries
|
|
189
|
-
* to assess what the user wants in a free form. For example, using `--name=false` will set the
|
|
190
|
-
* name properties to a boolean type.
|
|
191
|
-
* This should only be used when there's no schema available or if a schema is "true" (anything is
|
|
192
|
-
* valid).
|
|
193
|
-
*
|
|
194
|
-
* @param args Argument list to parse.
|
|
195
|
-
* @returns An object that contains a property per flags from the args.
|
|
196
|
-
*/
|
|
197
|
-
function parseFreeFormArguments(args) {
|
|
198
|
-
const parsedOptions = {};
|
|
199
|
-
const leftovers = [];
|
|
200
|
-
for (let arg = args.shift(); arg !== undefined; arg = args.shift()) {
|
|
201
|
-
if (arg == '--') {
|
|
202
|
-
leftovers.push(...args);
|
|
203
|
-
break;
|
|
204
|
-
}
|
|
205
|
-
if (arg.startsWith('--')) {
|
|
206
|
-
const eqSign = arg.indexOf('=');
|
|
207
|
-
let name;
|
|
208
|
-
let value;
|
|
209
|
-
if (eqSign !== -1) {
|
|
210
|
-
name = arg.substring(2, eqSign);
|
|
211
|
-
value = arg.substring(eqSign + 1);
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
name = arg.substr(2);
|
|
215
|
-
value = args.shift();
|
|
216
|
-
}
|
|
217
|
-
const v = _coerce(value, null, parsedOptions[name]);
|
|
218
|
-
if (v !== undefined) {
|
|
219
|
-
parsedOptions[name] = v;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
else if (arg.startsWith('-')) {
|
|
223
|
-
arg.split('').forEach((x) => (parsedOptions[x] = true));
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
leftovers.push(arg);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
if (leftovers.length) {
|
|
230
|
-
parsedOptions['--'] = leftovers;
|
|
231
|
-
}
|
|
232
|
-
return parsedOptions;
|
|
233
|
-
}
|
|
234
|
-
exports.parseFreeFormArguments = parseFreeFormArguments;
|
|
235
|
-
/**
|
|
236
|
-
* Parse the arguments in a consistent way, from a list of standardized options.
|
|
237
|
-
* The result object will have a key per option name, with the `_` key reserved for positional
|
|
238
|
-
* arguments, and `--` will contain everything that did not match. Any key that don't have an
|
|
239
|
-
* option will be pushed back in `--` and removed from the object. If you need to validate that
|
|
240
|
-
* there's no additionalProperties, you need to check the `--` key.
|
|
241
|
-
*
|
|
242
|
-
* @param args The argument array to parse.
|
|
243
|
-
* @param options List of supported options. {@see Option}.
|
|
244
|
-
* @param logger Logger to use to warn users.
|
|
245
|
-
* @returns An object that contains a property per option.
|
|
246
|
-
*/
|
|
247
|
-
function parseArguments(args, options, logger) {
|
|
248
|
-
if (options === null) {
|
|
249
|
-
options = [];
|
|
250
|
-
}
|
|
251
|
-
const leftovers = [];
|
|
252
|
-
const positionals = [];
|
|
253
|
-
const parsedOptions = {};
|
|
254
|
-
const ignored = [];
|
|
255
|
-
const errors = [];
|
|
256
|
-
const warnings = [];
|
|
257
|
-
const state = { options, parsedOptions, positionals, leftovers, ignored, errors, warnings };
|
|
258
|
-
for (let argIndex = 0; argIndex < args.length; argIndex++) {
|
|
259
|
-
const arg = args[argIndex];
|
|
260
|
-
let consumedNextArg = false;
|
|
261
|
-
if (arg == '--') {
|
|
262
|
-
// If we find a --, we're done.
|
|
263
|
-
leftovers.push(...args.slice(argIndex + 1));
|
|
264
|
-
break;
|
|
265
|
-
}
|
|
266
|
-
if (arg.startsWith('--')) {
|
|
267
|
-
consumedNextArg = _assignOption(arg, args[argIndex + 1], state);
|
|
268
|
-
}
|
|
269
|
-
else if (arg.startsWith('-')) {
|
|
270
|
-
// Argument is of form -abcdef. Starts at 1 because we skip the `-`.
|
|
271
|
-
for (let i = 1; i < arg.length; i++) {
|
|
272
|
-
const flag = arg[i];
|
|
273
|
-
// If the next character is an '=', treat it as a long flag.
|
|
274
|
-
if (arg[i + 1] == '=') {
|
|
275
|
-
const f = '-' + flag + arg.slice(i + 1);
|
|
276
|
-
consumedNextArg = _assignOption(f, args[argIndex + 1], state);
|
|
277
|
-
break;
|
|
278
|
-
}
|
|
279
|
-
// Treat the last flag as `--a` (as if full flag but just one letter). We do this in
|
|
280
|
-
// the loop because it saves us a check to see if the arg is just `-`.
|
|
281
|
-
if (i == arg.length - 1) {
|
|
282
|
-
const arg = '-' + flag;
|
|
283
|
-
consumedNextArg = _assignOption(arg, args[argIndex + 1], state);
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
const maybeOption = _getOptionFromName(flag, options);
|
|
287
|
-
if (maybeOption) {
|
|
288
|
-
const v = _coerce(undefined, maybeOption, parsedOptions[maybeOption.name]);
|
|
289
|
-
if (v !== undefined) {
|
|
290
|
-
parsedOptions[maybeOption.name] = v;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
else {
|
|
297
|
-
positionals.push(arg);
|
|
298
|
-
}
|
|
299
|
-
if (consumedNextArg) {
|
|
300
|
-
argIndex++;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
// Deal with positionals.
|
|
304
|
-
// TODO(hansl): this is by far the most complex piece of code in this file. Try to refactor it
|
|
305
|
-
// simpler.
|
|
306
|
-
if (positionals.length > 0) {
|
|
307
|
-
let pos = 0;
|
|
308
|
-
for (let i = 0; i < positionals.length;) {
|
|
309
|
-
let found = false;
|
|
310
|
-
let incrementPos = false;
|
|
311
|
-
let incrementI = true;
|
|
312
|
-
// We do this with a found flag because more than 1 option could have the same positional.
|
|
313
|
-
for (const option of options) {
|
|
314
|
-
// If any option has this positional and no value, AND fit the type, we need to remove it.
|
|
315
|
-
if (option.positional === pos) {
|
|
316
|
-
const coercedValue = _coerce(positionals[i], option, parsedOptions[option.name]);
|
|
317
|
-
if (parsedOptions[option.name] === undefined && coercedValue !== undefined) {
|
|
318
|
-
parsedOptions[option.name] = coercedValue;
|
|
319
|
-
found = true;
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
incrementI = false;
|
|
323
|
-
}
|
|
324
|
-
incrementPos = true;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
if (found) {
|
|
328
|
-
positionals.splice(i--, 1);
|
|
329
|
-
}
|
|
330
|
-
if (incrementPos) {
|
|
331
|
-
pos++;
|
|
332
|
-
}
|
|
333
|
-
if (incrementI) {
|
|
334
|
-
i++;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
if (positionals.length > 0 || leftovers.length > 0) {
|
|
339
|
-
parsedOptions['--'] = [...positionals, ...leftovers];
|
|
340
|
-
}
|
|
341
|
-
if (warnings.length > 0 && logger) {
|
|
342
|
-
warnings.forEach((message) => logger.warn(message));
|
|
343
|
-
}
|
|
344
|
-
if (errors.length > 0) {
|
|
345
|
-
throw new ParseArgumentException(errors, parsedOptions, ignored);
|
|
346
|
-
}
|
|
347
|
-
return parsedOptions;
|
|
348
|
-
}
|
|
349
|
-
exports.parseArguments = parseArguments;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Google LLC All Rights Reserved.
|
|
4
|
-
*
|
|
5
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.io/license
|
|
7
|
-
*/
|
|
8
|
-
import { logging } from '@angular-devkit/core';
|
|
9
|
-
import { workflow } from '@angular-devkit/schematics';
|
|
10
|
-
import { FileSystemCollection, FileSystemEngine, FileSystemSchematic, NodeWorkflow } from '@angular-devkit/schematics/tools';
|
|
11
|
-
import { BaseCommandOptions, Command } from './command';
|
|
12
|
-
import { Arguments, CommandContext, CommandDescription, Option } from './interface';
|
|
13
|
-
export interface BaseSchematicSchema {
|
|
14
|
-
debug?: boolean;
|
|
15
|
-
dryRun?: boolean;
|
|
16
|
-
force?: boolean;
|
|
17
|
-
interactive?: boolean;
|
|
18
|
-
defaults?: boolean;
|
|
19
|
-
packageRegistry?: string;
|
|
20
|
-
}
|
|
21
|
-
export interface RunSchematicOptions extends BaseSchematicSchema {
|
|
22
|
-
collectionName: string;
|
|
23
|
-
schematicName: string;
|
|
24
|
-
additionalOptions?: {
|
|
25
|
-
[key: string]: {};
|
|
26
|
-
};
|
|
27
|
-
schematicOptions?: string[];
|
|
28
|
-
showNothingDone?: boolean;
|
|
29
|
-
}
|
|
30
|
-
export declare class UnknownCollectionError extends Error {
|
|
31
|
-
constructor(collectionName: string);
|
|
32
|
-
}
|
|
33
|
-
export declare abstract class SchematicCommand<T extends BaseSchematicSchema & BaseCommandOptions> extends Command<T> {
|
|
34
|
-
protected readonly allowPrivateSchematics: boolean;
|
|
35
|
-
protected readonly useReportAnalytics = false;
|
|
36
|
-
protected _workflow: NodeWorkflow;
|
|
37
|
-
protected defaultCollectionName: string;
|
|
38
|
-
protected collectionName: string;
|
|
39
|
-
protected schematicName?: string;
|
|
40
|
-
constructor(context: CommandContext, description: CommandDescription, logger: logging.Logger);
|
|
41
|
-
initialize(options: T & Arguments): Promise<void>;
|
|
42
|
-
printHelp(): Promise<number>;
|
|
43
|
-
printHelpUsage(): Promise<void>;
|
|
44
|
-
protected getEngine(): FileSystemEngine;
|
|
45
|
-
protected getCollection(collectionName: string): FileSystemCollection;
|
|
46
|
-
protected getSchematic(collection: FileSystemCollection, schematicName: string, allowPrivate?: boolean): FileSystemSchematic;
|
|
47
|
-
protected setPathOptions(options: Option[], workingDir: string): {
|
|
48
|
-
[name: string]: string;
|
|
49
|
-
};
|
|
50
|
-
protected createWorkflow(options: BaseSchematicSchema): Promise<workflow.BaseWorkflow>;
|
|
51
|
-
protected getDefaultSchematicCollection(): Promise<string>;
|
|
52
|
-
protected runSchematic(options: RunSchematicOptions): Promise<number | void>;
|
|
53
|
-
protected parseFreeFormArguments(schematicOptions: string[]): Promise<Arguments>;
|
|
54
|
-
protected parseArguments(schematicOptions: string[], options: Option[] | null): Promise<Arguments>;
|
|
55
|
-
}
|