mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-19 04:26:01 +08:00
fix(@angular/cli): warn if targets
is present when using a schematic
This commit is contained in:
parent
57c049e507
commit
9e7391c685
@ -7,6 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
import {
|
import {
|
||||||
experimental,
|
experimental,
|
||||||
|
json,
|
||||||
logging,
|
logging,
|
||||||
normalize,
|
normalize,
|
||||||
schema,
|
schema,
|
||||||
@ -42,6 +43,7 @@ import {
|
|||||||
getProjectByCwd,
|
getProjectByCwd,
|
||||||
getSchematicDefaults,
|
getSchematicDefaults,
|
||||||
getWorkspace,
|
getWorkspace,
|
||||||
|
getWorkspaceRaw,
|
||||||
} from '../utilities/config';
|
} from '../utilities/config';
|
||||||
import { parseJsonSchemaToOptions } from '../utilities/json-schema';
|
import { parseJsonSchemaToOptions } from '../utilities/json-schema';
|
||||||
import { BaseCommandOptions, Command } from './command';
|
import { BaseCommandOptions, Command } from './command';
|
||||||
@ -357,6 +359,43 @@ export abstract class SchematicCommand<
|
|||||||
collectionName = schematic.collection.description.name;
|
collectionName = schematic.collection.description.name;
|
||||||
schematicName = schematic.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".
|
// Set the options of format "path".
|
||||||
let o: Option[] | null = null;
|
let o: Option[] | null = null;
|
||||||
let args: Arguments;
|
let args: Arguments;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user