source: trip-planner-front/node_modules/@angular-devkit/schematics/src/tree/scoped.js

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

initial commit

  • Property mode set to 100644
File size: 5.3 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.ScopedTree = void 0;
11const core_1 = require("@angular-devkit/core");
12const delegate_1 = require("./delegate");
13const interface_1 = require("./interface");
14class ScopedFileEntry {
15 constructor(_base, scope) {
16 this._base = _base;
17 this.scope = scope;
18 }
19 get path() {
20 return core_1.join(core_1.NormalizedRoot, core_1.relative(this.scope, this._base.path));
21 }
22 get content() {
23 return this._base.content;
24 }
25}
26class ScopedDirEntry {
27 constructor(_base, scope) {
28 this._base = _base;
29 this.scope = scope;
30 }
31 get parent() {
32 if (!this._base.parent || this._base.path == this.scope) {
33 return null;
34 }
35 return new ScopedDirEntry(this._base.parent, this.scope);
36 }
37 get path() {
38 return core_1.join(core_1.NormalizedRoot, core_1.relative(this.scope, this._base.path));
39 }
40 get subdirs() {
41 return this._base.subdirs;
42 }
43 get subfiles() {
44 return this._base.subfiles;
45 }
46 dir(name) {
47 const entry = this._base.dir(name);
48 return entry && new ScopedDirEntry(entry, this.scope);
49 }
50 file(name) {
51 const entry = this._base.file(name);
52 return entry && new ScopedFileEntry(entry, this.scope);
53 }
54 visit(visitor) {
55 return this._base.visit((path, entry) => {
56 visitor(core_1.join(core_1.NormalizedRoot, core_1.relative(this.scope, path)), entry && new ScopedFileEntry(entry, this.scope));
57 });
58 }
59}
60class ScopedTree {
61 constructor(_base, scope) {
62 this._base = _base;
63 const normalizedScope = core_1.normalize('/' + scope);
64 this._root = new ScopedDirEntry(this._base.getDir(normalizedScope), normalizedScope);
65 }
66 get root() {
67 return this._root;
68 }
69 branch() {
70 return new ScopedTree(this._base.branch(), this._root.scope);
71 }
72 merge(other, strategy) {
73 // eslint-disable-next-line @typescript-eslint/no-this-alias
74 const self = this;
75 const delegate = new (class extends delegate_1.DelegateTree {
76 get actions() {
77 return other.actions.map((action) => self._fullPathAction(action));
78 }
79 })(other);
80 this._base.merge(delegate, strategy);
81 }
82 // Readonly.
83 read(path) {
84 return this._base.read(this._fullPath(path));
85 }
86 exists(path) {
87 return this._base.exists(this._fullPath(path));
88 }
89 get(path) {
90 const entry = this._base.get(this._fullPath(path));
91 return entry && new ScopedFileEntry(entry, this._root.scope);
92 }
93 getDir(path) {
94 const entry = this._base.getDir(this._fullPath(path));
95 return entry && new ScopedDirEntry(entry, this._root.scope);
96 }
97 visit(visitor) {
98 return this._root.visit(visitor);
99 }
100 // Change content of host files.
101 overwrite(path, content) {
102 return this._base.overwrite(this._fullPath(path), content);
103 }
104 beginUpdate(path) {
105 return this._base.beginUpdate(this._fullPath(path));
106 }
107 commitUpdate(record) {
108 return this._base.commitUpdate(record);
109 }
110 // Structural methods.
111 create(path, content) {
112 return this._base.create(this._fullPath(path), content);
113 }
114 delete(path) {
115 return this._base.delete(this._fullPath(path));
116 }
117 rename(from, to) {
118 return this._base.rename(this._fullPath(from), this._fullPath(to));
119 }
120 apply(action, strategy) {
121 return this._base.apply(this._fullPathAction(action), strategy);
122 }
123 get actions() {
124 const scopedActions = [];
125 for (const action of this._base.actions) {
126 if (!action.path.startsWith(this._root.scope + '/')) {
127 continue;
128 }
129 if (action.kind !== 'r') {
130 scopedActions.push({
131 ...action,
132 path: core_1.join(core_1.NormalizedRoot, core_1.relative(this._root.scope, action.path)),
133 });
134 }
135 else if (action.to.startsWith(this._root.scope + '/')) {
136 scopedActions.push({
137 ...action,
138 path: core_1.join(core_1.NormalizedRoot, core_1.relative(this._root.scope, action.path)),
139 to: core_1.join(core_1.NormalizedRoot, core_1.relative(this._root.scope, action.to)),
140 });
141 }
142 }
143 return scopedActions;
144 }
145 [interface_1.TreeSymbol]() {
146 return this;
147 }
148 _fullPath(path) {
149 return core_1.join(this._root.scope, core_1.normalize('/' + path));
150 }
151 _fullPathAction(action) {
152 let fullPathAction;
153 if (action.kind === 'r') {
154 fullPathAction = {
155 ...action,
156 path: this._fullPath(action.path),
157 to: this._fullPath(action.to),
158 };
159 }
160 else {
161 fullPathAction = {
162 ...action,
163 path: this._fullPath(action.path),
164 };
165 }
166 return fullPathAction;
167 }
168}
169exports.ScopedTree = ScopedTree;
Note: See TracBrowser for help on using the repository browser.