UNPKG

2.23 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.dev/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.externalSchematic = externalSchematic;
11exports.schematic = schematic;
12const rxjs_1 = require("rxjs");
13const interface_1 = require("../tree/interface");
14const static_1 = require("../tree/static");
15/**
16 * Run a schematic from a separate collection.
17 *
18 * @param collectionName The name of the collection that contains the schematic to run.
19 * @param schematicName The name of the schematic to run.
20 * @param options The options to pass as input to the RuleFactory.
21 */
22function externalSchematic(collectionName, schematicName, options, executionOptions) {
23 return (input, context) => {
24 const collection = context.engine.createCollection(collectionName, context.schematic.collection);
25 const schematic = collection.createSchematic(schematicName);
26 return schematic.call(options, (0, rxjs_1.of)((0, static_1.branch)(input)), context, executionOptions).pipe((0, rxjs_1.last)(), (0, rxjs_1.map)((x) => {
27 input.merge(x, interface_1.MergeStrategy.AllowOverwriteConflict);
28 return input;
29 }));
30 };
31}
32/**
33 * Run a schematic from the same collection.
34 *
35 * @param schematicName The name of the schematic to run.
36 * @param options The options to pass as input to the RuleFactory.
37 */
38function schematic(schematicName, options, executionOptions) {
39 return (input, context) => {
40 const collection = context.schematic.collection;
41 const schematic = collection.createSchematic(schematicName, true);
42 return schematic.call(options, (0, rxjs_1.of)((0, static_1.branch)(input)), context, executionOptions).pipe((0, rxjs_1.last)(), (0, rxjs_1.map)((x) => {
43 // We allow overwrite conflict here because they're the only merge conflict we particularly
44 // don't want to deal with; the input tree might have an OVERWRITE which the sub
45 input.merge(x, interface_1.MergeStrategy.AllowOverwriteConflict);
46 return input;
47 }));
48 };
49}