1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const fs_1 = __importDefault(require("fs"));
|
7 | const fast_glob_1 = __importDefault(require("fast-glob"));
|
8 | const path_1 = __importDefault(require("path"));
|
9 | const tmp_1 = __importDefault(require("tmp"));
|
10 | const errors_1 = require("./errors");
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | class Doer {
|
16 | constructor(urlFetcher, folder) {
|
17 | if (!folder)
|
18 | folder = tmp_1.default.dirSync().name;
|
19 | this.folder = folder;
|
20 | this.urlFetcher = urlFetcher;
|
21 | }
|
22 | |
23 |
|
24 |
|
25 |
|
26 |
|
27 | exists(subpath) {
|
28 | return fs_1.default.existsSync(path_1.default.join(this.folder, subpath));
|
29 | }
|
30 | |
31 |
|
32 |
|
33 |
|
34 |
|
35 | glob(pattern) {
|
36 | try {
|
37 | return fast_glob_1.default.sync(pattern, {
|
38 | cwd: this.folder
|
39 | });
|
40 | }
|
41 | catch (error) {
|
42 | if (error.code === 'EACCES') {
|
43 | throw new errors_1.PermissionError(`You do no have permission to access the whole of folder "${this.folder}". Are you sure you want Dockter to compile this folder?`);
|
44 | }
|
45 | else
|
46 | throw error;
|
47 | }
|
48 | }
|
49 | |
50 |
|
51 |
|
52 |
|
53 |
|
54 | read(subpath) {
|
55 | return fs_1.default.readFileSync(path_1.default.join(this.folder, subpath), 'utf8');
|
56 | }
|
57 | |
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | write(subpath, content) {
|
64 | fs_1.default.writeFileSync(path_1.default.join(this.folder, subpath), content, 'utf8');
|
65 | }
|
66 | |
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | async fetch(url, options = { json: true }) {
|
73 | return this.urlFetcher.fetchUrl(url, options);
|
74 | }
|
75 | }
|
76 | exports.default = Doer;
|