Skip to content

Commit

Permalink
feat(@schematics/angular): use targets property on new projects
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva committed Jul 25, 2018
1 parent dcdb937 commit 3071608
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion packages/schematics/angular/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function addAppToWorkspaceFile(options: ApplicationOptions, workspace: Workspace
projectType: 'application',
prefix: options.prefix || 'app',
schematics,
architect: {
targets: {
build: {
builder: '@angular-devkit/build-angular:browser',
options: {
Expand Down
4 changes: 2 additions & 2 deletions packages/schematics/angular/application/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ describe('Application Schematic', () => {
const config = JSON.parse(tree.readContent('/angular.json'));
const prj = config.projects.foo;
expect(prj.root).toEqual('');
const buildOpt = prj.architect.build.options;
const buildOpt = prj.targets.build.options;
expect(buildOpt.index).toEqual('src/index.html');
expect(buildOpt.main).toEqual('src/main.ts');
expect(buildOpt.polyfills).toEqual('src/polyfills.ts');
expect(buildOpt.tsConfig).toEqual('src/tsconfig.app.json');

const testOpt = prj.architect.test.options;
const testOpt = prj.targets.test.options;
expect(testOpt.main).toEqual('src/test.ts');
expect(testOpt.tsConfig).toEqual('src/tsconfig.spec.json');
expect(testOpt.karmaConfig).toEqual('src/karma.conf.js');
Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/angular/e2e/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function addAppToWorkspaceFile(options: E2eOptions, workspace: WorkspaceSchema):
const project: any = {
root: projectRoot,
projectType: 'application',
architect: {
targets: {
e2e: {
builder: '@angular-devkit/build-angular:protractor',
options: {
Expand Down
8 changes: 4 additions & 4 deletions packages/schematics/angular/e2e/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,22 @@ describe('Application Schematic', () => {
it('should set 2 targets for the app', () => {
const tree = schematicRunner.runSchematic('e2e', defaultOptions, workspaceTree);
const workspace = JSON.parse(tree.readContent('/angular.json'));
const architect = workspace.projects.foo.architect;
expect(Object.keys(architect)).toEqual(['e2e', 'lint']);
const targets = workspace.projects.foo.targets;
expect(Object.keys(targets)).toEqual(['e2e', 'lint']);
});

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

it('should set the lint options', () => {
const tree = schematicRunner.runSchematic('e2e', defaultOptions, workspaceTree);
const workspace = JSON.parse(tree.readContent('/angular.json'));
const lintOptions = workspace.projects.foo.architect.lint.options;
const lintOptions = workspace.projects.foo.targets.lint.options;
expect(lintOptions.tsConfig).toEqual('projects/foo/tsconfig.e2e.json');
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/angular/library/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function addAppToWorkspaceFile(options: LibraryOptions, workspace: WorkspaceSche
sourceRoot: `${projectRoot}/src`,
projectType: 'library',
prefix: options.prefix || 'lib',
architect: {
targets: {
build: {
builder: '@angular-devkit/build-ng-packagr:build',
options: {
Expand Down
36 changes: 18 additions & 18 deletions packages/schematics/angular/migrations/update-6/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ function migrateConfiguration(oldConfig: CliConfig, logger: logging.LoggerApi):
if (schematicsConfig !== null) {
config.schematics = schematicsConfig;
}
const architectConfig = extractArchitectConfig(oldConfig);
if (architectConfig !== null) {
config.architect = architectConfig;
const targetsConfig = extractTargetsConfig(oldConfig);
if (targetsConfig !== null) {
config.targets = targetsConfig;
}

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

function extractArchitectConfig(_config: CliConfig): JsonObject | null {
function extractTargetsConfig(_config: CliConfig): JsonObject | null {
return null;
}

Expand Down Expand Up @@ -365,11 +365,11 @@ function extractProjectsConfig(
if (!environments) {
return {};
}
if (!architect) {
if (!targets) {
throw new Error();
}

const configurations = (architect.build as JsonObject).configurations as JsonObject;
const configurations = (targets.build as JsonObject).configurations as JsonObject;

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

const architect: JsonObject = {};
project.architect = architect;
const targets: JsonObject = {};
project.targets = targets;

// Browser target
const buildOptions: JsonObject = {
Expand Down Expand Up @@ -432,7 +432,7 @@ function extractProjectsConfig(
buildOptions.assets = (app.assets || []).map(_mapAssets).filter(x => !!x);
buildOptions.styles = (app.styles || []).map(_extraEntryMapper);
buildOptions.scripts = (app.scripts || []).map(_extraEntryMapper);
architect.build = {
targets.build = {
builder: `${builderPackage}:browser`,
options: buildOptions,
configurations: _buildConfigurations(),
Expand All @@ -443,15 +443,15 @@ function extractProjectsConfig(
browserTarget: `${name}:build`,
...serveDefaults,
};
architect.serve = {
targets.serve = {
builder: `${builderPackage}:dev-server`,
options: serveOptions,
configurations: _serveConfigurations(),
};

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

if (karmaConfig) {
architect.test = {
targets.test = {
builder: `${builderPackage}:karma`,
options: testOptions,
};
Expand Down Expand Up @@ -524,7 +524,7 @@ function extractProjectsConfig(
tsConfig: removeDupes(tsConfigs).filter(t => t.indexOf('e2e') === -1),
exclude: removeDupes(excludes),
};
architect.lint = {
targets.lint = {
builder: `${builderPackage}:tslint`,
options: lintOptions,
};
Expand All @@ -543,15 +543,15 @@ function extractProjectsConfig(
builder: '@angular-devkit/build-angular:server',
options: serverOptions,
};
architect.server = serverTarget;
targets.server = serverTarget;
}
const e2eProject: JsonObject = {
root: join(projectRoot, 'e2e'),
sourceRoot: join(projectRoot, 'e2e'),
projectType: 'application',
};

const e2eArchitect: JsonObject = {};
const e2eTargets: JsonObject = {};

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

e2eArchitect.e2e = e2eTarget;
e2eTargets.e2e = e2eTarget;
const e2eLintOptions: JsonObject = {
tsConfig: removeDupes(tsConfigs).filter(t => t.indexOf('e2e') !== -1),
exclude: removeDupes(excludes),
Expand All @@ -575,9 +575,9 @@ function extractProjectsConfig(
builder: `${builderPackage}:tslint`,
options: e2eLintOptions,
};
e2eArchitect.lint = e2eLintTarget;
e2eTargets.lint = e2eLintTarget;
if (protractorConfig) {
e2eProject.architect = e2eArchitect;
e2eProject.targets = e2eTargets;
}

return { name, project, e2eProject };
Expand Down
36 changes: 18 additions & 18 deletions packages/schematics/angular/migrations/update-6/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,12 @@ describe('Migration to v6', () => {
});
});

describe('architect', () => {
describe('targets', () => {
it('should exist', () => {
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
const config = getConfig(tree);
expect(config.architect).not.toBeDefined();
expect(config.targets).not.toBeDefined();
});
});

Expand Down Expand Up @@ -527,7 +527,7 @@ describe('Migration to v6', () => {
it('should set build target', () => {
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
const build = getConfig(tree).projects.foo.architect.build;
const build = getConfig(tree).projects.foo.targets.build;
expect(build.builder).toEqual('@angular-devkit/build-angular:browser');
expect(build.options.scripts).toEqual([]);
expect(build.options.styles).toEqual(['src/styles.css']);
Expand Down Expand Up @@ -561,7 +561,7 @@ describe('Migration to v6', () => {
it('should not set baseHref on build & serve targets if not defined', () => {
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
const build = getConfig(tree).projects.foo.architect.build;
const build = getConfig(tree).projects.foo.targets.build;
expect(build.options.baseHref).toBeUndefined();
});

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

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

Expand All @@ -590,7 +590,7 @@ describe('Migration to v6', () => {
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
const config = getConfig(tree);
expect(config.projects.foo.architect.build.configurations).toEqual({
expect(config.projects.foo.targets.build.configurations).toEqual({
production: {
optimization: true,
outputHashing: 'all',
Expand All @@ -610,7 +610,7 @@ describe('Migration to v6', () => {
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
const config = getConfig(tree);
expect(config.projects.foo.architect.build.configurations).toEqual({
expect(config.projects.foo.targets.build.configurations).toEqual({
prod: {
fileReplacements: [{
replace: 'src/environments/environment.ts',
Expand All @@ -634,7 +634,7 @@ describe('Migration to v6', () => {
it('should set the serve target', () => {
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
const serve = getConfig(tree).projects.foo.architect.serve;
const serve = getConfig(tree).projects.foo.targets.serve;
expect(serve.builder).toEqual('@angular-devkit/build-angular:dev-server');
expect(serve.options).toEqual({
browserTarget: 'foo:build',
Expand All @@ -647,7 +647,7 @@ describe('Migration to v6', () => {
it('should set the test target', () => {
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
const test = getConfig(tree).projects.foo.architect['test'];
const test = getConfig(tree).projects.foo.targets['test'];
expect(test.builder).toEqual('@angular-devkit/build-angular:karma');
expect(test.options.main).toEqual('src/test.ts');
expect(test.options.polyfills).toEqual('src/polyfills.ts');
Expand All @@ -666,7 +666,7 @@ describe('Migration to v6', () => {
it('should set the extract i18n target', () => {
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
const extract = getConfig(tree).projects.foo.architect['extract-i18n'];
const extract = getConfig(tree).projects.foo.targets['extract-i18n'];
expect(extract.builder).toEqual('@angular-devkit/build-angular:extract-i18n');
expect(extract.options).toBeDefined();
expect(extract.options.browserTarget).toEqual(`foo:build` );
Expand All @@ -675,7 +675,7 @@ describe('Migration to v6', () => {
it('should set the lint target', () => {
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
const tslint = getConfig(tree).projects.foo.architect['lint'];
const tslint = getConfig(tree).projects.foo.targets['lint'];
expect(tslint.builder).toEqual('@angular-devkit/build-angular:tslint');
expect(tslint.options).toBeDefined();
expect(tslint.options.tsConfig)
Expand All @@ -693,7 +693,7 @@ describe('Migration to v6', () => {
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
const config = getConfig(tree);
const budgets = config.projects.foo.architect.build.configurations.production.budgets;
const budgets = config.projects.foo.targets.build.configurations.production.budgets;
expect(budgets.length).toEqual(1);
expect(budgets[0].type).toEqual('bundle');
expect(budgets[0].name).toEqual('main');
Expand All @@ -708,7 +708,7 @@ describe('Migration to v6', () => {
const e2eProject = getConfig(tree).projects['foo-e2e'];
expect(e2eProject.root).toBe('e2e');
expect(e2eProject.sourceRoot).toBe('e2e');
const e2eOptions = e2eProject.architect.e2e;
const e2eOptions = e2eProject.targets.e2e;
expect(e2eOptions.builder).toEqual('@angular-devkit/build-angular:protractor');
const options = e2eOptions.options;
expect(options.protractorConfig).toEqual('./protractor.conf.js');
Expand All @@ -722,7 +722,7 @@ describe('Migration to v6', () => {
const e2eProject = getConfig(tree).projects['foo-e2e'];
expect(e2eProject.root).toBe('apps/app1/e2e');
expect(e2eProject.sourceRoot).toBe('apps/app1/e2e');
const e2eOptions = e2eProject.architect.e2e;
const e2eOptions = e2eProject.targets.e2e;
expect(e2eOptions.builder).toEqual('@angular-devkit/build-angular:protractor');
const options = e2eOptions.options;
expect(options.protractorConfig).toEqual('./protractor.conf.js');
Expand All @@ -732,7 +732,7 @@ describe('Migration to v6', () => {
it('should set the lint target', () => {
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
const tslint = getConfig(tree).projects['foo-e2e'].architect.lint;
const tslint = getConfig(tree).projects['foo-e2e'].targets.lint;
expect(tslint.builder).toEqual('@angular-devkit/build-angular:tslint');
expect(tslint.options).toBeDefined();
expect(tslint.options.tsConfig).toEqual(['e2e/tsconfig.e2e.json']);
Expand Down Expand Up @@ -989,7 +989,7 @@ describe('Migration to v6', () => {
tree.create(oldConfigPath, JSON.stringify(baseConfig, null, 2));
tree = schematicRunner.runSchematic('migration-01', defaultOptions, tree);
const config = getConfig(tree);
const target = config.projects.foo.architect.server;
const target = config.projects.foo.targets.server;
expect(target).toBeDefined();
expect(target.builder).toEqual('@angular-devkit/build-angular:server');
expect(target.options.outputPath).toEqual('dist/server');
Expand Down

0 comments on commit 3071608

Please sign in to comment.