UNPKG

1.14 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const tslib_1 = require("tslib");
4const fs = require("fs-extra");
5const lodash_1 = require("lodash");
6const path_1 = require("path");
7const typescript_lazy_get_decorator_1 = require("typescript-lazy-get-decorator");
8class 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 // noop
32 }
33 }
34}
35tslib_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);
40exports.AbstractReadWriter = AbstractReadWriter;