UNPKG

1.81 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10const rxjs_1 = require("rxjs");
11const operators_1 = require("rxjs/operators");
12const src_1 = require("../src");
13exports.default = src_1.createBuilder((options, context) => {
14 const allRuns = [];
15 context.reportProgress(0, (options.targets ? options.targets.length : 0) +
16 (options.builders ? options.builders.length : 0));
17 if (options.targets) {
18 allRuns.push(...options.targets.map(({ target: targetStr, overrides }) => {
19 const [project, target, configuration] = targetStr.split(/:/g, 3);
20 return () => context.scheduleTarget({ project, target, configuration }, overrides || {});
21 }));
22 }
23 if (options.builders) {
24 allRuns.push(...options.builders.map(({ builder, options }) => {
25 return () => context.scheduleBuilder(builder, options || {});
26 }));
27 }
28 let stop = null;
29 let i = 0;
30 context.reportProgress(i++, allRuns.length);
31 return rxjs_1.from(allRuns).pipe(operators_1.concatMap((fn) => stop
32 ? rxjs_1.of(null)
33 : rxjs_1.from(fn()).pipe(operators_1.switchMap((run) => (run === null ? rxjs_1.of(null) : run.output.pipe(operators_1.first()))))), operators_1.map((output) => {
34 context.reportProgress(i++, allRuns.length);
35 if (output === null || stop !== null) {
36 return stop || { success: false };
37 }
38 else if (output.success === false) {
39 return (stop = output);
40 }
41 else {
42 return output;
43 }
44 }), operators_1.last());
45});