source: trip-planner-front/node_modules/@angular-devkit/schematics/src/sink/host.js@ fa375fe

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

initial commit

  • Property mode set to 100644
File size: 2.8 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.HostSink = void 0;
11const rxjs_1 = require("rxjs");
12const operators_1 = require("rxjs/operators");
13const update_buffer_1 = require("../utility/update-buffer");
14const sink_1 = require("./sink");
15class HostSink extends sink_1.SimpleSinkBase {
16 constructor(_host, _force = false) {
17 super();
18 this._host = _host;
19 this._force = _force;
20 this._filesToDelete = new Set();
21 this._filesToRename = new Set();
22 this._filesToCreate = new Map();
23 this._filesToUpdate = new Map();
24 }
25 _validateCreateAction(action) {
26 return this._force ? rxjs_1.EMPTY : super._validateCreateAction(action);
27 }
28 _validateFileExists(p) {
29 if (this._filesToCreate.has(p) || this._filesToUpdate.has(p)) {
30 return rxjs_1.of(true);
31 }
32 if (this._filesToDelete.has(p)) {
33 return rxjs_1.of(false);
34 }
35 for (const [from, to] of this._filesToRename.values()) {
36 switch (p) {
37 case from:
38 return rxjs_1.of(false);
39 case to:
40 return rxjs_1.of(true);
41 }
42 }
43 return this._host.exists(p);
44 }
45 _overwriteFile(path, content) {
46 this._filesToUpdate.set(path, new update_buffer_1.UpdateBuffer(content));
47 return rxjs_1.EMPTY;
48 }
49 _createFile(path, content) {
50 this._filesToCreate.set(path, new update_buffer_1.UpdateBuffer(content));
51 return rxjs_1.EMPTY;
52 }
53 _renameFile(from, to) {
54 this._filesToRename.add([from, to]);
55 return rxjs_1.EMPTY;
56 }
57 _deleteFile(path) {
58 if (this._filesToCreate.has(path)) {
59 this._filesToCreate.delete(path);
60 this._filesToUpdate.delete(path);
61 }
62 else {
63 this._filesToDelete.add(path);
64 }
65 return rxjs_1.EMPTY;
66 }
67 _done() {
68 // Really commit everything to the actual filesystem.
69 return rxjs_1.concat(rxjs_1.from([...this._filesToDelete.values()]).pipe(operators_1.concatMap((path) => this._host.delete(path))), rxjs_1.from([...this._filesToRename.entries()]).pipe(operators_1.concatMap(([_, [path, to]]) => this._host.rename(path, to))), rxjs_1.from([...this._filesToCreate.entries()]).pipe(operators_1.concatMap(([path, buffer]) => {
70 return this._host.write(path, buffer.generate());
71 })), rxjs_1.from([...this._filesToUpdate.entries()]).pipe(operators_1.concatMap(([path, buffer]) => {
72 return this._host.write(path, buffer.generate());
73 }))).pipe(operators_1.reduce(() => { }));
74 }
75}
76exports.HostSink = HostSink;
Note: See TracBrowser for help on using the repository browser.