1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const fs = require("fs-extra");
|
5 | const lodash_1 = require("lodash");
|
6 | const path_1 = require("path");
|
7 | const typescript_lazy_get_decorator_1 = require("typescript-lazy-get-decorator");
|
8 | class AbstractReadWriter {
|
9 | constructor(filepath) {
|
10 | this.file = filepath;
|
11 | }
|
12 | get dirname() {
|
13 | if (this.file) {
|
14 | return path_1.dirname(this.file);
|
15 | }
|
16 | else {
|
17 | throw new Error('Unable to get dirname: file not set');
|
18 | }
|
19 | }
|
20 | save() {
|
21 | this.mkdirp();
|
22 | fs.writeFileSync(this.file, this.toString());
|
23 | return this;
|
24 | }
|
25 | mkdirp() {
|
26 | lodash_1.noop(this.dirname);
|
27 | try {
|
28 | fs.mkdirpSync(this.dirname);
|
29 | }
|
30 | catch (_a) {
|
31 |
|
32 | }
|
33 | }
|
34 | }
|
35 | tslib_1.__decorate([
|
36 | typescript_lazy_get_decorator_1.LazyGetter(),
|
37 | tslib_1.__metadata("design:type", String),
|
38 | tslib_1.__metadata("design:paramtypes", [])
|
39 | ], AbstractReadWriter.prototype, "dirname", null);
|
40 | exports.AbstractReadWriter = AbstractReadWriter;
|