/
index.ts
56 lines (49 loc) · 1.4 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import {
BuilderContext,
BuilderOutputLike,
createBuilder,
scheduleTargetAndForget,
targetFromTargetString
} from '@angular-devkit/architect';
import { Schema, Target, Targets } from './schema';
import { combineLatest, concat, noop, Observable, of, pipe } from 'rxjs';
import { catchError, concatMap, map, take, tap } from 'rxjs/operators';
function buildStep(
stepName: string,
targets: Targets,
context: BuilderContext
): Observable<any> {
const { deps = [], overrides, target, watch }: Target = targets[stepName];
const deps$ = deps.length
? combineLatest(deps.map(depName => buildStep(depName, targets, context)))
: of(null);
return deps$.pipe(
concatMap(() => {
return scheduleTargetAndForget(context, targetFromTargetString(target), {
watch,
...overrides
});
}),
watch ? tap(noop) : take(1)
);
}
function buildSteps(config: Schema, context: BuilderContext): Observable<any> {
return concat(
...config.steps.map(step => buildStep(step, config.targets, context))
);
}
export function runStepper(
input: Schema,
context: BuilderContext
): BuilderOutputLike {
return buildSteps(input, context).pipe(
map(() => ({
success: true
})),
catchError(error => {
return of({ error: error.toString(), success: false });
})
);
}
export const StepperBuilder = createBuilder(runStepper);
export default StepperBuilder;