1 | "use strict";
|
2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7 | };
|
8 | var __metadata = (this && this.__metadata) || function (k, v) {
|
9 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
10 | };
|
11 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
12 | return new (P || (P = Promise))(function (resolve, reject) {
|
13 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
14 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
15 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
16 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
17 | });
|
18 | };
|
19 | var __generator = (this && this.__generator) || function (thisArg, body) {
|
20 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
21 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
22 | function verb(n) { return function (v) { return step([n, v]); }; }
|
23 | function step(op) {
|
24 | if (f) throw new TypeError("Generator is already executing.");
|
25 | while (_) try {
|
26 | if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
|
27 | if (y = 0, t) op = [0, t.value];
|
28 | switch (op[0]) {
|
29 | case 0: case 1: t = op; break;
|
30 | case 4: _.label++; return { value: op[1], done: false };
|
31 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
32 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
33 | default:
|
34 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
35 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
36 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
37 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
38 | if (t[2]) _.ops.pop();
|
39 | _.trys.pop(); continue;
|
40 | }
|
41 | op = body.call(thisArg, _);
|
42 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
43 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
44 | }
|
45 | };
|
46 | Object.defineProperty(exports, "__esModule", { value: true });
|
47 | var fs_extra_1 = require("fs-extra");
|
48 | var oly_core_1 = require("oly-core");
|
49 |
|
50 |
|
51 |
|
52 | var FileService = (function () {
|
53 | function FileService() {
|
54 | }
|
55 | |
56 |
|
57 |
|
58 |
|
59 |
|
60 | FileService.prototype.exists = function (filepath) {
|
61 | return __awaiter(this, void 0, void 0, function () {
|
62 | return __generator(this, function (_a) {
|
63 | switch (_a.label) {
|
64 | case 0:
|
65 | this.logger.debug("exists " + filepath);
|
66 | return [4 , new Promise(function (resolve) { return fs_extra_1.exists(filepath, resolve); })];
|
67 | case 1: return [2 , _a.sent()];
|
68 | }
|
69 | });
|
70 | });
|
71 | };
|
72 | FileService.prototype.read = function (filepath, options) {
|
73 | return __awaiter(this, void 0, void 0, function () {
|
74 | return __generator(this, function (_a) {
|
75 | switch (_a.label) {
|
76 | case 0:
|
77 | this.logger.debug("read " + filepath);
|
78 | return [4 , fs_extra_1.readFile(filepath, options)];
|
79 | case 1: return [2 , _a.sent()];
|
80 | }
|
81 | });
|
82 | });
|
83 | };
|
84 | |
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 | FileService.prototype.write = function (filepath, data, options) {
|
92 | if (options === void 0) { options = {}; }
|
93 | return __awaiter(this, void 0, void 0, function () {
|
94 | return __generator(this, function (_a) {
|
95 | switch (_a.label) {
|
96 | case 0:
|
97 | this.logger.debug("write " + filepath);
|
98 | return [4 , fs_extra_1.writeFile(filepath, data)];
|
99 | case 1:
|
100 | _a.sent();
|
101 | return [2 ];
|
102 | }
|
103 | });
|
104 | });
|
105 | };
|
106 | |
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | FileService.prototype.move = function (filepath, destination) {
|
113 | return __awaiter(this, void 0, void 0, function () {
|
114 | return __generator(this, function (_a) {
|
115 | switch (_a.label) {
|
116 | case 0:
|
117 | this.logger.debug("move " + filepath + " to " + destination);
|
118 | return [4 , fs_extra_1.move(filepath, destination)];
|
119 | case 1: return [2 , _a.sent()];
|
120 | }
|
121 | });
|
122 | });
|
123 | };
|
124 | |
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 | FileService.prototype.copy = function (filepath, destination) {
|
131 | return __awaiter(this, void 0, void 0, function () {
|
132 | return __generator(this, function (_a) {
|
133 | switch (_a.label) {
|
134 | case 0:
|
135 | this.logger.debug("copy " + filepath + " to " + destination);
|
136 | return [4 , fs_extra_1.copy(filepath, destination)];
|
137 | case 1: return [2 , _a.sent()];
|
138 | }
|
139 | });
|
140 | });
|
141 | };
|
142 | |
143 |
|
144 |
|
145 |
|
146 |
|
147 | FileService.prototype.remove = function (filepath) {
|
148 | return __awaiter(this, void 0, void 0, function () {
|
149 | return __generator(this, function (_a) {
|
150 | switch (_a.label) {
|
151 | case 0:
|
152 | this.logger.debug("remove " + filepath);
|
153 | return [4 , fs_extra_1.remove(filepath)];
|
154 | case 1: return [2 , _a.sent()];
|
155 | }
|
156 | });
|
157 | });
|
158 | };
|
159 | |
160 |
|
161 |
|
162 |
|
163 |
|
164 | FileService.prototype.mkdirp = function (filepath) {
|
165 | return __awaiter(this, void 0, void 0, function () {
|
166 | return __generator(this, function (_a) {
|
167 | switch (_a.label) {
|
168 | case 0:
|
169 | this.logger.debug("mkdirp " + filepath);
|
170 | return [4 , fs_extra_1.mkdirp(filepath)];
|
171 | case 1: return [2 , _a.sent()];
|
172 | }
|
173 | });
|
174 | });
|
175 | };
|
176 | return FileService;
|
177 | }());
|
178 | __decorate([
|
179 | oly_core_1.inject,
|
180 | __metadata("design:type", oly_core_1.Logger)
|
181 | ], FileService.prototype, "logger", void 0);
|
182 | exports.FileService = FileService;
|
183 |
|
\ | No newline at end of file |