@angular/cli 14.0.0-next.5 → 14.0.0-next.6
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/postinstall/analytics-prompt.js +2 -2
- package/lib/config/schema.json +4 -4
- package/lib/config/workspace-schema.d.ts +1 -1
- package/lib/init.js +5 -1
- package/package.json +13 -13
- package/src/analytics/analytics-collector.js +5 -1
- package/{models/interface.js → src/analytics/analytics-environment-options.d.ts} +2 -2
- package/src/analytics/analytics-environment-options.js +20 -0
- package/src/analytics/analytics.d.ts +10 -23
- package/src/analytics/analytics.js +96 -182
- package/src/command-builder/architect-base-command-module.js +3 -5
- package/src/command-builder/architect-command-module.js +4 -6
- package/src/command-builder/command-module.d.ts +4 -1
- package/src/command-builder/command-module.js +9 -3
- package/src/command-builder/command-runner.js +9 -20
- package/src/command-builder/schematics-command-module.d.ts +18 -5
- package/src/command-builder/schematics-command-module.js +207 -29
- 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 +16 -14
- package/src/command-builder/utilities/json-help.js +26 -22
- package/{models → src/command-builder/utilities}/schematic-engine-host.d.ts +0 -0
- package/{models → src/command-builder/utilities}/schematic-engine-host.js +0 -0
- 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 +11 -1
- package/src/commands/add/cli.js +325 -6
- package/src/commands/analytics/cli.d.ts +5 -10
- package/src/commands/analytics/cli.js +15 -50
- 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/config/cli.d.ts +4 -1
- package/src/commands/config/cli.js +126 -4
- package/src/commands/doc/cli.js +5 -1
- package/src/commands/generate/cli.d.ts +4 -2
- package/src/commands/generate/cli.js +37 -21
- package/src/commands/new/cli.d.ts +5 -3
- package/src/commands/new/cli.js +36 -6
- package/src/commands/update/cli.d.ts +30 -5
- package/src/commands/update/cli.js +680 -9
- package/src/commands/update/schematic/index.js +5 -1
- package/src/commands/version/cli.js +18 -23
- package/src/utilities/color.js +5 -1
- package/src/utilities/config.d.ts +1 -0
- package/src/utilities/config.js +36 -2
- package/src/utilities/find-up.js +5 -1
- package/src/utilities/package-metadata.js +5 -1
- package/src/utilities/package-tree.js +5 -1
- package/src/utilities/project.js +5 -1
- package/src/utilities/prompt.js +5 -1
- package/models/command.d.ts +0 -29
- package/models/command.js +0 -50
- package/models/interface.d.ts +0 -19
- package/models/schematic-command.d.ts +0 -43
- package/models/schematic-command.js +0 -378
- package/src/commands/add/add-impl.d.ts +0 -22
- package/src/commands/add/add-impl.js +0 -331
- package/src/commands/analytics/long-description.md +0 -10
- package/src/commands/config/config-impl.d.ts +0 -17
- package/src/commands/config/config-impl.js +0 -151
- package/src/commands/generate/generate-impl.d.ts +0 -19
- package/src/commands/generate/generate-impl.js +0 -49
- package/src/commands/new/new-impl.d.ts +0 -18
- package/src/commands/new/new-impl.js +0 -38
- package/src/commands/update/update-impl.d.ts +0 -40
- package/src/commands/update/update-impl.js +0 -728
|
@@ -1,331 +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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.AddCommandModule = void 0;
|
|
14
|
-
const core_1 = require("@angular-devkit/core");
|
|
15
|
-
const tools_1 = require("@angular-devkit/schematics/tools");
|
|
16
|
-
const npm_package_arg_1 = __importDefault(require("npm-package-arg"));
|
|
17
|
-
const path_1 = require("path");
|
|
18
|
-
const semver_1 = require("semver");
|
|
19
|
-
const workspace_schema_1 = require("../../../lib/config/workspace-schema");
|
|
20
|
-
const schematic_command_1 = require("../../../models/schematic-command");
|
|
21
|
-
const analytics_1 = require("../../analytics/analytics");
|
|
22
|
-
const color_1 = require("../../utilities/color");
|
|
23
|
-
const install_package_1 = require("../../utilities/install-package");
|
|
24
|
-
const package_manager_1 = require("../../utilities/package-manager");
|
|
25
|
-
const package_metadata_1 = require("../../utilities/package-metadata");
|
|
26
|
-
const prompt_1 = require("../../utilities/prompt");
|
|
27
|
-
const spinner_1 = require("../../utilities/spinner");
|
|
28
|
-
const tty_1 = require("../../utilities/tty");
|
|
29
|
-
/**
|
|
30
|
-
* The set of packages that should have certain versions excluded from consideration
|
|
31
|
-
* when attempting to find a compatible version for a package.
|
|
32
|
-
* The key is a package name and the value is a SemVer range of versions to exclude.
|
|
33
|
-
*/
|
|
34
|
-
const packageVersionExclusions = {
|
|
35
|
-
// @angular/localize@9.x versions do not have peer dependencies setup
|
|
36
|
-
'@angular/localize': '9.x',
|
|
37
|
-
};
|
|
38
|
-
class AddCommandModule extends schematic_command_1.SchematicCommand {
|
|
39
|
-
constructor() {
|
|
40
|
-
super(...arguments);
|
|
41
|
-
this.allowPrivateSchematics = true;
|
|
42
|
-
}
|
|
43
|
-
// eslint-disable-next-line max-lines-per-function
|
|
44
|
-
async run(options) {
|
|
45
|
-
var _a;
|
|
46
|
-
await (0, package_manager_1.ensureCompatibleNpm)(this.context.root);
|
|
47
|
-
if (!options.collection) {
|
|
48
|
-
this.logger.fatal(`The "ng add" command requires a name argument to be specified eg. ` +
|
|
49
|
-
`${color_1.colors.yellow('ng add [name] ')}. For more details, use "ng help".`);
|
|
50
|
-
return 1;
|
|
51
|
-
}
|
|
52
|
-
let packageIdentifier;
|
|
53
|
-
try {
|
|
54
|
-
packageIdentifier = (0, npm_package_arg_1.default)(options.collection);
|
|
55
|
-
}
|
|
56
|
-
catch (e) {
|
|
57
|
-
this.logger.error(e.message);
|
|
58
|
-
return 1;
|
|
59
|
-
}
|
|
60
|
-
if (packageIdentifier.name &&
|
|
61
|
-
packageIdentifier.registry &&
|
|
62
|
-
this.isPackageInstalled(packageIdentifier.name)) {
|
|
63
|
-
const validVersion = await this.isProjectVersionValid(packageIdentifier);
|
|
64
|
-
if (validVersion) {
|
|
65
|
-
// Already installed so just run schematic
|
|
66
|
-
this.logger.info('Skipping installation: Package already installed');
|
|
67
|
-
return this.executeSchematic(packageIdentifier.name, options);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
const spinner = new spinner_1.Spinner();
|
|
71
|
-
spinner.start('Determining package manager...');
|
|
72
|
-
const packageManager = await (0, package_manager_1.getPackageManager)(this.context.root);
|
|
73
|
-
const usingYarn = packageManager === workspace_schema_1.PackageManager.Yarn;
|
|
74
|
-
spinner.info(`Using package manager: ${color_1.colors.grey(packageManager)}`);
|
|
75
|
-
if (packageIdentifier.name && packageIdentifier.type === 'tag' && !packageIdentifier.rawSpec) {
|
|
76
|
-
// only package name provided; search for viable version
|
|
77
|
-
// plus special cases for packages that did not have peer deps setup
|
|
78
|
-
spinner.start('Searching for compatible package version...');
|
|
79
|
-
let packageMetadata;
|
|
80
|
-
try {
|
|
81
|
-
packageMetadata = await (0, package_metadata_1.fetchPackageMetadata)(packageIdentifier.name, this.logger, {
|
|
82
|
-
registry: options.registry,
|
|
83
|
-
usingYarn,
|
|
84
|
-
verbose: options.verbose,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
catch (e) {
|
|
88
|
-
spinner.fail('Unable to load package information from registry: ' + e.message);
|
|
89
|
-
return 1;
|
|
90
|
-
}
|
|
91
|
-
// Start with the version tagged as `latest` if it exists
|
|
92
|
-
const latestManifest = packageMetadata.tags['latest'];
|
|
93
|
-
if (latestManifest) {
|
|
94
|
-
packageIdentifier = npm_package_arg_1.default.resolve(latestManifest.name, latestManifest.version);
|
|
95
|
-
}
|
|
96
|
-
// Adjust the version based on name and peer dependencies
|
|
97
|
-
if (latestManifest && Object.keys(latestManifest.peerDependencies).length === 0) {
|
|
98
|
-
if (latestManifest.name === '@angular/pwa') {
|
|
99
|
-
const version = await this.findProjectVersion('@angular/cli');
|
|
100
|
-
const semverOptions = { includePrerelease: true };
|
|
101
|
-
if (version &&
|
|
102
|
-
(((0, semver_1.validRange)(version) && (0, semver_1.intersects)(version, '7', semverOptions)) ||
|
|
103
|
-
((0, semver_1.valid)(version) && (0, semver_1.satisfies)(version, '7', semverOptions)))) {
|
|
104
|
-
packageIdentifier = npm_package_arg_1.default.resolve('@angular/pwa', '0.12');
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
spinner.succeed(`Found compatible package version: ${color_1.colors.grey(packageIdentifier.toString())}.`);
|
|
108
|
-
}
|
|
109
|
-
else if (!latestManifest || (await this.hasMismatchedPeer(latestManifest))) {
|
|
110
|
-
// 'latest' is invalid so search for most recent matching package
|
|
111
|
-
const versionExclusions = packageVersionExclusions[packageMetadata.name];
|
|
112
|
-
const versionManifests = Object.values(packageMetadata.versions).filter((value) => {
|
|
113
|
-
// Prerelease versions are not stable and should not be considered by default
|
|
114
|
-
if ((0, semver_1.prerelease)(value.version)) {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
// Deprecated versions should not be used or considered
|
|
118
|
-
if (value.deprecated) {
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
// Excluded package versions should not be considered
|
|
122
|
-
if (versionExclusions && (0, semver_1.satisfies)(value.version, versionExclusions)) {
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
return true;
|
|
126
|
-
});
|
|
127
|
-
versionManifests.sort((a, b) => (0, semver_1.rcompare)(a.version, b.version, true));
|
|
128
|
-
let newIdentifier;
|
|
129
|
-
for (const versionManifest of versionManifests) {
|
|
130
|
-
if (!(await this.hasMismatchedPeer(versionManifest))) {
|
|
131
|
-
newIdentifier = npm_package_arg_1.default.resolve(versionManifest.name, versionManifest.version);
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (!newIdentifier) {
|
|
136
|
-
spinner.warn("Unable to find compatible package. Using 'latest' tag.");
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
packageIdentifier = newIdentifier;
|
|
140
|
-
spinner.succeed(`Found compatible package version: ${color_1.colors.grey(packageIdentifier.toString())}.`);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
spinner.succeed(`Found compatible package version: ${color_1.colors.grey(packageIdentifier.toString())}.`);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
let collectionName = packageIdentifier.name;
|
|
148
|
-
let savePackage;
|
|
149
|
-
try {
|
|
150
|
-
spinner.start('Loading package information from registry...');
|
|
151
|
-
const manifest = await (0, package_metadata_1.fetchPackageManifest)(packageIdentifier.toString(), this.logger, {
|
|
152
|
-
registry: options.registry,
|
|
153
|
-
verbose: options.verbose,
|
|
154
|
-
usingYarn,
|
|
155
|
-
});
|
|
156
|
-
savePackage = (_a = manifest['ng-add']) === null || _a === void 0 ? void 0 : _a.save;
|
|
157
|
-
collectionName = manifest.name;
|
|
158
|
-
if (await this.hasMismatchedPeer(manifest)) {
|
|
159
|
-
spinner.warn('Package has unmet peer dependencies. Adding the package may not succeed.');
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
spinner.succeed(`Package information loaded.`);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
catch (e) {
|
|
166
|
-
spinner.fail(`Unable to fetch package information for '${packageIdentifier}': ${e.message}`);
|
|
167
|
-
return 1;
|
|
168
|
-
}
|
|
169
|
-
if (!options.skipConfirmation) {
|
|
170
|
-
const confirmationResponse = await (0, prompt_1.askConfirmation)(`\nThe package ${color_1.colors.blue(packageIdentifier.raw)} will be installed and executed.\n` +
|
|
171
|
-
'Would you like to proceed?', true, false);
|
|
172
|
-
if (!confirmationResponse) {
|
|
173
|
-
if (!(0, tty_1.isTTY)()) {
|
|
174
|
-
this.logger.error('No terminal detected. ' +
|
|
175
|
-
`'--skip-confirmation' can be used to bypass installation confirmation. ` +
|
|
176
|
-
`Ensure package name is correct prior to '--skip-confirmation' option usage.`);
|
|
177
|
-
}
|
|
178
|
-
this.logger.error('Command aborted.');
|
|
179
|
-
return 1;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
if (savePackage === false) {
|
|
183
|
-
// Temporary packages are located in a different directory
|
|
184
|
-
// Hence we need to resolve them using the temp path
|
|
185
|
-
const { status, tempNodeModules } = await (0, install_package_1.installTempPackage)(packageIdentifier.raw, packageManager, options.registry ? [`--registry="${options.registry}"`] : undefined);
|
|
186
|
-
const resolvedCollectionPath = require.resolve((0, path_1.join)(collectionName, 'package.json'), {
|
|
187
|
-
paths: [tempNodeModules],
|
|
188
|
-
});
|
|
189
|
-
if (status !== 0) {
|
|
190
|
-
return status;
|
|
191
|
-
}
|
|
192
|
-
collectionName = (0, path_1.dirname)(resolvedCollectionPath);
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
const status = await (0, install_package_1.installPackage)(packageIdentifier.raw, packageManager, savePackage, options.registry ? [`--registry="${options.registry}"`] : undefined);
|
|
196
|
-
if (status !== 0) {
|
|
197
|
-
return status;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return this.executeSchematic(collectionName, options);
|
|
201
|
-
}
|
|
202
|
-
async isProjectVersionValid(packageIdentifier) {
|
|
203
|
-
if (!packageIdentifier.name) {
|
|
204
|
-
return false;
|
|
205
|
-
}
|
|
206
|
-
let validVersion = false;
|
|
207
|
-
const installedVersion = await this.findProjectVersion(packageIdentifier.name);
|
|
208
|
-
if (installedVersion) {
|
|
209
|
-
if (packageIdentifier.type === 'range' && packageIdentifier.fetchSpec) {
|
|
210
|
-
validVersion = (0, semver_1.satisfies)(installedVersion, packageIdentifier.fetchSpec);
|
|
211
|
-
}
|
|
212
|
-
else if (packageIdentifier.type === 'version') {
|
|
213
|
-
const v1 = (0, semver_1.valid)(packageIdentifier.fetchSpec);
|
|
214
|
-
const v2 = (0, semver_1.valid)(installedVersion);
|
|
215
|
-
validVersion = v1 !== null && v1 === v2;
|
|
216
|
-
}
|
|
217
|
-
else if (!packageIdentifier.rawSpec) {
|
|
218
|
-
validVersion = true;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return validVersion;
|
|
222
|
-
}
|
|
223
|
-
async reportAnalytics(paths, options, dimensions = [], metrics = []) {
|
|
224
|
-
const collection = options.collection;
|
|
225
|
-
// Add the collection if it's safe listed.
|
|
226
|
-
if (collection && (0, analytics_1.isPackageNameSafeForAnalytics)(collection)) {
|
|
227
|
-
dimensions[core_1.analytics.NgCliAnalyticsDimensions.NgAddCollection] = collection;
|
|
228
|
-
}
|
|
229
|
-
else {
|
|
230
|
-
delete dimensions[core_1.analytics.NgCliAnalyticsDimensions.NgAddCollection];
|
|
231
|
-
}
|
|
232
|
-
return super.reportAnalytics(paths, options, dimensions, metrics);
|
|
233
|
-
}
|
|
234
|
-
isPackageInstalled(name) {
|
|
235
|
-
try {
|
|
236
|
-
require.resolve((0, path_1.join)(name, 'package.json'), { paths: [this.context.root] });
|
|
237
|
-
return true;
|
|
238
|
-
}
|
|
239
|
-
catch (e) {
|
|
240
|
-
if (e.code !== 'MODULE_NOT_FOUND') {
|
|
241
|
-
throw e;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
return false;
|
|
245
|
-
}
|
|
246
|
-
async executeSchematic(collectionName, options) {
|
|
247
|
-
try {
|
|
248
|
-
const { collection, verbose, registry, skipConfirmation, skipInstall, interactive, force, dryRun, defaults: defaultVal, ...schematicOptions } = options;
|
|
249
|
-
return await this.runSchematic({
|
|
250
|
-
schematicOptions,
|
|
251
|
-
collectionName,
|
|
252
|
-
schematicName: 'ng-add',
|
|
253
|
-
dryRun: false,
|
|
254
|
-
force: false,
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
catch (e) {
|
|
258
|
-
if (e instanceof tools_1.NodePackageDoesNotSupportSchematics) {
|
|
259
|
-
this.logger.error(core_1.tags.oneLine `
|
|
260
|
-
The package that you are trying to add does not support schematics. You can try using
|
|
261
|
-
a different version of the package or contact the package author to add ng-add support.
|
|
262
|
-
`);
|
|
263
|
-
return 1;
|
|
264
|
-
}
|
|
265
|
-
throw e;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
async findProjectVersion(name) {
|
|
269
|
-
let installedPackage;
|
|
270
|
-
try {
|
|
271
|
-
installedPackage = require.resolve((0, path_1.join)(name, 'package.json'), {
|
|
272
|
-
paths: [this.context.root],
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
catch { }
|
|
276
|
-
if (installedPackage) {
|
|
277
|
-
try {
|
|
278
|
-
const installed = await (0, package_metadata_1.fetchPackageManifest)((0, path_1.dirname)(installedPackage), this.logger);
|
|
279
|
-
return installed.version;
|
|
280
|
-
}
|
|
281
|
-
catch { }
|
|
282
|
-
}
|
|
283
|
-
let projectManifest;
|
|
284
|
-
try {
|
|
285
|
-
projectManifest = await (0, package_metadata_1.fetchPackageManifest)(this.context.root, this.logger);
|
|
286
|
-
}
|
|
287
|
-
catch { }
|
|
288
|
-
if (projectManifest) {
|
|
289
|
-
const version = projectManifest.dependencies[name] || projectManifest.devDependencies[name];
|
|
290
|
-
if (version) {
|
|
291
|
-
return version;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
return null;
|
|
295
|
-
}
|
|
296
|
-
async hasMismatchedPeer(manifest) {
|
|
297
|
-
for (const peer in manifest.peerDependencies) {
|
|
298
|
-
let peerIdentifier;
|
|
299
|
-
try {
|
|
300
|
-
peerIdentifier = npm_package_arg_1.default.resolve(peer, manifest.peerDependencies[peer]);
|
|
301
|
-
}
|
|
302
|
-
catch {
|
|
303
|
-
this.logger.warn(`Invalid peer dependency ${peer} found in package.`);
|
|
304
|
-
continue;
|
|
305
|
-
}
|
|
306
|
-
if (peerIdentifier.type === 'version' || peerIdentifier.type === 'range') {
|
|
307
|
-
try {
|
|
308
|
-
const version = await this.findProjectVersion(peer);
|
|
309
|
-
if (!version) {
|
|
310
|
-
continue;
|
|
311
|
-
}
|
|
312
|
-
const options = { includePrerelease: true };
|
|
313
|
-
if (!(0, semver_1.intersects)(version, peerIdentifier.rawSpec, options) &&
|
|
314
|
-
!(0, semver_1.satisfies)(version, peerIdentifier.rawSpec, options)) {
|
|
315
|
-
return true;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
catch {
|
|
319
|
-
// Not found or invalid so ignore
|
|
320
|
-
continue;
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
else {
|
|
324
|
-
// type === 'tag' | 'file' | 'directory' | 'remote' | 'git'
|
|
325
|
-
// Cannot accurately compare these as the tag/location may have changed since install
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
return false;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
exports.AddCommandModule = AddCommandModule;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
The value of `setting-or-project` is one of the following.
|
|
2
|
-
|
|
3
|
-
- `on`: Enables analytics gathering and reporting for the user.
|
|
4
|
-
- `off`: Disables analytics gathering and reporting for the user.
|
|
5
|
-
- `ci`: Enables analytics and configures reporting for use with Continuous Integration,
|
|
6
|
-
which uses a common CI user.
|
|
7
|
-
- `prompt`: Prompts the user to set the status interactively.
|
|
8
|
-
- `project`: Sets the default status for the project to the `project-setting` value, which can be any of the other values. The `project-setting` argument is ignored for all other values of `setting_or_project`.
|
|
9
|
-
|
|
10
|
-
For further details, see [Gathering an Viewing CLI Usage Analytics](cli/usage-analytics-gathering).
|
|
@@ -1,17 +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 { Command } from '../../../models/command';
|
|
9
|
-
import { Options } from '../../command-builder/command-module';
|
|
10
|
-
import { ConfigCommandArgs } from './cli';
|
|
11
|
-
declare type ConfigCommandOptions = Options<ConfigCommandArgs>;
|
|
12
|
-
export declare class ConfigCommand extends Command<ConfigCommandOptions> {
|
|
13
|
-
run(options: ConfigCommandOptions): Promise<0 | 1>;
|
|
14
|
-
private get;
|
|
15
|
-
private set;
|
|
16
|
-
}
|
|
17
|
-
export {};
|
|
@@ -1,151 +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.ConfigCommand = void 0;
|
|
11
|
-
const uuid_1 = require("uuid");
|
|
12
|
-
const command_1 = require("../../../models/command");
|
|
13
|
-
const config_1 = require("../../utilities/config");
|
|
14
|
-
const json_file_1 = require("../../utilities/json-file");
|
|
15
|
-
const validCliPaths = new Map([
|
|
16
|
-
['cli.warnings.versionMismatch', undefined],
|
|
17
|
-
['cli.defaultCollection', undefined],
|
|
18
|
-
['cli.packageManager', undefined],
|
|
19
|
-
['cli.analytics', undefined],
|
|
20
|
-
['cli.analyticsSharing.tracking', undefined],
|
|
21
|
-
['cli.analyticsSharing.uuid', (v) => (v === '' ? (0, uuid_1.v4)() : `${v}`)],
|
|
22
|
-
['cli.cache.enabled', undefined],
|
|
23
|
-
['cli.cache.environment', undefined],
|
|
24
|
-
['cli.cache.path', undefined],
|
|
25
|
-
]);
|
|
26
|
-
/**
|
|
27
|
-
* Splits a JSON path string into fragments. Fragments can be used to get the value referenced
|
|
28
|
-
* by the path. For example, a path of "a[3].foo.bar[2]" would give you a fragment array of
|
|
29
|
-
* ["a", 3, "foo", "bar", 2].
|
|
30
|
-
* @param path The JSON string to parse.
|
|
31
|
-
* @returns {(string|number)[]} The fragments for the string.
|
|
32
|
-
* @private
|
|
33
|
-
*/
|
|
34
|
-
function parseJsonPath(path) {
|
|
35
|
-
const fragments = (path || '').split(/\./g);
|
|
36
|
-
const result = [];
|
|
37
|
-
while (fragments.length > 0) {
|
|
38
|
-
const fragment = fragments.shift();
|
|
39
|
-
if (fragment == undefined) {
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
const match = fragment.match(/([^[]+)((\[.*\])*)/);
|
|
43
|
-
if (!match) {
|
|
44
|
-
throw new Error('Invalid JSON path.');
|
|
45
|
-
}
|
|
46
|
-
result.push(match[1]);
|
|
47
|
-
if (match[2]) {
|
|
48
|
-
const indices = match[2]
|
|
49
|
-
.slice(1, -1)
|
|
50
|
-
.split('][')
|
|
51
|
-
.map((x) => (/^\d$/.test(x) ? +x : x.replace(/"|'/g, '')));
|
|
52
|
-
result.push(...indices);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return result.filter((fragment) => fragment != null);
|
|
56
|
-
}
|
|
57
|
-
function normalizeValue(value) {
|
|
58
|
-
const valueString = `${value}`.trim();
|
|
59
|
-
switch (valueString) {
|
|
60
|
-
case 'true':
|
|
61
|
-
return true;
|
|
62
|
-
case 'false':
|
|
63
|
-
return false;
|
|
64
|
-
case 'null':
|
|
65
|
-
return null;
|
|
66
|
-
case 'undefined':
|
|
67
|
-
return undefined;
|
|
68
|
-
}
|
|
69
|
-
if (isFinite(+valueString)) {
|
|
70
|
-
return +valueString;
|
|
71
|
-
}
|
|
72
|
-
try {
|
|
73
|
-
// We use `JSON.parse` instead of `parseJson` because the latter will parse UUIDs
|
|
74
|
-
// and convert them into a numberic entities.
|
|
75
|
-
// Example: 73b61974-182c-48e4-b4c6-30ddf08c5c98 -> 73.
|
|
76
|
-
// These values should never contain comments, therefore using `JSON.parse` is safe.
|
|
77
|
-
return JSON.parse(valueString);
|
|
78
|
-
}
|
|
79
|
-
catch {
|
|
80
|
-
return value;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
class ConfigCommand extends command_1.Command {
|
|
84
|
-
async run(options) {
|
|
85
|
-
const level = options.global ? 'global' : 'local';
|
|
86
|
-
const [config] = (0, config_1.getWorkspaceRaw)(level);
|
|
87
|
-
if (options.value == undefined) {
|
|
88
|
-
if (!config) {
|
|
89
|
-
this.logger.error('No config found.');
|
|
90
|
-
return 1;
|
|
91
|
-
}
|
|
92
|
-
return this.get(config, options);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
return this.set(options);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
get(jsonFile, options) {
|
|
99
|
-
let value;
|
|
100
|
-
if (options.jsonPath) {
|
|
101
|
-
value = jsonFile.get(parseJsonPath(options.jsonPath));
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
value = jsonFile.content;
|
|
105
|
-
}
|
|
106
|
-
if (value === undefined) {
|
|
107
|
-
this.logger.error('Value cannot be found.');
|
|
108
|
-
return 1;
|
|
109
|
-
}
|
|
110
|
-
else if (typeof value === 'string') {
|
|
111
|
-
this.logger.info(value);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
this.logger.info(JSON.stringify(value, null, 2));
|
|
115
|
-
}
|
|
116
|
-
return 0;
|
|
117
|
-
}
|
|
118
|
-
async set(options) {
|
|
119
|
-
var _a, _b, _c;
|
|
120
|
-
if (!((_a = options.jsonPath) === null || _a === void 0 ? void 0 : _a.trim())) {
|
|
121
|
-
throw new Error('Invalid Path.');
|
|
122
|
-
}
|
|
123
|
-
if (options.global &&
|
|
124
|
-
!options.jsonPath.startsWith('schematics.') &&
|
|
125
|
-
!validCliPaths.has(options.jsonPath)) {
|
|
126
|
-
throw new Error('Invalid Path.');
|
|
127
|
-
}
|
|
128
|
-
const [config, configPath] = (0, config_1.getWorkspaceRaw)(options.global ? 'global' : 'local');
|
|
129
|
-
if (!config || !configPath) {
|
|
130
|
-
this.logger.error('Confguration file cannot be found.');
|
|
131
|
-
return 1;
|
|
132
|
-
}
|
|
133
|
-
const jsonPath = parseJsonPath(options.jsonPath);
|
|
134
|
-
const value = (_c = (_b = validCliPaths.get(options.jsonPath)) === null || _b === void 0 ? void 0 : _b(options.value)) !== null && _c !== void 0 ? _c : options.value;
|
|
135
|
-
const modified = config.modify(jsonPath, normalizeValue(value));
|
|
136
|
-
if (!modified) {
|
|
137
|
-
this.logger.error('Value cannot be found.');
|
|
138
|
-
return 1;
|
|
139
|
-
}
|
|
140
|
-
try {
|
|
141
|
-
await (0, config_1.validateWorkspace)((0, json_file_1.parseJson)(config.content));
|
|
142
|
-
}
|
|
143
|
-
catch (error) {
|
|
144
|
-
this.logger.fatal(error.message);
|
|
145
|
-
return 1;
|
|
146
|
-
}
|
|
147
|
-
config.save();
|
|
148
|
-
return 0;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
exports.ConfigCommand = ConfigCommand;
|
|
@@ -1,19 +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 { SchematicCommand } from '../../../models/schematic-command';
|
|
9
|
-
import { Options, OtherOptions } from '../../command-builder/command-module';
|
|
10
|
-
import { GenerateCommandArgs } from './cli';
|
|
11
|
-
declare type GenerateCommandOptions = Options<GenerateCommandArgs>;
|
|
12
|
-
export declare class GenerateCommand extends SchematicCommand<GenerateCommandOptions> {
|
|
13
|
-
longSchematicName: string | undefined;
|
|
14
|
-
initialize(options: GenerateCommandOptions): Promise<void>;
|
|
15
|
-
run(options: GenerateCommandOptions & OtherOptions): Promise<number | void>;
|
|
16
|
-
reportAnalytics(paths: string[], options: GenerateCommandOptions): Promise<void>;
|
|
17
|
-
private parseSchematicInfo;
|
|
18
|
-
}
|
|
19
|
-
export {};
|
|
@@ -1,49 +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.GenerateCommand = void 0;
|
|
11
|
-
const schematic_command_1 = require("../../../models/schematic-command");
|
|
12
|
-
class GenerateCommand extends schematic_command_1.SchematicCommand {
|
|
13
|
-
async initialize(options) {
|
|
14
|
-
// Fill up the schematics property of the command description.
|
|
15
|
-
const [collectionName, schematicName] = await this.parseSchematicInfo(options.schematic);
|
|
16
|
-
this.collectionName = collectionName !== null && collectionName !== void 0 ? collectionName : (await this.getDefaultSchematicCollection());
|
|
17
|
-
this.schematicName = schematicName;
|
|
18
|
-
await super.initialize(options);
|
|
19
|
-
}
|
|
20
|
-
async run(options) {
|
|
21
|
-
if (!this.schematicName || !this.collectionName) {
|
|
22
|
-
return 1;
|
|
23
|
-
}
|
|
24
|
-
const { dryRun, force, interactive, defaults, schematic, ...schematicOptions } = options;
|
|
25
|
-
return this.runSchematic({
|
|
26
|
-
collectionName: this.collectionName,
|
|
27
|
-
schematicName: this.schematicName,
|
|
28
|
-
schematicOptions: schematicOptions,
|
|
29
|
-
debug: false,
|
|
30
|
-
dryRun,
|
|
31
|
-
force,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
async reportAnalytics(paths, options) {
|
|
35
|
-
if (!this.collectionName || !this.schematicName) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const escapedSchematicName = (this.longSchematicName || this.schematicName).replace(/\//g, '_');
|
|
39
|
-
return super.reportAnalytics(['generate', this.collectionName.replace(/\//g, '_'), escapedSchematicName], options);
|
|
40
|
-
}
|
|
41
|
-
parseSchematicInfo(schematic) {
|
|
42
|
-
if (schematic === null || schematic === void 0 ? void 0 : schematic.includes(':')) {
|
|
43
|
-
const [collectionName, schematicName] = schematic.split(':', 2);
|
|
44
|
-
return [collectionName, schematicName];
|
|
45
|
-
}
|
|
46
|
-
return [undefined, schematic];
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.GenerateCommand = GenerateCommand;
|
|
@@ -1,18 +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 { SchematicCommand } from '../../../models/schematic-command';
|
|
9
|
-
import { Options, OtherOptions } from '../../command-builder/command-module';
|
|
10
|
-
import { NewCommandArgs } from './cli';
|
|
11
|
-
declare type NewCommandOptions = Options<NewCommandArgs>;
|
|
12
|
-
export declare class NewCommand extends SchematicCommand<NewCommandOptions> {
|
|
13
|
-
readonly allowMissingWorkspace = true;
|
|
14
|
-
schematicName: string;
|
|
15
|
-
initialize(options: NewCommandOptions): Promise<void>;
|
|
16
|
-
run(options: NewCommandOptions & OtherOptions): Promise<number | void>;
|
|
17
|
-
}
|
|
18
|
-
export {};
|
|
@@ -1,38 +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.NewCommand = void 0;
|
|
11
|
-
const schematic_command_1 = require("../../../models/schematic-command");
|
|
12
|
-
const version_1 = require("../../utilities/version");
|
|
13
|
-
class NewCommand extends schematic_command_1.SchematicCommand {
|
|
14
|
-
constructor() {
|
|
15
|
-
super(...arguments);
|
|
16
|
-
this.allowMissingWorkspace = true;
|
|
17
|
-
this.schematicName = 'ng-new';
|
|
18
|
-
}
|
|
19
|
-
async initialize(options) {
|
|
20
|
-
this.collectionName = options.collection || (await this.getDefaultSchematicCollection());
|
|
21
|
-
return super.initialize(options);
|
|
22
|
-
}
|
|
23
|
-
async run(options) {
|
|
24
|
-
// Register the version of the CLI in the registry.
|
|
25
|
-
const version = version_1.VERSION.full;
|
|
26
|
-
this._workflow.registry.addSmartDefaultProvider('ng-cli-version', () => version);
|
|
27
|
-
const { dryRun, force, interactive, defaults, collection, ...schematicOptions } = options;
|
|
28
|
-
return this.runSchematic({
|
|
29
|
-
collectionName: this.collectionName,
|
|
30
|
-
schematicName: this.schematicName,
|
|
31
|
-
schematicOptions,
|
|
32
|
-
debug: false,
|
|
33
|
-
dryRun,
|
|
34
|
-
force,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
exports.NewCommand = NewCommand;
|
|
@@ -1,40 +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 { Command } from '../../../models/command';
|
|
9
|
-
import { Options } from '../../command-builder/command-module';
|
|
10
|
-
import { UpdateCommandArgs } from './cli';
|
|
11
|
-
declare type UpdateCommandOptions = Options<UpdateCommandArgs>;
|
|
12
|
-
export declare class UpdateCommand extends Command<UpdateCommandOptions> {
|
|
13
|
-
readonly allowMissingWorkspace = true;
|
|
14
|
-
private workflow;
|
|
15
|
-
private packageManager;
|
|
16
|
-
initialize(options: UpdateCommandOptions): Promise<void>;
|
|
17
|
-
private executeSchematic;
|
|
18
|
-
/**
|
|
19
|
-
* @return Whether or not the migration was performed successfully.
|
|
20
|
-
*/
|
|
21
|
-
private executeMigration;
|
|
22
|
-
/**
|
|
23
|
-
* @return Whether or not the migrations were performed successfully.
|
|
24
|
-
*/
|
|
25
|
-
private executeMigrations;
|
|
26
|
-
private executePackageMigrations;
|
|
27
|
-
run(options: UpdateCommandOptions): Promise<number>;
|
|
28
|
-
/**
|
|
29
|
-
* @return Whether or not the commit was successful.
|
|
30
|
-
*/
|
|
31
|
-
private commit;
|
|
32
|
-
private checkCleanGit;
|
|
33
|
-
/**
|
|
34
|
-
* Checks if the current installed CLI version is older or newer than a compatible version.
|
|
35
|
-
* @returns the version to install or null when there is no update to install.
|
|
36
|
-
*/
|
|
37
|
-
private checkCLIVersion;
|
|
38
|
-
private getCLIUpdateRunnerVersion;
|
|
39
|
-
}
|
|
40
|
-
export {};
|