Skip to content

Commit 05ae15d

Browse files
committed
wip: architect API
1 parent 063525f commit 05ae15d

35 files changed

+2315
-252
lines changed

packages/_/builders/builders.json

-10
This file was deleted.

packages/_/builders/package.json

-12
This file was deleted.

packages/_/builders/src/true.ts

-20
This file was deleted.

packages/angular_devkit/architect/BUILD

+43
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,50 @@ licenses(["notice"]) # MIT
77

88
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
99
load("@build_bazel_rules_nodejs//:defs.bzl", "npm_package")
10+
load("//tools:ts_json_schema.bzl", "ts_json_schema")
1011

1112
package(default_visibility = ["//visibility:public"])
1213

14+
15+
ts_json_schema(
16+
name = "builder_input_schema",
17+
src = "src/input-schema.json",
18+
)
19+
ts_json_schema(
20+
name = "builder_output_schema",
21+
src = "src/output-schema.json",
22+
)
23+
ts_json_schema(
24+
name = "builder_builders_schema",
25+
src = "src/builders-schema.json",
26+
)
27+
28+
29+
ts_library(
30+
name = "node",
31+
srcs = glob(
32+
include = ["node/**/*.ts"],
33+
exclude = [
34+
"**/*_spec.ts",
35+
"**/*_spec_large.ts",
36+
],
37+
),
38+
module_name = "@angular-devkit/architect/node",
39+
module_root = "node/index.d.ts",
40+
# strict_checks = False,
41+
deps = [
42+
"//packages/angular_devkit/core",
43+
"//packages/angular_devkit/core:node",
44+
"@rxjs",
45+
"@rxjs//operators",
46+
"@npm//@types/node",
47+
":architect",
48+
":builder_builders_schema",
49+
":builder_input_schema",
50+
":builder_output_schema",
51+
],
52+
)
53+
1354
ts_library(
1455
name = "architect",
1556
srcs = glob(
@@ -29,6 +70,8 @@ ts_library(
2970
"@rxjs",
3071
"@rxjs//operators",
3172
"@npm//@types/node",
73+
":builder_input_schema",
74+
":builder_output_schema",
3275
],
3376
)
3477

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 { EMPTY, from, of } from 'rxjs';
10+
import { map, mergeMap, tap } from 'rxjs/operators';
11+
import { BuilderOutput, BuilderRun, createBuilder } from '../src/index2';
12+
import { Schema as OperatorSchema } from './operator-schema';
13+
14+
export default createBuilder<json.JsonObject & OperatorSchema>((options, context) => {
15+
const allRuns: Promise<[number, BuilderRun]>[] = [];
16+
17+
context.progress(0,
18+
(options.targets ? options.targets.length : 0)
19+
+ (options.builders ? options.builders.length : 0),
20+
);
21+
22+
if (options.targets) {
23+
allRuns.push(...options.targets.map(({ target: targetStr, overrides }, i) => {
24+
const [project, target, configuration] = targetStr.split(/:/g, 3);
25+
26+
return context.scheduleTarget({ project, target, configuration }, overrides || {})
27+
.then(run => [i, run] as [number, BuilderRun]);
28+
}));
29+
}
30+
31+
if (options.builders) {
32+
allRuns.push(...options.builders.map(({ builder, options }, i) => {
33+
return context.scheduleBuilder(builder, options || {})
34+
.then(run => [i, run] as [number, BuilderRun]);
35+
}));
36+
}
37+
38+
const allResults: (BuilderOutput | null)[] = allRuns.map(() => null);
39+
let n = 0;
40+
41+
return from(allRuns).pipe(
42+
tap(() => context.progress(0, allRuns.length)),
43+
mergeMap(runPromise => from(runPromise)),
44+
mergeMap(([i, run]: [number, BuilderRun]) => run.output.pipe(map(output => [i, output]))),
45+
mergeMap<[number, BuilderOutput], BuilderOutput>(([i, output]) => {
46+
allResults[i] = output;
47+
context.progress(++n, allRuns.length);
48+
49+
if (allResults.some(x => x === null)) {
50+
// Some builders aren't done running yet.
51+
return EMPTY;
52+
} else {
53+
return of({
54+
success: allResults.every(x => x ? x.success : false),
55+
});
56+
}
57+
}),
58+
);
59+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"$schema": "../src/builders-schema.json",
3+
"builders": {
4+
"true": {
5+
"implementation": "./true",
6+
"schema": "./noop-schema.json",
7+
"description": "Always succeed."
8+
},
9+
"false": {
10+
"implementation": "./false",
11+
"schema": "./noop-schema.json",
12+
"description": "Always fails."
13+
},
14+
"allOf": {
15+
"implementation": "./all-of",
16+
"schema": "./operator-schema.json",
17+
"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)"
23+
}
24+
}
25+
}
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/index2';
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+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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 { of } from 'rxjs';
9+
import { createBuilder } from '../src/index2';
10+
11+
export default createBuilder(() => of({
12+
success: false,
13+
error: 'False builder always errors.',
14+
}));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"$schema": "http://json-schema.org/schema",
3+
"description": "All input types of builders that perform operations on one or multiple sub-builders.",
4+
"type": "object",
5+
"properties": {
6+
"builders": {
7+
"type": "array",
8+
"items": {
9+
"type": "object",
10+
"properties": {
11+
"builder": {
12+
"type": "string",
13+
"pattern": ".*:.*"
14+
},
15+
"options": {
16+
"type": "object"
17+
}
18+
},
19+
"required": [
20+
"builder"
21+
]
22+
},
23+
"minItems": 1
24+
},
25+
"targets": {
26+
"type": "array",
27+
"items": {
28+
"type": "object",
29+
"properties": {
30+
"target": {
31+
"type": "string",
32+
"pattern": ".*:.*"
33+
},
34+
"overrides": {
35+
"type": "object"
36+
}
37+
},
38+
"required": [
39+
"target"
40+
]
41+
},
42+
"minItems": 1
43+
}
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 { of } from 'rxjs';
9+
import { createBuilder } from '../src/index2';
10+
11+
export default createBuilder(() => of({ success: true }));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
export * from './node-modules-architect-host';

0 commit comments

Comments
 (0)