source: trip-planner-front/node_modules/@angular-devkit/schematics/src/rules/base.js@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 5.1 KB
Line 
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.applyToSubtree = exports.composeFileOperators = exports.forEach = exports.partitionApplyMerge = exports.when = exports.branchAndMerge = exports.asSource = exports.filter = exports.noop = exports.mergeWith = exports.apply = exports.chain = exports.empty = exports.source = void 0;
11const rxjs_1 = require("rxjs");
12const operators_1 = require("rxjs/operators");
13const exception_1 = require("../exception/exception");
14const host_tree_1 = require("../tree/host-tree");
15const interface_1 = require("../tree/interface");
16const scoped_1 = require("../tree/scoped");
17const static_1 = require("../tree/static");
18const call_1 = require("./call");
19/**
20 * A Source that returns an tree as its single value.
21 */
22function source(tree) {
23 return () => tree;
24}
25exports.source = source;
26/**
27 * A source that returns an empty tree.
28 */
29function empty() {
30 return () => static_1.empty();
31}
32exports.empty = empty;
33/**
34 * Chain multiple rules into a single rule.
35 */
36function chain(rules) {
37 return (tree, context) => {
38 return rules.reduce((acc, curr) => call_1.callRule(curr, acc, context), tree);
39 };
40}
41exports.chain = chain;
42/**
43 * Apply multiple rules to a source, and returns the source transformed.
44 */
45function apply(source, rules) {
46 return (context) => call_1.callRule(chain(rules), call_1.callSource(source, context), context);
47}
48exports.apply = apply;
49/**
50 * Merge an input tree with the source passed in.
51 */
52function mergeWith(source, strategy = interface_1.MergeStrategy.Default) {
53 return (tree, context) => {
54 return call_1.callSource(source, context).pipe(operators_1.map((sourceTree) => tree.merge(sourceTree, strategy || context.strategy)), operators_1.mapTo(tree));
55 };
56}
57exports.mergeWith = mergeWith;
58function noop() {
59 return () => { };
60}
61exports.noop = noop;
62function filter(predicate) {
63 return (tree) => {
64 if (host_tree_1.HostTree.isHostTree(tree)) {
65 return new host_tree_1.FilterHostTree(tree, predicate);
66 }
67 else {
68 throw new exception_1.SchematicsException('Tree type is not supported.');
69 }
70 };
71}
72exports.filter = filter;
73function asSource(rule) {
74 return (context) => call_1.callRule(rule, static_1.empty(), context);
75}
76exports.asSource = asSource;
77function branchAndMerge(rule, strategy = interface_1.MergeStrategy.Default) {
78 return (tree, context) => {
79 return call_1.callRule(rule, tree.branch(), context).pipe(operators_1.map((branch) => tree.merge(branch, strategy || context.strategy)), operators_1.mapTo(tree));
80 };
81}
82exports.branchAndMerge = branchAndMerge;
83function when(predicate, operator) {
84 return (entry) => {
85 if (predicate(entry.path, entry)) {
86 return operator(entry);
87 }
88 else {
89 return entry;
90 }
91 };
92}
93exports.when = when;
94function partitionApplyMerge(predicate, ruleYes, ruleNo) {
95 return (tree, context) => {
96 const [yes, no] = static_1.partition(tree, predicate);
97 return rxjs_1.concat(call_1.callRule(ruleYes, yes, context), call_1.callRule(ruleNo || noop(), no, context)).pipe(operators_1.toArray(), operators_1.map(([yesTree, noTree]) => {
98 yesTree.merge(noTree, context.strategy);
99 return yesTree;
100 }));
101 };
102}
103exports.partitionApplyMerge = partitionApplyMerge;
104function forEach(operator) {
105 return (tree) => {
106 tree.visit((path, entry) => {
107 if (!entry) {
108 return;
109 }
110 const newEntry = operator(entry);
111 if (newEntry === entry) {
112 return;
113 }
114 if (newEntry === null) {
115 tree.delete(path);
116 return;
117 }
118 if (newEntry.path != path) {
119 tree.rename(path, newEntry.path);
120 }
121 if (!newEntry.content.equals(entry.content)) {
122 tree.overwrite(newEntry.path, newEntry.content);
123 }
124 });
125 };
126}
127exports.forEach = forEach;
128function composeFileOperators(operators) {
129 return (entry) => {
130 let current = entry;
131 for (const op of operators) {
132 current = op(current);
133 if (current === null) {
134 // Deleted, just return.
135 return null;
136 }
137 }
138 return current;
139 };
140}
141exports.composeFileOperators = composeFileOperators;
142function applyToSubtree(path, rules) {
143 return (tree, context) => {
144 const scoped = new scoped_1.ScopedTree(tree, path);
145 return call_1.callRule(chain(rules), scoped, context).pipe(operators_1.map((result) => {
146 if (result === scoped) {
147 return tree;
148 }
149 else {
150 throw new exception_1.SchematicsException('Original tree must be returned from all rules when using "applyToSubtree".');
151 }
152 }));
153 };
154}
155exports.applyToSubtree = applyToSubtree;
Note: See TracBrowser for help on using the repository browser.