UNPKG

2.29 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 });
10exports.schematic = exports.externalSchematic = void 0;
11const rxjs_1 = require("rxjs");
12const interface_1 = require("../tree/interface");
13const static_1 = require("../tree/static");
14/**
15 * Run a schematic from a separate collection.
16 *
17 * @param collectionName The name of the collection that contains the schematic to run.
18 * @param schematicName The name of the schematic to run.
19 * @param options The options to pass as input to the RuleFactory.
20 */
21function externalSchematic(collectionName, schematicName, options, executionOptions) {
22 return (input, context) => {
23 const collection = context.engine.createCollection(collectionName, context.schematic.collection);
24 const schematic = collection.createSchematic(schematicName);
25 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) => {
26 input.merge(x, interface_1.MergeStrategy.AllowOverwriteConflict);
27 return input;
28 }));
29 };
30}
31exports.externalSchematic = externalSchematic;
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}
50exports.schematic = schematic;