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 | const FIXTURE_DIR = path_1.join(__dirname, '..', 'fixtures');
|
9 | class 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 |
|
34 | }
|
35 | fs.writeFileSync(to, formatted);
|
36 | }
|
37 | else {
|
38 | return formatted;
|
39 | }
|
40 | }
|
41 | }
|
42 | tslib_1.__decorate([
|
43 | typescript_lazy_get_decorator_1.LazyGetter(),
|
44 | tslib_1.__metadata("design:type", String),
|
45 | tslib_1.__metadata("design:paramtypes", [])
|
46 | ], Fixture.prototype, "srcDir", null);
|
47 | exports.Fixture = Fixture;
|