Skip to content

Commit

Permalink
feat(all): use targets instead of architect
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed Sep 9, 2018
1 parent b672c36 commit 8bcb619
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"root": "",
"sourceRoot": "src",
"projectType": "application",
"architect": {
"targets": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
Expand Down Expand Up @@ -107,7 +107,7 @@
"root": "",
"sourceRoot": "",
"projectType": "application",
"architect": {
"targets": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
Expand Down
6 changes: 4 additions & 2 deletions packages/schematics/plugin/plugin.g2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ describe('NgAlainSchematic: plugin: g2', () => {
it(`should add scripts`, () => {
const json = JSON.parse(tree.readContent('angular.json'));
const scripts: string[] =
json.projects.foo.architect.build.options.scripts || [];
(json.projects.foo.architect || json.projects.foo.targets).build.options
.scripts || [];
expect(scripts.filter(w => w.includes('g2')).length).toBeGreaterThan(0);
});
});
Expand All @@ -36,7 +37,8 @@ describe('NgAlainSchematic: plugin: g2', () => {
it(`should add scripts`, () => {
const json = JSON.parse(tree.readContent('angular.json'));
const scripts: string[] =
json.projects.foo.architect.build.options.scripts || [];
(json.projects.foo.architect || json.projects.foo.targets).build.options
.scripts || [];
expect(scripts.filter(w => w.includes('g2')).length).toBe(0);
});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/schematics/plugin/plugin.hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function configToAngularJson(host: Tree, options: PluginOptions) {
const json = getAngular(host);
const project = getProjectFromWorkspace(json, options.project);
// add build config
project.architect!.build!.configurations['hmr'] = {
project.targets!.build!.configurations['hmr'] = {
fileReplacements: [
{
replace: `${options.sourceRoot}/environments/environment.ts`,
Expand All @@ -25,7 +25,7 @@ function configToAngularJson(host: Tree, options: PluginOptions) {
],
};
// add serve config
project.architect!.serve!.configurations['hmr'] = {
project.targets!.serve!.configurations['hmr'] = {
browserTarget: `${project.name}:build:hmr`,
hmr: true,
};
Expand Down
4 changes: 2 additions & 2 deletions packages/schematics/update/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ function getTsConfigPaths(tree: Tree): string[] {
const workspace = getWorkspace(tree);

for (const project of Object.values(workspace.projects)) {
if (project && project.architect) {
if (project && (project.architect || project.targets)) {
for (const taskName of ['build', 'test']) {
const task = project.architect[taskName];
const task = (project.architect || project.targets)[taskName];
if (task && task.options && task.options.tsConfig) {
const tsConfigOption = task.options.tsConfig;
if (typeof tsConfigOption === 'string') {
Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/utils/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Project } from './project';

/** Gets the app index.html file */
export function getIndexHtmlPath(host: Tree, project: Project): string {
const buildTarget = project.architect.build.options;
const buildTarget = project.targets.build.options;

if (buildTarget.index && buildTarget.index.endsWith('index.html')) {
return buildTarget.index;
Expand Down
4 changes: 2 additions & 2 deletions packages/schematics/utils/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export function scriptsToAngularJson(
const json = getAngular(host);
const project = getProjectFromWorkspace(json, projectName);
types.forEach(type => {
const scriptsNode = project.architect[type]!.options!.scripts as string[];
const stylesNode = project.architect[type]!.options!.styles as string[];
const scriptsNode = project.targets[type]!.options!.scripts as string[];
const stylesNode = project.targets[type]!.options!.styles as string[];
for (const path of resources) {
const list = path.endsWith('.js') ? scriptsNode : stylesNode;
if (behavior === 'add') {
Expand Down
4 changes: 2 additions & 2 deletions packages/schematics/utils/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface Workspace {
[k: string]: any;
};
/** Tool options. */
architect?: {
targets?: {
/** Link to schema. */
$schema?: string;
[k: string]: any;
Expand Down Expand Up @@ -64,7 +64,7 @@ export interface Project {
[k: string]: any;
};
/** Tool options. */
architect?: ProjectBuildOptions;
targets?: ProjectBuildOptions;
}

/** Architect options for an Angular CLI workspace. */
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/code.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class CodeService {
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"targets": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
Expand Down Expand Up @@ -122,7 +122,7 @@ export class CodeService {
"demo-e2e": {
"root": "e2e/",
"projectType": "application",
"architect": {
"targets": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
Expand Down

0 comments on commit 8bcb619

Please sign in to comment.