Skip to content

Commit 0c5e52d

Browse files
committed
feat(@angular/cli): build only the projects of a certain type
This commit is just a first example for angular#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 1ad2525 commit 0c5e52d

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-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

+7-3
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ export abstract class ArchitectCommand<T = any> extends Command<T> {
164164
if (!targetSpec.project && this.target) {
165165
// This runs each target sequentially.
166166
// Running them in parallel would jumble the log messages.
167-
return await from(this.getAllProjectsForTargetName(this.target)).pipe(
167+
return await from(
168+
this.getAllProjectsForTargetName(this.target, targetSpec.projectFilter)
169+
).pipe(
168170
concatMap(project => runSingleTarget({ ...targetSpec, project })),
169171
toArray(),
170172
).toPromise().then(results => results.every(res => res === 0) ? 0 : 1);
@@ -197,8 +199,10 @@ export abstract class ArchitectCommand<T = any> extends Command<T> {
197199
}
198200
}
199201

200-
private getAllProjectsForTargetName(targetName: string) {
201-
return this._workspace.listProjectNames().map(projectName =>
202+
private getAllProjectsForTargetName(
203+
targetName: string, filter?: experimental.workspace.projectFilter
204+
) {
205+
return this._workspace.listProjectNames(filter).map(projectName =>
202206
this._architect.listProjectTargets(projectName).includes(targetName) ? projectName : null
203207
).filter(x => !!x);
204208
}

0 commit comments

Comments
 (0)