|
10 | 10 | import {
|
11 | 11 | JsonObject,
|
12 | 12 | experimental,
|
| 13 | + json, |
13 | 14 | logging,
|
14 | 15 | normalize,
|
15 | 16 | schema,
|
@@ -43,6 +44,7 @@ import {
|
43 | 44 | getDefaultSchematicCollection,
|
44 | 45 | getPackageManager,
|
45 | 46 | getSchematicDefaults,
|
| 47 | + getWorkspaceRaw, |
46 | 48 | } from '../utilities/config';
|
47 | 49 | import { ArgumentStrategy, Command, CommandContext, Option } from './command';
|
48 | 50 |
|
@@ -202,6 +204,43 @@ export abstract class SchematicCommand extends Command {
|
202 | 204 | const defaultOptions = this.readDefaults(collectionName, schematicName, schematicOptions);
|
203 | 205 | schematicOptions = { ...schematicOptions, ...defaultOptions };
|
204 | 206 |
|
| 207 | + // TODO: Remove warning check when 'targets' is default |
| 208 | + if (collectionName !== '@schematics/angular') { |
| 209 | + const [ast, configPath] = getWorkspaceRaw('local'); |
| 210 | + if (ast) { |
| 211 | + const projectsKeyValue = ast.properties.find(p => p.key.value === 'projects'); |
| 212 | + if (!projectsKeyValue || projectsKeyValue.value.kind !== 'object') { |
| 213 | + return; |
| 214 | + } |
| 215 | + |
| 216 | + const positions: json.Position[] = []; |
| 217 | + for (const projectKeyValue of projectsKeyValue.value.properties) { |
| 218 | + const projectNode = projectKeyValue.value; |
| 219 | + if (projectNode.kind !== 'object') { |
| 220 | + continue; |
| 221 | + } |
| 222 | + const targetsKeyValue = projectNode.properties.find(p => p.key.value === 'targets'); |
| 223 | + if (targetsKeyValue) { |
| 224 | + positions.push(targetsKeyValue.start); |
| 225 | + } |
| 226 | + } |
| 227 | + |
| 228 | + if (positions.length > 0) { |
| 229 | + const warning = tags.oneLine` |
| 230 | + WARNING: This command may not execute successfully. |
| 231 | + The package/collection may not support the 'targets' field within '${configPath}'. |
| 232 | + This can be corrected by renaming the following 'targets' fields to 'architect': |
| 233 | + `; |
| 234 | + |
| 235 | + const locations = positions |
| 236 | + .map((p, i) => `${i + 1}) Line: ${p.line + 1}; Column: ${p.character + 1}`) |
| 237 | + .join('\n'); |
| 238 | + |
| 239 | + this.logger.warn(warning + '\n' + locations + '\n'); |
| 240 | + } |
| 241 | + } |
| 242 | + } |
| 243 | + |
205 | 244 | // Remove all of the original arguments which have already been parsed
|
206 | 245 |
|
207 | 246 | const argumentCount = this._originalOptions
|
|
0 commit comments