[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.FallbackEngineHost = void 0;
|
---|
| 11 | const rxjs_1 = require("rxjs");
|
---|
| 12 | const operators_1 = require("rxjs/operators");
|
---|
| 13 | const src_1 = require("../src");
|
---|
| 14 | /**
|
---|
| 15 | * An EngineHost that support multiple hosts in a fallback configuration. If a host does not
|
---|
| 16 | * have a collection/schematics, use the following host before giving up.
|
---|
| 17 | */
|
---|
| 18 | class FallbackEngineHost {
|
---|
| 19 | constructor() {
|
---|
| 20 | this._hosts = [];
|
---|
| 21 | }
|
---|
| 22 | addHost(host) {
|
---|
| 23 | this._hosts.push(host);
|
---|
| 24 | }
|
---|
| 25 | createCollectionDescription(name, requester) {
|
---|
| 26 | for (const host of this._hosts) {
|
---|
| 27 | try {
|
---|
| 28 | const description = host.createCollectionDescription(name, requester);
|
---|
| 29 | return { name, host, description };
|
---|
| 30 | }
|
---|
| 31 | catch (_) { }
|
---|
| 32 | }
|
---|
| 33 | throw new src_1.UnknownCollectionException(name);
|
---|
| 34 | }
|
---|
| 35 | createSchematicDescription(name, collection) {
|
---|
| 36 | const description = collection.host.createSchematicDescription(name, collection.description);
|
---|
| 37 | if (!description) {
|
---|
| 38 | return null;
|
---|
| 39 | }
|
---|
| 40 | return { name, collection, description };
|
---|
| 41 | }
|
---|
| 42 | getSchematicRuleFactory(schematic, collection) {
|
---|
| 43 | return collection.host.getSchematicRuleFactory(schematic.description, collection.description);
|
---|
| 44 | }
|
---|
| 45 | createSourceFromUrl(url, context) {
|
---|
| 46 | return context.schematic.collection.description.host.createSourceFromUrl(url, context);
|
---|
| 47 | }
|
---|
| 48 | transformOptions(schematic, options, context) {
|
---|
| 49 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
---|
| 50 | return rxjs_1.of(options).pipe(...this._hosts.map((host) => operators_1.mergeMap((opt) => host.transformOptions(schematic, opt, context))));
|
---|
| 51 | }
|
---|
| 52 | transformContext(context) {
|
---|
| 53 | let result = context;
|
---|
| 54 | this._hosts.forEach((host) => {
|
---|
| 55 | result = (host.transformContext(result) || result);
|
---|
| 56 | });
|
---|
| 57 | return result;
|
---|
| 58 | }
|
---|
| 59 | listSchematicNames(collection) {
|
---|
| 60 | const allNames = new Set();
|
---|
| 61 | this._hosts.forEach((host) => {
|
---|
| 62 | try {
|
---|
| 63 | host.listSchematicNames(collection.description).forEach((name) => allNames.add(name));
|
---|
| 64 | }
|
---|
| 65 | catch (_) { }
|
---|
| 66 | });
|
---|
| 67 | return [...allNames];
|
---|
| 68 | }
|
---|
| 69 | createTaskExecutor(name) {
|
---|
| 70 | for (const host of this._hosts) {
|
---|
| 71 | if (host.hasTaskExecutor(name)) {
|
---|
| 72 | return host.createTaskExecutor(name);
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 | return rxjs_1.throwError(new src_1.UnregisteredTaskException(name));
|
---|
| 76 | }
|
---|
| 77 | hasTaskExecutor(name) {
|
---|
| 78 | for (const host of this._hosts) {
|
---|
| 79 | if (host.hasTaskExecutor(name)) {
|
---|
| 80 | return true;
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 | return false;
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 | exports.FallbackEngineHost = FallbackEngineHost;
|
---|