[6a3a178] | 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 | */
|
---|
| 9 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 10 | exports.scheduleByTarget = exports.scheduleByName = void 0;
|
---|
| 11 | const core_1 = require("@angular-devkit/core");
|
---|
| 12 | const rxjs_1 = require("rxjs");
|
---|
| 13 | const operators_1 = require("rxjs/operators");
|
---|
| 14 | const api_1 = require("./api");
|
---|
| 15 | const progressSchema = require('./progress-schema.json');
|
---|
| 16 | let _uniqueId = 0;
|
---|
| 17 | async function scheduleByName(name, buildOptions, options) {
|
---|
| 18 | const childLoggerName = options.target ? `{${api_1.targetStringFromTarget(options.target)}}` : name;
|
---|
| 19 | const logger = options.logger.createChild(childLoggerName);
|
---|
| 20 | const job = options.scheduler.schedule(name, {});
|
---|
| 21 | let stateSubscription;
|
---|
| 22 | const workspaceRoot = await options.workspaceRoot;
|
---|
| 23 | const currentDirectory = await options.currentDirectory;
|
---|
| 24 | const description = await job.description.toPromise();
|
---|
| 25 | const info = description.info;
|
---|
| 26 | const id = ++_uniqueId;
|
---|
| 27 | const message = {
|
---|
| 28 | id,
|
---|
| 29 | currentDirectory,
|
---|
| 30 | workspaceRoot,
|
---|
| 31 | info: info,
|
---|
| 32 | options: buildOptions,
|
---|
| 33 | ...(options.target ? { target: options.target } : {}),
|
---|
| 34 | };
|
---|
| 35 | // Wait for the job to be ready.
|
---|
| 36 | if (job.state !== core_1.experimental.jobs.JobState.Started) {
|
---|
| 37 | stateSubscription = job.outboundBus.subscribe((event) => {
|
---|
| 38 | if (event.kind === core_1.experimental.jobs.JobOutboundMessageKind.Start) {
|
---|
| 39 | job.input.next(message);
|
---|
| 40 | }
|
---|
| 41 | }, () => { });
|
---|
| 42 | }
|
---|
| 43 | else {
|
---|
| 44 | job.input.next(message);
|
---|
| 45 | }
|
---|
| 46 | const logChannelSub = job.getChannel('log').subscribe((entry) => {
|
---|
| 47 | logger.next(entry);
|
---|
| 48 | }, () => { });
|
---|
| 49 | const s = job.outboundBus.subscribe({
|
---|
| 50 | error() { },
|
---|
| 51 | complete() {
|
---|
| 52 | s.unsubscribe();
|
---|
| 53 | logChannelSub.unsubscribe();
|
---|
| 54 | if (stateSubscription) {
|
---|
| 55 | stateSubscription.unsubscribe();
|
---|
| 56 | }
|
---|
| 57 | },
|
---|
| 58 | });
|
---|
| 59 | const output = job.output.pipe(operators_1.map((output) => ({
|
---|
| 60 | ...output,
|
---|
| 61 | ...(options.target ? { target: options.target } : 0),
|
---|
| 62 | info,
|
---|
| 63 | })), operators_1.shareReplay());
|
---|
| 64 | // If there's an analytics object, take the job channel and report it to the analytics.
|
---|
| 65 | if (options.analytics) {
|
---|
| 66 | const reporter = new core_1.analytics.AnalyticsReporter(options.analytics);
|
---|
| 67 | job
|
---|
| 68 | .getChannel('analytics')
|
---|
| 69 | .subscribe((report) => reporter.report(report));
|
---|
| 70 | }
|
---|
| 71 | // Start the builder.
|
---|
| 72 | output.pipe(operators_1.first()).subscribe({
|
---|
| 73 | error() { },
|
---|
| 74 | });
|
---|
| 75 | return {
|
---|
| 76 | id,
|
---|
| 77 | info,
|
---|
| 78 | // This is a getter so that it always returns the next output, and not the same one.
|
---|
| 79 | get result() {
|
---|
| 80 | return output.pipe(operators_1.first()).toPromise();
|
---|
| 81 | },
|
---|
| 82 | output,
|
---|
| 83 | progress: job
|
---|
| 84 | .getChannel('progress', progressSchema)
|
---|
| 85 | .pipe(operators_1.shareReplay(1)),
|
---|
| 86 | stop() {
|
---|
| 87 | job.stop();
|
---|
| 88 | return job.outboundBus
|
---|
| 89 | .pipe(operators_1.ignoreElements(), operators_1.catchError(() => rxjs_1.EMPTY))
|
---|
| 90 | .toPromise();
|
---|
| 91 | },
|
---|
| 92 | };
|
---|
| 93 | }
|
---|
| 94 | exports.scheduleByName = scheduleByName;
|
---|
| 95 | async function scheduleByTarget(target, overrides, options) {
|
---|
| 96 | return scheduleByName(`{${api_1.targetStringFromTarget(target)}}`, overrides, {
|
---|
| 97 | ...options,
|
---|
| 98 | target,
|
---|
| 99 | logger: options.logger,
|
---|
| 100 | });
|
---|
| 101 | }
|
---|
| 102 | exports.scheduleByTarget = scheduleByTarget;
|
---|