Skip to content

Commit 150d8bf

Browse files
committed
feat(@angular/cli): build only the projects of a certain type
This commit is just a first example for #10369, following the discussion started in angular/devkit#730. angular/devkit#739 would be needed. This example would also require some evolutions on @angular-devkit/architect, but I'm sure there is a way to do this.
1 parent 89242be commit 150d8bf

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

packages/@angular/cli/commands/build.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { ArchitectCommand } from '../models/architect-command';
22
import { Option, CommandScope } from '../models/command';
33
import { Version } from '../upgrade/version';
4+
import { experimental } from '@angular-devkit/core';
45

56
export interface Options {
67
project?: string;
78
configuration?: string;
9+
projectType?: string;
810
prod: boolean;
911
}
1012

13+
1114
export default class BuildCommand extends ArchitectCommand {
1215
public readonly name = 'build';
1316
public readonly target = 'build';
@@ -38,9 +41,13 @@ export default class BuildCommand extends ArchitectCommand {
3841
delete overrides.configuration;
3942
delete overrides.prod;
4043

44+
const filter: experimental.workspace.projectFilter = options.projectType
45+
&& ((project) => project.projectType === options.projectType);
46+
4147
return this.runArchitectTarget({
4248
project: options.project,
4349
target: this.target,
50+
projectFilter: filter,
4451
configuration,
4552
overrides
4653
}, options);

packages/@angular/cli/models/architect-command.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { from } from 'rxjs';
1010
import { concatMap, map, tap, toArray } from 'rxjs/operators';
1111
import { WorkspaceLoader } from '../models/workspace-loader';
1212

13+
type projectFilter = experimental.workspace.projectFilter;
14+
1315

1416
export abstract class ArchitectCommand<T = any> extends Command<T> {
1517
private _host = new NodeJsSyncHost();
@@ -161,7 +163,7 @@ export abstract class ArchitectCommand<T = any> extends Command<T> {
161163
if (!targetSpec.project && this.target) {
162164
// This runs each target sequentially.
163165
// Running them in parallel would jumble the log messages.
164-
return await from(this.getProjectNamesByTarget(this.target)).pipe(
166+
return await from(this.getProjectNamesByTarget(this.target, targetSpec.projectFilter)).pipe(
165167
concatMap(project => runSingleTarget({ ...targetSpec, project })),
166168
toArray(),
167169
).toPromise().then(results => results.every(res => res === 0) ? 0 : 1);
@@ -194,8 +196,8 @@ export abstract class ArchitectCommand<T = any> extends Command<T> {
194196
}
195197
}
196198

197-
private getProjectNamesByTarget(targetName: string): string[] {
198-
const allProjectsForTargetName = this._workspace.listProjectNames().map(projectName =>
199+
private getProjectNamesByTarget(targetName: string, filter?: projectFilter): string[] {
200+
const allProjectsForTargetName = this._workspace.listProjectNames(filter).map(projectName =>
199201
this._architect.listProjectTargets(projectName).includes(targetName) ? projectName : null
200202
).filter(x => !!x);
201203

0 commit comments

Comments
 (0)