fallback-engine-host.js 2.9 KB

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