@angular/cli 14.0.0-next.4 → 14.0.0-next.7

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.
Files changed (231) hide show
  1. package/bin/ng.js +3 -5
  2. package/lib/cli/index.d.ts +1 -2
  3. package/lib/cli/index.js +16 -45
  4. package/lib/config/schema.json +30 -15
  5. package/lib/config/workspace-schema.d.ts +6 -1
  6. package/lib/init.js +10 -9
  7. package/package.json +18 -20
  8. package/{models → src/analytics}/analytics-collector.d.ts +0 -0
  9. package/{models → src/analytics}/analytics-collector.js +8 -2
  10. package/src/analytics/analytics.d.ts +47 -0
  11. package/src/analytics/analytics.js +304 -0
  12. package/src/command-builder/architect-base-command-module.d.ts +23 -0
  13. package/src/command-builder/architect-base-command-module.js +103 -0
  14. package/src/command-builder/architect-command-module.d.ts +22 -0
  15. package/src/command-builder/architect-command-module.js +108 -0
  16. package/src/command-builder/command-module.d.ts +89 -0
  17. package/src/command-builder/command-module.js +191 -0
  18. package/{utilities/package-json.js → src/command-builder/command-runner.d.ts} +2 -2
  19. package/src/command-builder/command-runner.js +152 -0
  20. package/src/command-builder/schematics-command-module.d.ts +46 -0
  21. package/src/command-builder/schematics-command-module.js +335 -0
  22. package/src/command-builder/utilities/command.d.ts +13 -0
  23. package/src/command-builder/utilities/command.js +27 -0
  24. package/src/command-builder/utilities/json-help.d.ts +36 -0
  25. package/src/command-builder/utilities/json-help.js +94 -0
  26. package/src/command-builder/utilities/json-schema.d.ts +40 -0
  27. package/{utilities → src/command-builder/utilities}/json-schema.js +20 -121
  28. package/{models → src/command-builder/utilities}/schematic-engine-host.d.ts +0 -0
  29. package/{models → src/command-builder/utilities}/schematic-engine-host.js +0 -0
  30. package/src/command-builder/utilities/schematic-workflow.d.ts +14 -0
  31. package/src/command-builder/utilities/schematic-workflow.js +68 -0
  32. package/src/commands/add/cli.d.ts +33 -0
  33. package/{commands/add-impl.js → src/commands/add/cli.js} +108 -80
  34. package/src/commands/add/long-description.md +7 -0
  35. package/src/commands/analytics/cli.d.ts +16 -0
  36. package/src/commands/analytics/cli.js +35 -0
  37. package/src/commands/analytics/info/cli.d.ts +16 -0
  38. package/src/commands/analytics/info/cli.js +26 -0
  39. package/src/commands/analytics/settings/cli.d.ts +35 -0
  40. package/src/commands/analytics/settings/cli.js +61 -0
  41. package/src/commands/build/cli.d.ts +16 -0
  42. package/src/commands/build/cli.js +23 -0
  43. package/{commands/build-long.md → src/commands/build/long-description.md} +0 -0
  44. package/src/commands/cache/clean/cli.d.ts +17 -0
  45. package/src/commands/cache/clean/cli.js +32 -0
  46. package/src/commands/cache/cli.d.ts +17 -0
  47. package/src/commands/cache/cli.js +38 -0
  48. package/src/commands/cache/info/cli.d.ts +20 -0
  49. package/src/commands/cache/info/cli.js +82 -0
  50. package/src/commands/cache/long-description.md +53 -0
  51. package/src/commands/cache/settings/cli.d.ts +27 -0
  52. package/src/commands/cache/settings/cli.js +42 -0
  53. package/src/commands/cache/utilities.d.ts +11 -0
  54. package/src/commands/cache/utilities.js +50 -0
  55. package/src/commands/config/cli.d.ts +24 -0
  56. package/{commands/config-impl.js → src/commands/config/cli.js} +102 -89
  57. package/{commands/config-long.md → src/commands/config/long-description.md} +2 -2
  58. package/src/commands/deploy/cli.d.ts +16 -0
  59. package/src/commands/deploy/cli.js +35 -0
  60. package/{commands/deploy-long.md → src/commands/deploy/long-description.md} +0 -0
  61. package/src/commands/doc/cli.d.ts +23 -0
  62. package/{commands/doc-impl.js → src/commands/doc/cli.js} +41 -12
  63. package/src/commands/e2e/cli.d.ts +17 -0
  64. package/src/commands/e2e/cli.js +34 -0
  65. package/src/commands/extract-i18n/cli.d.ts +15 -0
  66. package/src/commands/extract-i18n/cli.js +20 -0
  67. package/src/commands/generate/cli.d.ts +39 -0
  68. package/src/commands/generate/cli.js +145 -0
  69. package/src/commands/lint/cli.d.ts +16 -0
  70. package/src/commands/lint/cli.js +31 -0
  71. package/{commands/lint-long.md → src/commands/lint/long-description.md} +0 -0
  72. package/src/commands/make-this-awesome/cli.d.ts +17 -0
  73. package/{commands/easter-egg-impl.js → src/commands/make-this-awesome/cli.js} +17 -10
  74. package/src/commands/new/cli.d.ts +27 -0
  75. package/src/commands/new/cli.js +77 -0
  76. package/src/commands/run/cli.d.ts +23 -0
  77. package/src/commands/run/cli.js +59 -0
  78. package/{commands/run-long.md → src/commands/run/long-description.md} +0 -0
  79. package/src/commands/serve/cli.d.ts +16 -0
  80. package/src/commands/serve/cli.js +21 -0
  81. package/src/commands/test/cli.d.ts +16 -0
  82. package/src/commands/test/cli.js +23 -0
  83. package/{commands/test-long.md → src/commands/test/long-description.md} +0 -0
  84. package/{commands/update-impl.d.ts → src/commands/update/cli.d.ts} +26 -9
  85. package/{commands/update-impl.js → src/commands/update/cli.js} +362 -316
  86. package/{commands/update-long.md → src/commands/update/long-description.md} +0 -0
  87. package/src/commands/update/schematic/index.js +33 -20
  88. package/src/commands/version/cli.d.ts +18 -0
  89. package/{commands/version-impl.js → src/commands/version/cli.js} +56 -74
  90. package/src/typings-bazel.d.ts +14 -0
  91. package/src/typings.d.ts +1 -14
  92. package/{utilities → src/utilities}/color.d.ts +0 -0
  93. package/{utilities → src/utilities}/color.js +5 -1
  94. package/{utilities → src/utilities}/config.d.ts +2 -2
  95. package/{utilities → src/utilities}/config.js +24 -16
  96. package/src/utilities/environment-options.d.ts +12 -0
  97. package/src/utilities/environment-options.js +24 -0
  98. package/{utilities → src/utilities}/find-up.d.ts +0 -0
  99. package/{utilities → src/utilities}/find-up.js +5 -1
  100. package/{utilities → src/utilities}/json-file.d.ts +0 -0
  101. package/{utilities → src/utilities}/json-file.js +0 -0
  102. package/{utilities → src/utilities}/log-file.d.ts +0 -0
  103. package/{utilities → src/utilities}/log-file.js +0 -0
  104. package/src/utilities/package-manager.d.ts +41 -0
  105. package/src/utilities/package-manager.js +276 -0
  106. package/{utilities → src/utilities}/package-metadata.d.ts +15 -37
  107. package/{utilities → src/utilities}/package-metadata.js +15 -27
  108. package/{utilities → src/utilities}/package-tree.d.ts +2 -2
  109. package/{utilities → src/utilities}/package-tree.js +5 -1
  110. package/{utilities → src/utilities}/project.d.ts +0 -0
  111. package/{utilities → src/utilities}/project.js +5 -1
  112. package/{utilities → src/utilities}/prompt.d.ts +0 -0
  113. package/{utilities → src/utilities}/prompt.js +7 -3
  114. package/{utilities → src/utilities}/spinner.d.ts +0 -0
  115. package/{utilities → src/utilities}/spinner.js +0 -0
  116. package/{utilities → src/utilities}/tty.d.ts +0 -0
  117. package/{utilities → src/utilities}/tty.js +0 -0
  118. package/{models → src/utilities}/version.d.ts +2 -1
  119. package/{models → src/utilities}/version.js +6 -6
  120. package/bin/postinstall/analytics-prompt.js +0 -27
  121. package/bin/postinstall/script.js +0 -16
  122. package/commands/add-impl.d.ts +0 -21
  123. package/commands/add.d.ts +0 -42
  124. package/commands/add.js +0 -10
  125. package/commands/add.json +0 -54
  126. package/commands/add.md +0 -10
  127. package/commands/analytics-impl.d.ts +0 -13
  128. package/commands/analytics-impl.js +0 -80
  129. package/commands/analytics-long.md +0 -8
  130. package/commands/analytics.d.ts +0 -46
  131. package/commands/analytics.js +0 -31
  132. package/commands/analytics.json +0 -37
  133. package/commands/build-impl.d.ts +0 -14
  134. package/commands/build-impl.js +0 -21
  135. package/commands/build.d.ts +0 -30
  136. package/commands/build.js +0 -10
  137. package/commands/build.json +0 -16
  138. package/commands/config-impl.d.ts +0 -15
  139. package/commands/config.d.ts +0 -34
  140. package/commands/config.js +0 -10
  141. package/commands/config.json +0 -43
  142. package/commands/definitions.json +0 -66
  143. package/commands/deploy-impl.d.ts +0 -15
  144. package/commands/deploy-impl.js +0 -36
  145. package/commands/deploy.d.ts +0 -30
  146. package/commands/deploy.js +0 -10
  147. package/commands/deploy.json +0 -34
  148. package/commands/doc-impl.d.ts +0 -13
  149. package/commands/doc.d.ts +0 -39
  150. package/commands/doc.js +0 -14
  151. package/commands/doc.json +0 -46
  152. package/commands/e2e-impl.d.ts +0 -16
  153. package/commands/e2e-impl.js +0 -36
  154. package/commands/e2e-long.md +0 -4
  155. package/commands/e2e.d.ts +0 -29
  156. package/commands/e2e.js +0 -10
  157. package/commands/e2e.json +0 -17
  158. package/commands/easter-egg-impl.d.ts +0 -12
  159. package/commands/easter-egg.d.ts +0 -14
  160. package/commands/easter-egg.js +0 -10
  161. package/commands/easter-egg.json +0 -12
  162. package/commands/extract-i18n-impl.d.ts +0 -14
  163. package/commands/extract-i18n-impl.js +0 -21
  164. package/commands/extract-i18n.d.ts +0 -29
  165. package/commands/extract-i18n.js +0 -10
  166. package/commands/extract-i18n.json +0 -15
  167. package/commands/generate-impl.d.ts +0 -18
  168. package/commands/generate-impl.js +0 -89
  169. package/commands/generate.d.ts +0 -37
  170. package/commands/generate.js +0 -10
  171. package/commands/generate.json +0 -31
  172. package/commands/help-impl.d.ts +0 -12
  173. package/commands/help-impl.js +0 -26
  174. package/commands/help-long.md +0 -7
  175. package/commands/help.d.ts +0 -17
  176. package/commands/help.js +0 -10
  177. package/commands/help.json +0 -13
  178. package/commands/lint-impl.d.ts +0 -16
  179. package/commands/lint-impl.js +0 -69
  180. package/commands/lint.d.ts +0 -29
  181. package/commands/lint.js +0 -10
  182. package/commands/lint.json +0 -36
  183. package/commands/new-impl.d.ts +0 -16
  184. package/commands/new-impl.js +0 -37
  185. package/commands/new.d.ts +0 -41
  186. package/commands/new.js +0 -10
  187. package/commands/new.json +0 -34
  188. package/commands/new.md +0 -16
  189. package/commands/run-impl.d.ts +0 -13
  190. package/commands/run-impl.js +0 -22
  191. package/commands/run.d.ts +0 -30
  192. package/commands/run.js +0 -10
  193. package/commands/run.json +0 -36
  194. package/commands/serve-impl.d.ts +0 -15
  195. package/commands/serve-impl.js +0 -24
  196. package/commands/serve.d.ts +0 -29
  197. package/commands/serve.js +0 -10
  198. package/commands/serve.json +0 -17
  199. package/commands/test-impl.d.ts +0 -15
  200. package/commands/test-impl.js +0 -22
  201. package/commands/test.d.ts +0 -29
  202. package/commands/test.js +0 -10
  203. package/commands/test.json +0 -17
  204. package/commands/update.d.ts +0 -61
  205. package/commands/update.js +0 -10
  206. package/commands/update.json +0 -78
  207. package/commands/version-impl.d.ts +0 -17
  208. package/commands/version.d.ts +0 -17
  209. package/commands/version.js +0 -10
  210. package/commands/version.json +0 -13
  211. package/commands.json +0 -20
  212. package/models/analytics.d.ts +0 -58
  213. package/models/analytics.js +0 -358
  214. package/models/architect-command.d.ts +0 -35
  215. package/models/architect-command.js +0 -364
  216. package/models/command-runner.d.ts +0 -24
  217. package/models/command-runner.js +0 -241
  218. package/models/command.d.ts +0 -34
  219. package/models/command.js +0 -143
  220. package/models/interface.d.ts +0 -196
  221. package/models/interface.js +0 -31
  222. package/models/parser.d.ts +0 -39
  223. package/models/parser.js +0 -349
  224. package/models/schematic-command.d.ts +0 -55
  225. package/models/schematic-command.js +0 -485
  226. package/utilities/install-package.d.ts +0 -16
  227. package/utilities/install-package.js +0 -193
  228. package/utilities/json-schema.d.ts +0 -17
  229. package/utilities/package-json.d.ts +0 -249
  230. package/utilities/package-manager.d.ts +0 -13
  231. package/utilities/package-manager.js +0 -106
@@ -7,102 +7,9 @@
7
7
  * found in the LICENSE file at https://angular.io/license
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.parseJsonSchemaToOptions = exports.parseJsonSchemaToCommandDescription = exports.parseJsonSchemaToSubCommandDescription = exports.CommandJsonPathException = void 0;
10
+ exports.parseJsonSchemaToOptions = void 0;
11
11
  const core_1 = require("@angular-devkit/core");
12
- const tools_1 = require("@angular-devkit/schematics/tools");
13
- const fs_1 = require("fs");
14
- const path_1 = require("path");
15
- const interface_1 = require("../models/interface");
16
- class CommandJsonPathException extends core_1.BaseException {
17
- constructor(path, name) {
18
- super(`File ${path} was not found while constructing the subcommand ${name}.`);
19
- this.path = path;
20
- this.name = name;
21
- }
22
- }
23
- exports.CommandJsonPathException = CommandJsonPathException;
24
- function _getEnumFromValue(value, enumeration, defaultValue) {
25
- if (typeof value !== 'string') {
26
- return defaultValue;
27
- }
28
- if (Object.values(enumeration).includes(value)) {
29
- return value;
30
- }
31
- return defaultValue;
32
- }
33
- async function parseJsonSchemaToSubCommandDescription(name, jsonPath, registry, schema) {
34
- const options = await parseJsonSchemaToOptions(registry, schema);
35
- const aliases = [];
36
- if (core_1.json.isJsonArray(schema.$aliases)) {
37
- schema.$aliases.forEach((value) => {
38
- if (typeof value == 'string') {
39
- aliases.push(value);
40
- }
41
- });
42
- }
43
- if (core_1.json.isJsonArray(schema.aliases)) {
44
- schema.aliases.forEach((value) => {
45
- if (typeof value == 'string') {
46
- aliases.push(value);
47
- }
48
- });
49
- }
50
- if (typeof schema.alias == 'string') {
51
- aliases.push(schema.alias);
52
- }
53
- let longDescription = '';
54
- if (typeof schema.$longDescription == 'string' && schema.$longDescription) {
55
- const ldPath = (0, path_1.resolve)((0, path_1.dirname)(jsonPath), schema.$longDescription);
56
- try {
57
- longDescription = (0, fs_1.readFileSync)(ldPath, 'utf-8');
58
- }
59
- catch (e) {
60
- throw new CommandJsonPathException(ldPath, name);
61
- }
62
- }
63
- let usageNotes = '';
64
- if (typeof schema.$usageNotes == 'string' && schema.$usageNotes) {
65
- const unPath = (0, path_1.resolve)((0, path_1.dirname)(jsonPath), schema.$usageNotes);
66
- try {
67
- usageNotes = (0, fs_1.readFileSync)(unPath, 'utf-8');
68
- }
69
- catch (e) {
70
- throw new CommandJsonPathException(unPath, name);
71
- }
72
- }
73
- const description = '' + (schema.description === undefined ? '' : schema.description);
74
- return {
75
- name,
76
- description,
77
- ...(longDescription ? { longDescription } : {}),
78
- ...(usageNotes ? { usageNotes } : {}),
79
- options,
80
- aliases,
81
- };
82
- }
83
- exports.parseJsonSchemaToSubCommandDescription = parseJsonSchemaToSubCommandDescription;
84
- async function parseJsonSchemaToCommandDescription(name, jsonPath, registry, schema) {
85
- const subcommand = await parseJsonSchemaToSubCommandDescription(name, jsonPath, registry, schema);
86
- // Before doing any work, let's validate the implementation.
87
- if (typeof schema.$impl != 'string') {
88
- throw new Error(`Command ${name} has an invalid implementation.`);
89
- }
90
- const ref = new tools_1.ExportStringRef(schema.$impl, (0, path_1.dirname)(jsonPath));
91
- const impl = ref.ref;
92
- if (impl === undefined || typeof impl !== 'function') {
93
- throw new Error(`Command ${name} has an invalid implementation.`);
94
- }
95
- const scope = _getEnumFromValue(schema.$scope, interface_1.CommandScope, interface_1.CommandScope.Default);
96
- const hidden = !!schema.$hidden;
97
- return {
98
- ...subcommand,
99
- scope,
100
- hidden,
101
- impl,
102
- };
103
- }
104
- exports.parseJsonSchemaToCommandDescription = parseJsonSchemaToCommandDescription;
105
- async function parseJsonSchemaToOptions(registry, schema) {
12
+ async function parseJsonSchemaToOptions(registry, schema, interactive = true) {
106
13
  const options = [];
107
14
  function visitor(current, pointer, parentSchema) {
108
15
  if (!parentSchema) {
@@ -131,8 +38,7 @@ async function parseJsonSchemaToOptions(registry, schema) {
131
38
  throw new Error('Cannot find type of schema.');
132
39
  }
133
40
  // We only support number, string or boolean (or array of those), so remove everything else.
134
- const types = [...typeSet]
135
- .filter((x) => {
41
+ const types = [...typeSet].filter((x) => {
136
42
  switch (x) {
137
43
  case 'boolean':
138
44
  case 'number':
@@ -149,8 +55,7 @@ async function parseJsonSchemaToOptions(registry, schema) {
149
55
  default:
150
56
  return false;
151
57
  }
152
- })
153
- .map((x) => _getEnumFromValue(x, interface_1.OptionType, interface_1.OptionType.String));
58
+ });
154
59
  if (types.length == 0) {
155
60
  // This means it's not usable on the command line. e.g. an Object.
156
61
  return;
@@ -190,10 +95,11 @@ async function parseJsonSchemaToOptions(registry, schema) {
190
95
  const $default = current.$default;
191
96
  const $defaultIndex = core_1.json.isJsonObject($default) && $default['$source'] == 'argv' ? $default['index'] : undefined;
192
97
  const positional = typeof $defaultIndex == 'number' ? $defaultIndex : undefined;
193
- const required = core_1.json.isJsonArray(current.required)
194
- ? current.required.indexOf(name) != -1
195
- : false;
196
- const aliases = core_1.json.isJsonArray(current.aliases)
98
+ let required = core_1.json.isJsonArray(schema.required) ? schema.required.includes(name) : false;
99
+ if (required && interactive && current['x-prompt']) {
100
+ required = false;
101
+ }
102
+ const alias = core_1.json.isJsonArray(current.aliases)
197
103
  ? [...current.aliases].map((x) => '' + x)
198
104
  : current.alias
199
105
  ? ['' + current.alias]
@@ -209,37 +115,30 @@ async function parseJsonSchemaToOptions(registry, schema) {
209
115
  const option = {
210
116
  name,
211
117
  description: '' + (current.description === undefined ? '' : current.description),
212
- ...(types.length == 1 ? { type } : { type, types }),
213
- ...(defaultValue !== undefined ? { default: defaultValue } : {}),
214
- ...(enumValues && enumValues.length > 0 ? { enum: enumValues } : {}),
118
+ type,
119
+ default: defaultValue,
120
+ choices: enumValues.length ? enumValues : undefined,
215
121
  required,
216
- aliases,
217
- ...(format !== undefined ? { format } : {}),
122
+ alias,
123
+ format,
218
124
  hidden,
219
- ...(userAnalytics ? { userAnalytics } : {}),
220
- ...(deprecated !== undefined ? { deprecated } : {}),
221
- ...(positional !== undefined ? { positional } : {}),
125
+ userAnalytics,
126
+ deprecated,
127
+ positional,
222
128
  };
223
129
  options.push(option);
224
130
  }
225
131
  const flattenedSchema = await registry.flatten(schema).toPromise();
226
132
  core_1.json.schema.visitJsonSchema(flattenedSchema, visitor);
227
- // Sort by positional.
133
+ // Sort by positional and name.
228
134
  return options.sort((a, b) => {
229
135
  if (a.positional) {
230
- if (b.positional) {
231
- return a.positional - b.positional;
232
- }
233
- else {
234
- return 1;
235
- }
136
+ return b.positional ? a.positional - b.positional : a.name.localeCompare(b.name);
236
137
  }
237
138
  else if (b.positional) {
238
139
  return -1;
239
140
  }
240
- else {
241
- return 0;
242
- }
141
+ return a.name.localeCompare(b.name);
243
142
  });
244
143
  }
245
144
  exports.parseJsonSchemaToOptions = parseJsonSchemaToOptions;
@@ -0,0 +1,14 @@
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 { NodeWorkflow } from '@angular-devkit/schematics/tools';
10
+ export declare function subscribeToWorkflow(workflow: NodeWorkflow, logger: logging.LoggerApi): {
11
+ files: Set<string>;
12
+ error: boolean;
13
+ unsubscribe: () => void;
14
+ };
@@ -0,0 +1,68 @@
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.subscribeToWorkflow = void 0;
11
+ const core_1 = require("@angular-devkit/core");
12
+ const color_1 = require("../../utilities/color");
13
+ function subscribeToWorkflow(workflow, logger) {
14
+ const files = new Set();
15
+ let error = false;
16
+ let logs = [];
17
+ const reporterSubscription = workflow.reporter.subscribe((event) => {
18
+ // Strip leading slash to prevent confusion.
19
+ const eventPath = event.path.charAt(0) === '/' ? event.path.substring(1) : event.path;
20
+ switch (event.kind) {
21
+ case 'error':
22
+ error = true;
23
+ const desc = event.description == 'alreadyExist' ? 'already exists' : 'does not exist';
24
+ logger.error(`ERROR! ${eventPath} ${desc}.`);
25
+ break;
26
+ case 'update':
27
+ logs.push(core_1.tags.oneLine `
28
+ ${color_1.colors.cyan('UPDATE')} ${eventPath} (${event.content.length} bytes)
29
+ `);
30
+ files.add(eventPath);
31
+ break;
32
+ case 'create':
33
+ logs.push(core_1.tags.oneLine `
34
+ ${color_1.colors.green('CREATE')} ${eventPath} (${event.content.length} bytes)
35
+ `);
36
+ files.add(eventPath);
37
+ break;
38
+ case 'delete':
39
+ logs.push(`${color_1.colors.yellow('DELETE')} ${eventPath}`);
40
+ files.add(eventPath);
41
+ break;
42
+ case 'rename':
43
+ const eventToPath = event.to.charAt(0) === '/' ? event.to.substring(1) : event.to;
44
+ logs.push(`${color_1.colors.blue('RENAME')} ${eventPath} => ${eventToPath}`);
45
+ files.add(eventPath);
46
+ break;
47
+ }
48
+ });
49
+ const lifecycleSubscription = workflow.lifeCycle.subscribe((event) => {
50
+ if (event.kind == 'end' || event.kind == 'post-tasks-start') {
51
+ if (!error) {
52
+ // Output the logging queue, no error happened.
53
+ logs.forEach((log) => logger.info(log));
54
+ }
55
+ logs = [];
56
+ error = false;
57
+ }
58
+ });
59
+ return {
60
+ files,
61
+ error,
62
+ unsubscribe: () => {
63
+ reporterSubscription.unsubscribe();
64
+ lifecycleSubscription.unsubscribe();
65
+ },
66
+ };
67
+ }
68
+ exports.subscribeToWorkflow = subscribeToWorkflow;
@@ -0,0 +1,33 @@
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 { Argv } from 'yargs';
9
+ import { CommandModuleImplementation, Options, OtherOptions } from '../../command-builder/command-module';
10
+ import { SchematicsCommandArgs, SchematicsCommandModule } from '../../command-builder/schematics-command-module';
11
+ interface AddCommandArgs extends SchematicsCommandArgs {
12
+ collection: string;
13
+ verbose?: boolean;
14
+ registry?: string;
15
+ 'skip-confirmation'?: boolean;
16
+ }
17
+ export declare class AddCommandModule extends SchematicsCommandModule implements CommandModuleImplementation<AddCommandArgs> {
18
+ command: string;
19
+ describe: string;
20
+ longDescriptionPath: string;
21
+ protected allowPrivateSchematics: boolean;
22
+ private readonly schematicName;
23
+ builder(argv: Argv): Promise<Argv<AddCommandArgs>>;
24
+ run(options: Options<AddCommandArgs> & OtherOptions): Promise<number | void>;
25
+ private isProjectVersionValid;
26
+ reportAnalytics(options: OtherOptions, paths: string[]): Promise<void>;
27
+ private getCollectionName;
28
+ private isPackageInstalled;
29
+ private executeSchematic;
30
+ private findProjectVersion;
31
+ private hasMismatchedPeer;
32
+ }
33
+ export {};
@@ -10,22 +10,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
10
10
  return (mod && mod.__esModule) ? mod : { "default": mod };
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.AddCommand = void 0;
13
+ exports.AddCommandModule = void 0;
14
14
  const core_1 = require("@angular-devkit/core");
15
15
  const tools_1 = require("@angular-devkit/schematics/tools");
16
16
  const npm_package_arg_1 = __importDefault(require("npm-package-arg"));
17
17
  const path_1 = require("path");
18
18
  const semver_1 = require("semver");
19
- const workspace_schema_1 = require("../lib/config/workspace-schema");
20
- const analytics_1 = require("../models/analytics");
21
- const schematic_command_1 = require("../models/schematic-command");
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");
19
+ const workspace_schema_1 = require("../../../lib/config/workspace-schema");
20
+ const analytics_1 = require("../../analytics/analytics");
21
+ const schematics_command_module_1 = require("../../command-builder/schematics-command-module");
22
+ const color_1 = require("../../utilities/color");
23
+ const package_metadata_1 = require("../../utilities/package-metadata");
24
+ const prompt_1 = require("../../utilities/prompt");
25
+ const spinner_1 = require("../../utilities/spinner");
26
+ const tty_1 = require("../../utilities/tty");
29
27
  /**
30
28
  * The set of packages that should have certain versions excluded from consideration
31
29
  * when attempting to find a compatible version for a package.
@@ -35,34 +33,64 @@ const packageVersionExclusions = {
35
33
  // @angular/localize@9.x versions do not have peer dependencies setup
36
34
  '@angular/localize': '9.x',
37
35
  };
38
- class AddCommand extends schematic_command_1.SchematicCommand {
36
+ class AddCommandModule extends schematics_command_module_1.SchematicsCommandModule {
39
37
  constructor() {
40
38
  super(...arguments);
39
+ this.command = 'add <collection>';
40
+ this.describe = 'Adds support for an external library to your project.';
41
+ this.longDescriptionPath = (0, path_1.join)(__dirname, 'long-description.md');
41
42
  this.allowPrivateSchematics = true;
43
+ this.schematicName = 'ng-add';
42
44
  }
43
- async initialize(options) {
44
- if (options.registry) {
45
- return super.initialize({ ...options, packageRegistry: options.registry });
45
+ async builder(argv) {
46
+ const localYargs = (await super.builder(argv))
47
+ .positional('collection', {
48
+ description: 'The package to be added.',
49
+ type: 'string',
50
+ demandOption: true,
51
+ })
52
+ .option('registry', { description: 'The NPM registry to use.', type: 'string' })
53
+ .option('verbose', {
54
+ description: 'Display additional details about internal operations during execution.',
55
+ type: 'boolean',
56
+ default: false,
57
+ })
58
+ .option('skip-confirmation', {
59
+ description: 'Skip asking a confirmation prompt before installing and executing the package. ' +
60
+ 'Ensure package name is correct prior to using this option.',
61
+ type: 'boolean',
62
+ default: false,
63
+ })
64
+ // Prior to downloading we don't know the full schema and therefore we cannot be strict on the options.
65
+ // Possibly in the future update the logic to use the following syntax:
66
+ // `ng add @angular/localize -- --package-options`.
67
+ .strict(false);
68
+ const collectionName = await this.getCollectionName();
69
+ const workflow = await this.getOrCreateWorkflowForBuilder(collectionName);
70
+ try {
71
+ const collection = workflow.engine.createCollection(collectionName);
72
+ const options = await this.getSchematicOptions(collection, this.schematicName, workflow);
73
+ return this.addSchemaOptionsToCommand(localYargs, options);
46
74
  }
47
- else {
48
- return super.initialize(options);
75
+ catch (error) {
76
+ // During `ng add` prior to the downloading of the package
77
+ // we are not able to resolve and create a collection.
78
+ // Or when the the collection value is a path to a tarball.
49
79
  }
80
+ return localYargs;
50
81
  }
51
82
  // eslint-disable-next-line max-lines-per-function
52
83
  async run(options) {
53
84
  var _a;
54
- await (0, package_manager_1.ensureCompatibleNpm)(this.context.root);
55
- if (!options.collection) {
56
- this.logger.fatal(`The "ng add" command requires a name argument to be specified eg. ` +
57
- `${color_1.colors.yellow('ng add [name] ')}. For more details, use "ng help".`);
58
- return 1;
59
- }
85
+ const { logger, packageManager } = this.context;
86
+ const { verbose, registry, collection, skipConfirmation } = options;
87
+ packageManager.ensureCompatibility();
60
88
  let packageIdentifier;
61
89
  try {
62
- packageIdentifier = (0, npm_package_arg_1.default)(options.collection);
90
+ packageIdentifier = (0, npm_package_arg_1.default)(collection);
63
91
  }
64
92
  catch (e) {
65
- this.logger.error(e.message);
93
+ logger.error(e.message);
66
94
  return 1;
67
95
  }
68
96
  if (packageIdentifier.name &&
@@ -71,29 +99,28 @@ class AddCommand extends schematic_command_1.SchematicCommand {
71
99
  const validVersion = await this.isProjectVersionValid(packageIdentifier);
72
100
  if (validVersion) {
73
101
  // Already installed so just run schematic
74
- this.logger.info('Skipping installation: Package already installed');
75
- return this.executeSchematic(packageIdentifier.name, options['--']);
102
+ logger.info('Skipping installation: Package already installed');
103
+ return this.executeSchematic({ ...options, collection: packageIdentifier.name });
76
104
  }
77
105
  }
78
106
  const spinner = new spinner_1.Spinner();
79
107
  spinner.start('Determining package manager...');
80
- const packageManager = await (0, package_manager_1.getPackageManager)(this.context.root);
81
- const usingYarn = packageManager === workspace_schema_1.PackageManager.Yarn;
82
- spinner.info(`Using package manager: ${color_1.colors.grey(packageManager)}`);
108
+ const usingYarn = packageManager.name === workspace_schema_1.PackageManager.Yarn;
109
+ spinner.info(`Using package manager: ${color_1.colors.grey(packageManager.name)}`);
83
110
  if (packageIdentifier.name && packageIdentifier.type === 'tag' && !packageIdentifier.rawSpec) {
84
111
  // only package name provided; search for viable version
85
112
  // plus special cases for packages that did not have peer deps setup
86
113
  spinner.start('Searching for compatible package version...');
87
114
  let packageMetadata;
88
115
  try {
89
- packageMetadata = await (0, package_metadata_1.fetchPackageMetadata)(packageIdentifier.name, this.logger, {
90
- registry: options.registry,
116
+ packageMetadata = await (0, package_metadata_1.fetchPackageMetadata)(packageIdentifier.name, logger, {
117
+ registry,
91
118
  usingYarn,
92
- verbose: options.verbose,
119
+ verbose,
93
120
  });
94
121
  }
95
122
  catch (e) {
96
- spinner.fail('Unable to load package information from registry: ' + e.message);
123
+ spinner.fail(`Unable to load package information from registry: ${e.message}`);
97
124
  return 1;
98
125
  }
99
126
  // Start with the version tagged as `latest` if it exists
@@ -102,16 +129,8 @@ class AddCommand extends schematic_command_1.SchematicCommand {
102
129
  packageIdentifier = npm_package_arg_1.default.resolve(latestManifest.name, latestManifest.version);
103
130
  }
104
131
  // Adjust the version based on name and peer dependencies
105
- if (latestManifest && Object.keys(latestManifest.peerDependencies).length === 0) {
106
- if (latestManifest.name === '@angular/pwa') {
107
- const version = await this.findProjectVersion('@angular/cli');
108
- const semverOptions = { includePrerelease: true };
109
- if (version &&
110
- (((0, semver_1.validRange)(version) && (0, semver_1.intersects)(version, '7', semverOptions)) ||
111
- ((0, semver_1.valid)(version) && (0, semver_1.satisfies)(version, '7', semverOptions)))) {
112
- packageIdentifier = npm_package_arg_1.default.resolve('@angular/pwa', '0.12');
113
- }
114
- }
132
+ if ((latestManifest === null || latestManifest === void 0 ? void 0 : latestManifest.peerDependencies) &&
133
+ Object.keys(latestManifest.peerDependencies).length === 0) {
115
134
  spinner.succeed(`Found compatible package version: ${color_1.colors.grey(packageIdentifier.toString())}.`);
116
135
  }
117
136
  else if (!latestManifest || (await this.hasMismatchedPeer(latestManifest))) {
@@ -132,7 +151,7 @@ class AddCommand extends schematic_command_1.SchematicCommand {
132
151
  }
133
152
  return true;
134
153
  });
135
- versionManifests.sort((a, b) => (0, semver_1.rcompare)(a.version, b.version, true));
154
+ versionManifests.sort((a, b) => (0, semver_1.compare)(a.version, b.version, true));
136
155
  let newIdentifier;
137
156
  for (const versionManifest of versionManifests) {
138
157
  if (!(await this.hasMismatchedPeer(versionManifest))) {
@@ -156,9 +175,9 @@ class AddCommand extends schematic_command_1.SchematicCommand {
156
175
  let savePackage;
157
176
  try {
158
177
  spinner.start('Loading package information from registry...');
159
- const manifest = await (0, package_metadata_1.fetchPackageManifest)(packageIdentifier.toString(), this.logger, {
160
- registry: options.registry,
161
- verbose: options.verbose,
178
+ const manifest = await (0, package_metadata_1.fetchPackageManifest)(packageIdentifier.toString(), logger, {
179
+ registry,
180
+ verbose,
162
181
  usingYarn,
163
182
  });
164
183
  savePackage = (_a = manifest['ng-add']) === null || _a === void 0 ? void 0 : _a.save;
@@ -174,38 +193,38 @@ class AddCommand extends schematic_command_1.SchematicCommand {
174
193
  spinner.fail(`Unable to fetch package information for '${packageIdentifier}': ${e.message}`);
175
194
  return 1;
176
195
  }
177
- if (!options.skipConfirmation) {
196
+ if (!skipConfirmation) {
178
197
  const confirmationResponse = await (0, prompt_1.askConfirmation)(`\nThe package ${color_1.colors.blue(packageIdentifier.raw)} will be installed and executed.\n` +
179
198
  'Would you like to proceed?', true, false);
180
199
  if (!confirmationResponse) {
181
200
  if (!(0, tty_1.isTTY)()) {
182
- this.logger.error('No terminal detected. ' +
201
+ logger.error('No terminal detected. ' +
183
202
  `'--skip-confirmation' can be used to bypass installation confirmation. ` +
184
203
  `Ensure package name is correct prior to '--skip-confirmation' option usage.`);
185
204
  }
186
- this.logger.error('Command aborted.');
205
+ logger.error('Command aborted.');
187
206
  return 1;
188
207
  }
189
208
  }
190
209
  if (savePackage === false) {
191
210
  // Temporary packages are located in a different directory
192
211
  // Hence we need to resolve them using the temp path
193
- const { status, tempNodeModules } = await (0, install_package_1.installTempPackage)(packageIdentifier.raw, packageManager, options.registry ? [`--registry="${options.registry}"`] : undefined);
212
+ const { success, tempNodeModules } = await packageManager.installTemp(packageIdentifier.raw, registry ? [`--registry="${registry}"`] : undefined);
194
213
  const resolvedCollectionPath = require.resolve((0, path_1.join)(collectionName, 'package.json'), {
195
214
  paths: [tempNodeModules],
196
215
  });
197
- if (status !== 0) {
198
- return status;
216
+ if (!success) {
217
+ return 1;
199
218
  }
200
219
  collectionName = (0, path_1.dirname)(resolvedCollectionPath);
201
220
  }
202
221
  else {
203
- const status = await (0, install_package_1.installPackage)(packageIdentifier.raw, packageManager, savePackage, options.registry ? [`--registry="${options.registry}"`] : undefined);
204
- if (status !== 0) {
205
- return status;
222
+ const success = await packageManager.install(packageIdentifier.raw, savePackage, registry ? [`--registry="${registry}"`] : undefined);
223
+ if (!success) {
224
+ return 1;
206
225
  }
207
226
  }
208
- return this.executeSchematic(collectionName, options['--']);
227
+ return this.executeSchematic({ ...options, collection: collectionName });
209
228
  }
210
229
  async isProjectVersionValid(packageIdentifier) {
211
230
  if (!packageIdentifier.name) {
@@ -228,16 +247,18 @@ class AddCommand extends schematic_command_1.SchematicCommand {
228
247
  }
229
248
  return validVersion;
230
249
  }
231
- async reportAnalytics(paths, options, dimensions = [], metrics = []) {
232
- const collection = options.collection;
250
+ async reportAnalytics(options, paths) {
251
+ const collection = await this.getCollectionName();
252
+ const dimensions = [];
233
253
  // Add the collection if it's safe listed.
234
254
  if (collection && (0, analytics_1.isPackageNameSafeForAnalytics)(collection)) {
235
255
  dimensions[core_1.analytics.NgCliAnalyticsDimensions.NgAddCollection] = collection;
236
256
  }
237
- else {
238
- delete dimensions[core_1.analytics.NgCliAnalyticsDimensions.NgAddCollection];
239
- }
240
- return super.reportAnalytics(paths, options, dimensions, metrics);
257
+ return super.reportAnalytics(options, paths, dimensions);
258
+ }
259
+ async getCollectionName() {
260
+ const [, collectionName] = this.context.args.positional;
261
+ return collectionName;
241
262
  }
242
263
  isPackageInstalled(name) {
243
264
  try {
@@ -251,20 +272,25 @@ class AddCommand extends schematic_command_1.SchematicCommand {
251
272
  }
252
273
  return false;
253
274
  }
254
- async executeSchematic(collectionName, options = []) {
255
- const runOptions = {
256
- schematicOptions: options,
257
- collectionName,
258
- schematicName: 'ng-add',
259
- dryRun: false,
260
- force: false,
261
- };
275
+ async executeSchematic(options) {
262
276
  try {
263
- return await this.runSchematic(runOptions);
277
+ const { verbose, skipConfirmation, interactive, force, dryRun, registry, defaults, collection: collectionName, ...schematicOptions } = options;
278
+ return await this.runSchematic({
279
+ schematicOptions,
280
+ schematicName: this.schematicName,
281
+ collectionName,
282
+ executionOptions: {
283
+ interactive,
284
+ force,
285
+ dryRun,
286
+ defaults,
287
+ packageRegistry: registry,
288
+ },
289
+ });
264
290
  }
265
291
  catch (e) {
266
292
  if (e instanceof tools_1.NodePackageDoesNotSupportSchematics) {
267
- this.logger.error(core_1.tags.oneLine `
293
+ this.context.logger.error(core_1.tags.oneLine `
268
294
  The package that you are trying to add does not support schematics. You can try using
269
295
  a different version of the package or contact the package author to add ng-add support.
270
296
  `);
@@ -274,27 +300,29 @@ class AddCommand extends schematic_command_1.SchematicCommand {
274
300
  }
275
301
  }
276
302
  async findProjectVersion(name) {
303
+ var _a, _b;
304
+ const { logger, root } = this.context;
277
305
  let installedPackage;
278
306
  try {
279
307
  installedPackage = require.resolve((0, path_1.join)(name, 'package.json'), {
280
- paths: [this.context.root],
308
+ paths: [root],
281
309
  });
282
310
  }
283
311
  catch { }
284
312
  if (installedPackage) {
285
313
  try {
286
- const installed = await (0, package_metadata_1.fetchPackageManifest)((0, path_1.dirname)(installedPackage), this.logger);
314
+ const installed = await (0, package_metadata_1.fetchPackageManifest)((0, path_1.dirname)(installedPackage), logger);
287
315
  return installed.version;
288
316
  }
289
317
  catch { }
290
318
  }
291
319
  let projectManifest;
292
320
  try {
293
- projectManifest = await (0, package_metadata_1.fetchPackageManifest)(this.context.root, this.logger);
321
+ projectManifest = await (0, package_metadata_1.fetchPackageManifest)(root, logger);
294
322
  }
295
323
  catch { }
296
324
  if (projectManifest) {
297
- const version = projectManifest.dependencies[name] || projectManifest.devDependencies[name];
325
+ const version = ((_a = projectManifest.dependencies) === null || _a === void 0 ? void 0 : _a[name]) || ((_b = projectManifest.devDependencies) === null || _b === void 0 ? void 0 : _b[name]);
298
326
  if (version) {
299
327
  return version;
300
328
  }
@@ -308,7 +336,7 @@ class AddCommand extends schematic_command_1.SchematicCommand {
308
336
  peerIdentifier = npm_package_arg_1.default.resolve(peer, manifest.peerDependencies[peer]);
309
337
  }
310
338
  catch {
311
- this.logger.warn(`Invalid peer dependency ${peer} found in package.`);
339
+ this.context.logger.warn(`Invalid peer dependency ${peer} found in package.`);
312
340
  continue;
313
341
  }
314
342
  if (peerIdentifier.type === 'version' || peerIdentifier.type === 'range') {
@@ -336,4 +364,4 @@ class AddCommand extends schematic_command_1.SchematicCommand {
336
364
  return false;
337
365
  }
338
366
  }
339
- exports.AddCommand = AddCommand;
367
+ exports.AddCommandModule = AddCommandModule;