fix(@angular/cli): warn if targets is present when using a schematic

This commit is contained in:
Charles Lyding 2018-09-11 21:03:37 -04:00 committed by Keen Yee Liau
parent 57c049e507
commit 9e7391c685

View File

@ -7,6 +7,7 @@
*/
import {
experimental,
json,
logging,
normalize,
schema,
@ -42,6 +43,7 @@ import {
getProjectByCwd,
getSchematicDefaults,
getWorkspace,
getWorkspaceRaw,
} from '../utilities/config';
import { parseJsonSchemaToOptions } from '../utilities/json-schema';
import { BaseCommandOptions, Command } from './command';
@ -357,6 +359,43 @@ export abstract class SchematicCommand<
collectionName = schematic.collection.description.name;
schematicName = schematic.description.name;
// TODO: Remove warning check when 'targets' is default
if (collectionName !== '@schematics/angular') {
const [ast, configPath] = getWorkspaceRaw('local');
if (ast) {
const projectsKeyValue = ast.properties.find(p => p.key.value === 'projects');
if (!projectsKeyValue || projectsKeyValue.value.kind !== 'object') {
return;
}
const positions: json.Position[] = [];
for (const projectKeyValue of projectsKeyValue.value.properties) {
const projectNode = projectKeyValue.value;
if (projectNode.kind !== 'object') {
continue;
}
const targetsKeyValue = projectNode.properties.find(p => p.key.value === 'targets');
if (targetsKeyValue) {
positions.push(targetsKeyValue.start);
}
}
if (positions.length > 0) {
const warning = tags.oneLine`
WARNING: This command may not execute successfully.
The package/collection may not support the 'targets' field within '${configPath}'.
This can be corrected by renaming the following 'targets' fields to 'architect':
`;
const locations = positions
.map((p, i) => `${i + 1}) Line: ${p.line + 1}; Column: ${p.character + 1}`)
.join('\n');
this.logger.warn(warning + '\n' + locations + '\n');
}
}
}
// Set the options of format "path".
let o: Option[] | null = null;
let args: Arguments;