UNPKG

2.93 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.DryRunSink = void 0;
11const core_1 = require("@angular-devkit/core");
12const node_1 = require("@angular-devkit/core/node");
13const rxjs_1 = require("rxjs");
14const host_1 = require("./host");
15class DryRunSink extends host_1.HostSink {
16 constructor(host, force = false) {
17 super(typeof host == 'string'
18 ? new core_1.virtualFs.ScopedHost(new node_1.NodeJsSyncHost(), (0, core_1.normalize)(host))
19 : host, force);
20 this._subject = new rxjs_1.Subject();
21 this._fileDoesNotExistExceptionSet = new Set();
22 this._fileAlreadyExistExceptionSet = new Set();
23 this.reporter = this._subject.asObservable();
24 }
25 _fileAlreadyExistException(path) {
26 this._fileAlreadyExistExceptionSet.add(path);
27 }
28 _fileDoesNotExistException(path) {
29 this._fileDoesNotExistExceptionSet.add(path);
30 }
31 _done() {
32 this._fileAlreadyExistExceptionSet.forEach((path) => {
33 this._subject.next({
34 kind: 'error',
35 description: 'alreadyExist',
36 path,
37 });
38 });
39 this._fileDoesNotExistExceptionSet.forEach((path) => {
40 this._subject.next({
41 kind: 'error',
42 description: 'doesNotExist',
43 path,
44 });
45 });
46 this._filesToDelete.forEach((path) => {
47 // Check if this is a renaming.
48 for (const [from] of this._filesToRename) {
49 if (from == path) {
50 // The event is sent later on.
51 return;
52 }
53 }
54 this._subject.next({ kind: 'delete', path });
55 });
56 this._filesToRename.forEach(([path, to]) => {
57 this._subject.next({ kind: 'rename', path, to });
58 });
59 this._filesToCreate.forEach((content, path) => {
60 // Check if this is a renaming.
61 for (const [, to] of this._filesToRename) {
62 if (to == path) {
63 // The event is sent later on.
64 return;
65 }
66 }
67 if (this._fileAlreadyExistExceptionSet.has(path) ||
68 this._fileDoesNotExistExceptionSet.has(path)) {
69 return;
70 }
71 this._subject.next({ kind: 'create', path, content: content.generate() });
72 });
73 this._filesToUpdate.forEach((content, path) => {
74 this._subject.next({ kind: 'update', path, content: content.generate() });
75 });
76 this._subject.complete();
77 return (0, rxjs_1.of)(undefined);
78 }
79}
80exports.DryRunSink = DryRunSink;