Skip to content

Commit 3071608

Browse files
committed
feat(@schematics/angular): use targets property on new projects
1 parent dcdb937 commit 3071608

File tree

7 files changed

+45
-45
lines changed

7 files changed

+45
-45
lines changed

packages/schematics/angular/application/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function addAppToWorkspaceFile(options: ApplicationOptions, workspace: Workspace
136136
projectType: 'application',
137137
prefix: options.prefix || 'app',
138138
schematics,
139-
architect: {
139+
targets: {
140140
build: {
141141
builder: '@angular-devkit/build-angular:browser',
142142
options: {

packages/schematics/angular/application/index_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,13 @@ describe('Application Schematic', () => {
208208
const config = JSON.parse(tree.readContent('/angular.json'));
209209
const prj = config.projects.foo;
210210
expect(prj.root).toEqual('');
211-
const buildOpt = prj.architect.build.options;
211+
const buildOpt = prj.targets.build.options;
212212
expect(buildOpt.index).toEqual('src/index.html');
213213
expect(buildOpt.main).toEqual('src/main.ts');
214214
expect(buildOpt.polyfills).toEqual('src/polyfills.ts');
215215
expect(buildOpt.tsConfig).toEqual('src/tsconfig.app.json');
216216

217-
const testOpt = prj.architect.test.options;
217+
const testOpt = prj.targets.test.options;
218218
expect(testOpt.main).toEqual('src/test.ts');
219219
expect(testOpt.tsConfig).toEqual('src/tsconfig.spec.json');
220220
expect(testOpt.karmaConfig).toEqual('src/karma.conf.js');

packages/schematics/angular/e2e/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function addAppToWorkspaceFile(options: E2eOptions, workspace: WorkspaceSchema):
7070
const project: any = {
7171
root: projectRoot,
7272
projectType: 'application',
73-
architect: {
73+
targets: {
7474
e2e: {
7575
builder: '@angular-devkit/build-angular:protractor',
7676
options: {

packages/schematics/angular/e2e/index_spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,22 @@ describe('Application Schematic', () => {
8080
it('should set 2 targets for the app', () => {
8181
const tree = schematicRunner.runSchematic('e2e', defaultOptions, workspaceTree);
8282
const workspace = JSON.parse(tree.readContent('/angular.json'));
83-
const architect = workspace.projects.foo.architect;
84-
expect(Object.keys(architect)).toEqual(['e2e', 'lint']);
83+
const targets = workspace.projects.foo.targets;
84+
expect(Object.keys(targets)).toEqual(['e2e', 'lint']);
8585
});
8686

8787
it('should set the e2e options', () => {
8888
const tree = schematicRunner.runSchematic('e2e', defaultOptions, workspaceTree);
8989
const workspace = JSON.parse(tree.readContent('/angular.json'));
90-
const e2eOptions = workspace.projects.foo.architect.e2e.options;
90+
const e2eOptions = workspace.projects.foo.targets.e2e.options;
9191
expect(e2eOptions.protractorConfig).toEqual('projects/foo/protractor.conf.js');
9292
expect(e2eOptions.devServerTarget).toEqual('app:serve');
9393
});
9494

9595
it('should set the lint options', () => {
9696
const tree = schematicRunner.runSchematic('e2e', defaultOptions, workspaceTree);
9797
const workspace = JSON.parse(tree.readContent('/angular.json'));
98-
const lintOptions = workspace.projects.foo.architect.lint.options;
98+
const lintOptions = workspace.projects.foo.targets.lint.options;
9999
expect(lintOptions.tsConfig).toEqual('projects/foo/tsconfig.e2e.json');
100100
});
101101
});

packages/schematics/angular/library/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function addAppToWorkspaceFile(options: LibraryOptions, workspace: WorkspaceSche
138138
sourceRoot: `${projectRoot}/src`,
139139
projectType: 'library',
140140
prefix: options.prefix || 'lib',
141-
architect: {
141+
targets: {
142142
build: {
143143
builder: '@angular-devkit/build-ng-packagr:build',
144144
options: {

packages/schematics/angular/migrations/update-6/index.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ function migrateConfiguration(oldConfig: CliConfig, logger: logging.LoggerApi):
119119
if (schematicsConfig !== null) {
120120
config.schematics = schematicsConfig;
121121
}
122-
const architectConfig = extractArchitectConfig(oldConfig);
123-
if (architectConfig !== null) {
124-
config.architect = architectConfig;
122+
const targetsConfig = extractTargetsConfig(oldConfig);
123+
if (targetsConfig !== null) {
124+
config.targets = targetsConfig;
125125
}
126126

127127
context.logger.info(`Removing old config file (${oldConfigPath})`);
@@ -213,7 +213,7 @@ function extractSchematicsConfig(config: CliConfig): JsonObject | null {
213213
return schematicConfigs;
214214
}
215215

216-
function extractArchitectConfig(_config: CliConfig): JsonObject | null {
216+
function extractTargetsConfig(_config: CliConfig): JsonObject | null {
217217
return null;
218218
}
219219

@@ -365,11 +365,11 @@ function extractProjectsConfig(
365365
if (!environments) {
366366
return {};
367367
}
368-
if (!architect) {
368+
if (!targets) {
369369
throw new Error();
370370
}
371371

372-
const configurations = (architect.build as JsonObject).configurations as JsonObject;
372+
const configurations = (targets.build as JsonObject).configurations as JsonObject;
373373

374374
return Object.keys(configurations).reduce((acc, environment) => {
375375
acc[environment] = { browserTarget: `${name}:build:${environment}` };
@@ -401,8 +401,8 @@ function extractProjectsConfig(
401401
projectType: 'application',
402402
};
403403

404-
const architect: JsonObject = {};
405-
project.architect = architect;
404+
const targets: JsonObject = {};
405+
project.targets = targets;
406406

407407
// Browser target
408408
const buildOptions: JsonObject = {
@@ -432,7 +432,7 @@ function extractProjectsConfig(
432432
buildOptions.assets = (app.assets || []).map(_mapAssets).filter(x => !!x);
433433
buildOptions.styles = (app.styles || []).map(_extraEntryMapper);
434434
buildOptions.scripts = (app.scripts || []).map(_extraEntryMapper);
435-
architect.build = {
435+
targets.build = {
436436
builder: `${builderPackage}:browser`,
437437
options: buildOptions,
438438
configurations: _buildConfigurations(),
@@ -443,15 +443,15 @@ function extractProjectsConfig(
443443
browserTarget: `${name}:build`,
444444
...serveDefaults,
445445
};
446-
architect.serve = {
446+
targets.serve = {
447447
builder: `${builderPackage}:dev-server`,
448448
options: serveOptions,
449449
configurations: _serveConfigurations(),
450450
};
451451

452452
// Extract target
453453
const extractI18nOptions: JsonObject = { browserTarget: `${name}:build` };
454-
architect['extract-i18n'] = {
454+
targets['extract-i18n'] = {
455455
builder: `${builderPackage}:extract-i18n`,
456456
options: extractI18nOptions,
457457
};
@@ -478,7 +478,7 @@ function extractProjectsConfig(
478478
testOptions.assets = (app.assets || []).map(_mapAssets).filter(x => !!x);
479479

480480
if (karmaConfig) {
481-
architect.test = {
481+
targets.test = {
482482
builder: `${builderPackage}:karma`,
483483
options: testOptions,
484484
};
@@ -524,7 +524,7 @@ function extractProjectsConfig(
524524
tsConfig: removeDupes(tsConfigs).filter(t => t.indexOf('e2e') === -1),
525525
exclude: removeDupes(excludes),
526526
};
527-
architect.lint = {
527+
targets.lint = {
528528
builder: `${builderPackage}:tslint`,
529529
options: lintOptions,
530530
};
@@ -543,15 +543,15 @@ function extractProjectsConfig(
543543
builder: '@angular-devkit/build-angular:server',
544544
options: serverOptions,
545545
};
546-
architect.server = serverTarget;
546+
targets.server = serverTarget;
547547
}
548548
const e2eProject: JsonObject = {
549549
root: join(projectRoot, 'e2e'),
550550
sourceRoot: join(projectRoot, 'e2e'),
551551
projectType: 'application',
552552
};
553553

554-
const e2eArchitect: JsonObject = {};
554+
const e2eTargets: JsonObject = {};
555555

556556
// tslint:disable-next-line:max-line-length
557557
const protractorConfig = config && config.e2e && config.e2e.protractor && config.e2e.protractor.config
@@ -566,7 +566,7 @@ function extractProjectsConfig(
566566
options: e2eOptions,
567567
};
568568

569-
e2eArchitect.e2e = e2eTarget;
569+
e2eTargets.e2e = e2eTarget;
570570
const e2eLintOptions: JsonObject = {
571571
tsConfig: removeDupes(tsConfigs).filter(t => t.indexOf('e2e') !== -1),
572572
exclude: removeDupes(excludes),
@@ -575,9 +575,9 @@ function extractProjectsConfig(
575575
builder: `${builderPackage}:tslint`,
576576
options: e2eLintOptions,
577577
};
578-
e2eArchitect.lint = e2eLintTarget;
578+
e2eTargets.lint = e2eLintTarget;
579579
if (protractorConfig) {
580-
e2eProject.architect = e2eArchitect;
580+
e2eProject.targets = e2eTargets;
581581
}
582582

583583
return { name, project, e2eProject };

packages/schematics/angular/migrations/update-6/index_spec.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,12 @@ describe('Migration to v6', () => {
470470
});
471471
});
472472

473-
describe('architect', () => {
473+
describe('targets', () => {
474474
it('should exist', () => {
475475
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
476476
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
477477
const config = getConfig(tree);
478-
expect(config.architect).not.toBeDefined();
478+
expect(config.targets).not.toBeDefined();
479479
});
480480
});
481481

@@ -527,7 +527,7 @@ describe('Migration to v6', () => {
527527
it('should set build target', () => {
528528
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
529529
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
530-
const build = getConfig(tree).projects.foo.architect.build;
530+
const build = getConfig(tree).projects.foo.targets.build;
531531
expect(build.builder).toEqual('@angular-devkit/build-angular:browser');
532532
expect(build.options.scripts).toEqual([]);
533533
expect(build.options.styles).toEqual(['src/styles.css']);
@@ -561,7 +561,7 @@ describe('Migration to v6', () => {
561561
it('should not set baseHref on build & serve targets if not defined', () => {
562562
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
563563
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
564-
const build = getConfig(tree).projects.foo.architect.build;
564+
const build = getConfig(tree).projects.foo.targets.build;
565565
expect(build.options.baseHref).toBeUndefined();
566566
});
567567

@@ -570,7 +570,7 @@ describe('Migration to v6', () => {
570570
config.apps[0].baseHref = '/base/href/';
571571
tree.create(oldConfigPath, JSON.stringify(config, null, 2));
572572
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
573-
const build = getConfig(tree).projects.foo.architect.build;
573+
const build = getConfig(tree).projects.foo.targets.build;
574574
expect(build.options.baseHref).toEqual('/base/href/');
575575
});
576576

@@ -579,9 +579,9 @@ describe('Migration to v6', () => {
579579
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
580580
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
581581
const config = getConfig(tree);
582-
expect(config.projects.foo.architect.build.options.serviceWorker).toBeUndefined();
582+
expect(config.projects.foo.targets.build.options.serviceWorker).toBeUndefined();
583583
expect(
584-
config.projects.foo.architect.build.configurations.production.serviceWorker,
584+
config.projects.foo.targets.build.configurations.production.serviceWorker,
585585
).toBe(true);
586586
});
587587

@@ -590,7 +590,7 @@ describe('Migration to v6', () => {
590590
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
591591
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
592592
const config = getConfig(tree);
593-
expect(config.projects.foo.architect.build.configurations).toEqual({
593+
expect(config.projects.foo.targets.build.configurations).toEqual({
594594
production: {
595595
optimization: true,
596596
outputHashing: 'all',
@@ -610,7 +610,7 @@ describe('Migration to v6', () => {
610610
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
611611
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
612612
const config = getConfig(tree);
613-
expect(config.projects.foo.architect.build.configurations).toEqual({
613+
expect(config.projects.foo.targets.build.configurations).toEqual({
614614
prod: {
615615
fileReplacements: [{
616616
replace: 'src/environments/environment.ts',
@@ -634,7 +634,7 @@ describe('Migration to v6', () => {
634634
it('should set the serve target', () => {
635635
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
636636
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
637-
const serve = getConfig(tree).projects.foo.architect.serve;
637+
const serve = getConfig(tree).projects.foo.targets.serve;
638638
expect(serve.builder).toEqual('@angular-devkit/build-angular:dev-server');
639639
expect(serve.options).toEqual({
640640
browserTarget: 'foo:build',
@@ -647,7 +647,7 @@ describe('Migration to v6', () => {
647647
it('should set the test target', () => {
648648
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
649649
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
650-
const test = getConfig(tree).projects.foo.architect['test'];
650+
const test = getConfig(tree).projects.foo.targets['test'];
651651
expect(test.builder).toEqual('@angular-devkit/build-angular:karma');
652652
expect(test.options.main).toEqual('src/test.ts');
653653
expect(test.options.polyfills).toEqual('src/polyfills.ts');
@@ -666,7 +666,7 @@ describe('Migration to v6', () => {
666666
it('should set the extract i18n target', () => {
667667
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
668668
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
669-
const extract = getConfig(tree).projects.foo.architect['extract-i18n'];
669+
const extract = getConfig(tree).projects.foo.targets['extract-i18n'];
670670
expect(extract.builder).toEqual('@angular-devkit/build-angular:extract-i18n');
671671
expect(extract.options).toBeDefined();
672672
expect(extract.options.browserTarget).toEqual(`foo:build` );
@@ -675,7 +675,7 @@ describe('Migration to v6', () => {
675675
it('should set the lint target', () => {
676676
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
677677
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
678-
const tslint = getConfig(tree).projects.foo.architect['lint'];
678+
const tslint = getConfig(tree).projects.foo.targets['lint'];
679679
expect(tslint.builder).toEqual('@angular-devkit/build-angular:tslint');
680680
expect(tslint.options).toBeDefined();
681681
expect(tslint.options.tsConfig)
@@ -693,7 +693,7 @@ describe('Migration to v6', () => {
693693
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
694694
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
695695
const config = getConfig(tree);
696-
const budgets = config.projects.foo.architect.build.configurations.production.budgets;
696+
const budgets = config.projects.foo.targets.build.configurations.production.budgets;
697697
expect(budgets.length).toEqual(1);
698698
expect(budgets[0].type).toEqual('bundle');
699699
expect(budgets[0].name).toEqual('main');
@@ -708,7 +708,7 @@ describe('Migration to v6', () => {
708708
const e2eProject = getConfig(tree).projects['foo-e2e'];
709709
expect(e2eProject.root).toBe('e2e');
710710
expect(e2eProject.sourceRoot).toBe('e2e');
711-
const e2eOptions = e2eProject.architect.e2e;
711+
const e2eOptions = e2eProject.targets.e2e;
712712
expect(e2eOptions.builder).toEqual('@angular-devkit/build-angular:protractor');
713713
const options = e2eOptions.options;
714714
expect(options.protractorConfig).toEqual('./protractor.conf.js');
@@ -722,7 +722,7 @@ describe('Migration to v6', () => {
722722
const e2eProject = getConfig(tree).projects['foo-e2e'];
723723
expect(e2eProject.root).toBe('apps/app1/e2e');
724724
expect(e2eProject.sourceRoot).toBe('apps/app1/e2e');
725-
const e2eOptions = e2eProject.architect.e2e;
725+
const e2eOptions = e2eProject.targets.e2e;
726726
expect(e2eOptions.builder).toEqual('@angular-devkit/build-angular:protractor');
727727
const options = e2eOptions.options;
728728
expect(options.protractorConfig).toEqual('./protractor.conf.js');
@@ -732,7 +732,7 @@ describe('Migration to v6', () => {
732732
it('should set the lint target', () => {
733733
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
734734
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
735-
const tslint = getConfig(tree).projects['foo-e2e'].architect.lint;
735+
const tslint = getConfig(tree).projects['foo-e2e'].targets.lint;
736736
expect(tslint.builder).toEqual('@angular-devkit/build-angular:tslint');
737737
expect(tslint.options).toBeDefined();
738738
expect(tslint.options.tsConfig).toEqual(['e2e/tsconfig.e2e.json']);
@@ -989,7 +989,7 @@ describe('Migration to v6', () => {
989989
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
990990
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
991991
const config = getConfig(tree);
992-
const target = config.projects.foo.architect.server;
992+
const target = config.projects.foo.targets.server;
993993
expect(target).toBeDefined();
994994
expect(target.builder).toEqual('@angular-devkit/build-angular:server');
995995
expect(target.options.outputPath).toEqual('dist/server');

0 commit comments

Comments
 (0)