1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | Object.defineProperty(exports, "__esModule", { value: true });
|
11 | exports.TemplateLiteralFile = void 0;
|
12 | const mrm_core_1 = require("mrm-core");
|
13 | const File_1 = require("../Base/File");
|
14 |
|
15 |
|
16 |
|
17 | class TemplateLiteralFile extends File_1.File {
|
18 | constructor(basePath, filename, templatePath) {
|
19 | super(basePath);
|
20 | this.actions = [];
|
21 | this.removeOnRollback = true;
|
22 | this.overwrite = false;
|
23 | this.cdIn();
|
24 | this.filePointer = (0, mrm_core_1.template)(filename, templatePath);
|
25 | this.cdOut();
|
26 | }
|
27 | |
28 |
|
29 |
|
30 | get() {
|
31 | return this.filePointer.get();
|
32 | }
|
33 | |
34 |
|
35 |
|
36 | exists() {
|
37 | return this.filePointer.exists();
|
38 | }
|
39 | |
40 |
|
41 |
|
42 | apply(contents) {
|
43 | this.filePointer.apply(contents);
|
44 | return this;
|
45 | }
|
46 | |
47 |
|
48 |
|
49 | commit() {
|
50 | this.cdIn();
|
51 | |
52 |
|
53 |
|
54 |
|
55 | if (this.filePointer.exists() && !this.overwrite) {
|
56 | this.cdOut();
|
57 | return;
|
58 | }
|
59 | this.filePointer.save();
|
60 | this.cdOut();
|
61 | }
|
62 | |
63 |
|
64 |
|
65 | rollback() {
|
66 | this.cdIn();
|
67 | |
68 |
|
69 |
|
70 |
|
71 | if (this.filePointer.exists() && this.removeOnRollback) {
|
72 | this.filePointer.delete();
|
73 | }
|
74 | this.cdOut();
|
75 | }
|
76 | }
|
77 | exports.TemplateLiteralFile = TemplateLiteralFile;
|