Skip to content

feat(@angular/cli): build only the projects of a certain type #10397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/@angular/cli/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { ArchitectCommand } from '../models/architect-command';
import { Option, CommandScope } from '../models/command';
import { Version } from '../upgrade/version';
import { experimental } from '@angular-devkit/core';

export interface Options {
project?: string;
configuration?: string;
projectType?: string;
prod: boolean;
}


export default class BuildCommand extends ArchitectCommand {
public readonly name = 'build';
public readonly target = 'build';
Expand Down Expand Up @@ -38,9 +41,13 @@ export default class BuildCommand extends ArchitectCommand {
delete overrides.configuration;
delete overrides.prod;

const filter: experimental.workspace.projectFilter = options.projectType
&& ((project) => project.projectType === options.projectType);

return this.runArchitectTarget({
project: options.project,
target: this.target,
projectFilter: filter,
configuration,
overrides
}, options);
Expand Down
8 changes: 5 additions & 3 deletions packages/@angular/cli/models/architect-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { from } from 'rxjs';
import { concatMap, map, tap, toArray } from 'rxjs/operators';
import { WorkspaceLoader } from '../models/workspace-loader';

type projectFilter = experimental.workspace.projectFilter;


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

private getProjectNamesByTarget(targetName: string): string[] {
const allProjectsForTargetName = this._workspace.listProjectNames().map(projectName =>
private getProjectNamesByTarget(targetName: string, filter?: projectFilter): string[] {
const allProjectsForTargetName = this._workspace.listProjectNames(filter).map(projectName =>
this._architect.listProjectTargets(projectName).includes(targetName) ? projectName : null
).filter(x => !!x);

Expand Down