Skip to content

Commit 6d238c0

Browse files
committed
wip: .
1 parent 811b596 commit 6d238c0

File tree

5 files changed

+116
-91
lines changed

5 files changed

+116
-91
lines changed

packages/angular_devkit/architect/builders/builders.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
{
2-
"$schema": "../architect/src/builders-schema.json",
3-
"version": 2,
2+
"$schema": "../src/builders-schema.json",
43
"builders": {
54
"true": {
5+
"version": 2,
66
"implementation": "./true",
77
"schema": "./noop-schema.json",
88
"description": "Always succeed."
99
},
1010
"false": {
11+
"version": 2,
1112
"implementation": "./false",
1213
"schema": "./noop-schema.json",
1314
"description": "Always fails."
1415
},
1516
"and": {
17+
"version": 2,
1618
"implementation": "./and",
17-
"schema": "./and-schema.json",
19+
"schema": "./operator-schema.json",
1820
"description": "A builder that executes many builders in parallel, and succeed if both succeeds."
1921
}
2022
}

packages/angular_devkit/architect/src/api.ts

+41-63
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
import { experimental, isPromise, json, logging } from '@angular-devkit/core';
99
import { Observable, from, isObservable, of } from 'rxjs';
1010
import { concatMap, first, map, shareReplay, switchMap, tap } from 'rxjs/operators';
11-
import { JobInboundMessageKind, JobOutboundMessageKind } from '../../core/src/experimental/jobs';
12-
import { Schema as RealBuilderInput, Target } from './input-schema';
11+
import { JobInboundMessageKind } from '../../core/src/experimental/jobs';
12+
import { Schema as RealBuilderInput, Target as RealTarget } from './input-schema';
1313
import { Schema as RealBuilderOutput } from './output-schema';
1414
import { Schema as RealBuilderProgress } from './progress-schema';
1515

16-
export type Target = Target;
16+
export type Target = json.JsonObject & RealTarget;
1717

1818
// Type short hands.
1919
export type BuilderJobHandler<
@@ -55,7 +55,7 @@ export const VersionSymbol = Symbol.for('@angular-devkit/architect:version');
5555

5656

5757
export interface Builder<OptionT extends json.JsonObject> {
58-
handler: experimental.jobs.JobHandler<boolean, BuilderInput, BuilderOutput>;
58+
handler: experimental.jobs.JobHandler<json.JsonObject, BuilderInput, BuilderOutput>;
5959
[BuilderSymbol]: true;
6060
[VersionSymbol]: string;
6161
}
@@ -154,11 +154,17 @@ async function _scheduleTarget(
154154
reason: 'initial',
155155
options: overrides,
156156
target,
157-
} as BuilderInput);
157+
});
158158
}
159159
});
160160
} else {
161-
161+
job.input.next({
162+
currentDirectory: options.workspaceRoot,
163+
workspaceRoot: options.currentDirectory,
164+
reason: 'schedule',
165+
options: overrides,
166+
target,
167+
});
162168
}
163169

164170
job.outboundBus.subscribe(
@@ -181,70 +187,42 @@ async function _scheduleTarget(
181187
export function createBuilder<OptT extends json.JsonObject>(
182188
fn: BuilderHandlerFn<OptT>,
183189
): Builder<OptT> {
184-
function handler(
185-
options: boolean,
186-
context: experimental.jobs.JobHandlerContext<boolean, BuilderInput, BuilderOutput>,
187-
) {
188-
const description = context.description;
190+
const cjh = experimental.jobs.createJobHandler;
191+
const handler = cjh<json.JsonObject, BuilderInput, BuilderOutput>((options, context) => {
189192
const scheduler = context.scheduler;
190-
191-
return new Observable<experimental.jobs.JobOutboundMessage<BuilderOutput>>(observer => {
192-
const logger = new logging.Logger('job');
193-
logger.subscribe(entry => {
194-
observer.next({
195-
kind: JobOutboundMessageKind.Log,
196-
description,
197-
entry,
198-
});
199-
});
200-
201-
context.inboundBus.subscribe(x => {
202-
if (x.kind === experimental.jobs.JobInboundMessageKind.Input) {
203-
const i = x.value;
204-
const context: BuilderContext = {
205-
workspaceRoot: i.workspaceRoot,
206-
currentDirectory: i.currentDirectory,
207-
target: i.target,
208-
logger,
209-
scheduleTarget(target: Target, overrides: json.JsonObject) {
210-
return _scheduleTarget(target, overrides, scheduler, {
211-
logger,
212-
workspaceRoot: i.workspaceRoot,
213-
currentDirectory: i.currentDirectory,
214-
});
215-
},
216-
};
217-
218-
let result = fn(i.options as OptT, context);
219-
220-
if (isPromise(result)) {
221-
result = from(result);
222-
} else if (!isObservable(result)) {
223-
result = of(result);
224-
}
225-
226-
result.subscribe(
227-
value => observer.next({
228-
kind: experimental.jobs.JobOutboundMessageKind.Output,
229-
description,
230-
value,
231-
}),
232-
err => observer.error(err),
233-
() => observer.complete(),
234-
);
193+
const logger = context.logger;
194+
195+
return new Observable<BuilderOutput>(observer => {
196+
context.input.subscribe(i => {
197+
const context: BuilderContext = {
198+
workspaceRoot: i.workspaceRoot,
199+
currentDirectory: i.currentDirectory,
200+
target: i.target as Target,
201+
logger: logger,
202+
scheduleTarget(target: Target, overrides: json.JsonObject) {
203+
return _scheduleTarget(target, overrides, scheduler, {
204+
logger: logger.createChild(''),
205+
workspaceRoot: i.workspaceRoot,
206+
currentDirectory: i.currentDirectory,
207+
});
208+
},
209+
};
210+
211+
let result = fn(i.options as OptT, context);
212+
213+
if (isPromise(result)) {
214+
result = from(result);
215+
} else if (!isObservable(result)) {
216+
result = of(result);
235217
}
236-
});
237218

238-
// The job is ready to listen.
239-
observer.next({
240-
description,
241-
kind: experimental.jobs.JobOutboundMessageKind.Start,
219+
return result.subscribe(observer);
242220
});
243221
});
244-
}
222+
});
245223

246224
return {
247-
handler: Object.assign(handler, { jobDescription: {} }),
225+
handler,
248226
[BuilderSymbol]: true,
249227
[VersionSymbol]: require('../package.json').version,
250228
};

packages/angular_devkit/architect/src/progress-schema.json

+68-22
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,77 @@
33
"id": "BuilderProgressSchema",
44
"title": "Progress schema for builders.",
55
"type": "object",
6-
"properties": {
7-
"current": {
8-
"type": "number",
9-
"minimum": 0
10-
},
11-
"total": {
12-
"type": "number",
13-
"minimum": 0
6+
"oneOf": [
7+
{
8+
"type": "object",
9+
"properties": {
10+
"state": {
11+
"type": "string",
12+
"enum": [
13+
"stopped"
14+
]
15+
}
16+
},
17+
"required": [
18+
"state"
19+
]
1420
},
15-
"state": {
16-
"type": "string",
17-
"enum": [
18-
"stopped",
19-
"waiting",
20-
"running",
21-
"error"
21+
{
22+
"type": "object",
23+
"properties": {
24+
"state": {
25+
"type": "string",
26+
"enum": [
27+
"waiting"
28+
]
29+
},
30+
"status": {
31+
"type": "string"
32+
}
33+
},
34+
"required": [
35+
"state"
2236
]
2337
},
24-
"status": {
25-
"type": "string"
38+
{
39+
"type": "object",
40+
"properties": {
41+
"state": {
42+
"type": "string",
43+
"enum": [
44+
"running"
45+
]
46+
},
47+
"current": {
48+
"type": "number",
49+
"minimum": 0
50+
},
51+
"total": {
52+
"type": "number",
53+
"minimum": 0
54+
},
55+
"status": {
56+
"type": "string"
57+
}
58+
},
59+
"required": [
60+
"state"
61+
]
2662
},
27-
"error": true
28-
},
29-
"required": [
30-
"current",
31-
"state"
63+
{
64+
"type": "object",
65+
"properties": {
66+
"state": {
67+
"type": "string",
68+
"enum": [
69+
"error"
70+
]
71+
},
72+
"error": true
73+
},
74+
"required": [
75+
"state"
76+
]
77+
}
3278
]
3379
}

packages/angular_devkit/architect_cli/bin/architect.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ async function _executeTarget(
9696
run.output.subscribe(
9797
o => console.log('output: ', JSON.stringify(o)),
9898
err => console.error('err', err),
99-
() => console.log('complete\n\n'),
99+
() => console.log('complete'),
100100
);
101101

102102
// Wait for full completion of the builder.

packages/angular_devkit/core/src/experimental/jobs/create-job-handler.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ export function createJobHandler<A extends JsonValue, I extends JsonValue, O ext
108108
});
109109

110110
// Execute the function with the additional context.
111-
subject.next({ kind: JobOutboundMessageKind.Start, description });
112-
113111
const channels = new Map<string, Subject<JsonValue>>();
114112

115113
const newContext: SimpleJobHandlerContext<A, I, O> = {
@@ -145,6 +143,7 @@ export function createJobHandler<A extends JsonValue, I extends JsonValue, O ext
145143
},
146144
};
147145

146+
subject.next({ kind: JobOutboundMessageKind.Start, description });
148147
const result = fn(argument, newContext);
149148
// If the result is a promise, simply wait for it to complete before reporting the result.
150149
if (isPromise(result)) {

0 commit comments

Comments
 (0)