Skip to content

Commit 48f9525

Browse files
author
Angular Builds
committed
wip: .
1 parent 3935b84 commit 48f9525

19 files changed

+1129
-1741
lines changed

packages/angular_devkit/architect/builders/builders.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@
22
"$schema": "../src/builders-schema.json",
33
"builders": {
44
"true": {
5-
"version": 2,
65
"implementation": "./true",
76
"schema": "./noop-schema.json",
87
"description": "Always succeed."
98
},
109
"false": {
11-
"version": 2,
1210
"implementation": "./false",
1311
"schema": "./noop-schema.json",
1412
"description": "Always fails."
1513
},
1614
"allOf": {
17-
"version": 2,
1815
"implementation": "./all-of",
1916
"schema": "./operator-schema.json",
2017
"description": "A builder that executes many builders in parallel, and succeed if both succeeds."
18+
},
19+
"concat": {
20+
"implementation": "./concat",
21+
"schema": "./operator-schema.json",
22+
"description": "A builder that executes many builders one after the other, and stops when one fail. It will succeed if all builders succeeds (and return the last output)"
2123
}
2224
}
2325
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
import { json } from '@angular-devkit/core';
9+
import { from, of } from 'rxjs';
10+
import { concatMap, first, last, map, switchMap } from 'rxjs/operators';
11+
import { BuilderOutput, BuilderRun, createBuilder } from '../src';
12+
import { Schema as OperatorSchema } from './operator-schema';
13+
14+
export default createBuilder<json.JsonObject & OperatorSchema>((options, context) => {
15+
const allRuns: (() => Promise<BuilderRun>)[] = [];
16+
17+
context.progress(0,
18+
(options.targets ? options.targets.length : 0)
19+
+ (options.builders ? options.builders.length : 0),
20+
);
21+
22+
23+
if (options.targets) {
24+
allRuns.push(...options.targets.map(({ target: targetStr, overrides }) => {
25+
const [project, target, configuration] = targetStr.split(/:/g, 3);
26+
27+
return () => context.scheduleTarget({ project, target, configuration }, overrides || {});
28+
}));
29+
}
30+
31+
if (options.builders) {
32+
allRuns.push(...options.builders.map(({ builder, options }) => {
33+
return () => context.scheduleBuilder(builder, options || {});
34+
}));
35+
}
36+
37+
let stop: BuilderOutput | null = null;
38+
let i = 0;
39+
context.progress(i++, allRuns.length);
40+
41+
return from(allRuns).pipe(
42+
concatMap(fn => stop ? of(null) : from(fn()).pipe(
43+
switchMap(run => run === null ? of(null) : run.output.pipe(first())),
44+
)),
45+
map(output => {
46+
context.progress(i++, allRuns.length);
47+
if (output === null || stop !== null) {
48+
return stop || { success: false };
49+
} else if (output.success === false) {
50+
return stop = output;
51+
} else {
52+
return output;
53+
}
54+
}),
55+
last(),
56+
);
57+
});

packages/angular_devkit/architect/node/node-modules-architect-host.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@
88
import { experimental, json } from '@angular-devkit/core';
99
import { resolve } from '@angular-devkit/core/node';
1010
import * as path from 'path';
11-
import { ArchitectHost, BuilderInfo, BuilderJobHandler, BuilderSymbol } from '../src/api';
11+
import { ArchitectHost, BuilderInfo, BuilderJobHandler, BuilderSymbol } from '../src';
1212
import { Schema as BuilderSchema } from '../src/builders-schema';
1313
import { Target } from '../src/input-schema';
1414

15+
16+
export type NodeModulesBuilderInfo = BuilderInfo & {
17+
import: string;
18+
};
19+
20+
1521
// TODO: create a base class for all workspace related hosts.
16-
export class WorkspaceNodeModulesArchitectHost implements ArchitectHost {
22+
export class WorkspaceNodeModulesArchitectHost implements ArchitectHost<NodeModulesBuilderInfo> {
1723
constructor(
1824
protected _workspace: experimental.workspace.Workspace,
1925
protected _root: string,
@@ -30,7 +36,7 @@ export class WorkspaceNodeModulesArchitectHost implements ArchitectHost {
3036
* @param builderStr The name of the builder to be used.
3137
* @returns All the info needed for the builder itself.
3238
*/
33-
resolveBuilder(builderStr: string): Promise<BuilderInfo> {
39+
resolveBuilder(builderStr: string): Promise<NodeModulesBuilderInfo> {
3440
const [packageName, builderName] = builderStr.split(':', 2);
3541
if (!builderName) {
3642
throw new Error('No builder name specified.');
@@ -57,27 +63,25 @@ export class WorkspaceNodeModulesArchitectHost implements ArchitectHost {
5763
throw new Error(`Cannot find builder ${JSON.stringify(builderName)}.`);
5864
}
5965

60-
const importPath = builder.version == 2 ? builder.implementation : builder.class;
66+
const importPath = builder.implementation;
6167
if (!importPath) {
6268
throw new Error('Invalid builder JSON');
6369
}
6470

6571
return Promise.resolve({
6672
name: builderStr,
67-
version: builder.version || 1,
68-
packageName,
6973
builderName,
7074
description: builder['description'],
7175
optionSchema: require(path.resolve(path.dirname(builderJsonPath), builder.schema)),
7276
import: path.resolve(path.dirname(builderJsonPath), importPath),
7377
});
7478
}
7579

76-
getCurrentDirectory(): string {
80+
async getCurrentDirectory() {
7781
return process.cwd();
7882
}
7983

80-
getWorkspaceRoot(): string {
84+
async getWorkspaceRoot() {
8185
return this._root;
8286
}
8387

@@ -93,7 +97,7 @@ export class WorkspaceNodeModulesArchitectHost implements ArchitectHost {
9397
};
9498
}
9599

96-
async loadBuilder(info: BuilderInfo): Promise<BuilderJobHandler> {
100+
async loadBuilder(info: NodeModulesBuilderInfo): Promise<BuilderJobHandler> {
97101
const builder = (await import(info.import)).default;
98102
if (builder[BuilderSymbol]) {
99103
return builder.handler;

0 commit comments

Comments
 (0)