UNPKG

1.41 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const tslib_1 = require("tslib");
4const fs = require("fs-extra");
5const lazy_get_decorator_1 = require("lazy-get-decorator");
6const lodash_1 = require("lodash");
7const path_1 = require("path");
8const FIXTURE_DIR = path_1.join(__dirname, '..', 'fixtures');
9class Fixture {
10 constructor(feature) {
11 this.feature = feature;
12 }
13 get srcDir() {
14 return path_1.join(FIXTURE_DIR, this.feature);
15 }
16 copy(from, to, chmod) {
17 fs.copySync(path_1.join(this.srcDir, from), to);
18 if (chmod !== undefined) {
19 fs.chmodSync(to, chmod);
20 }
21 }
22 read(from) {
23 return fs.readFileSync(path_1.join(this.srcDir, from));
24 }
25 template(from, tpl, to) {
26 const compiled = lodash_1.template(this.read(from).toString().trim());
27 const formatted = compiled(tpl) + '\n';
28 if (to) {
29 try {
30 fs.mkdirpSync(path_1.dirname(to));
31 }
32 catch (_a) {
33 //noop
34 }
35 fs.writeFileSync(to, formatted);
36 }
37 else {
38 return formatted;
39 }
40 }
41}
42tslib_1.__decorate([
43 lazy_get_decorator_1.LazyGetter(),
44 tslib_1.__metadata("design:type", String),
45 tslib_1.__metadata("design:paramtypes", [])
46], Fixture.prototype, "srcDir", null);
47exports.Fixture = Fixture;