@datatruck/cli 0.26.1 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocalFs = exports.AbstractFs = exports.resolvePath = void 0;
4
+ const fs_1 = require("./fs");
5
+ const promises_1 = require("fs/promises");
6
+ const path_1 = require("path");
7
+ function resolvePath(path) {
8
+ const { pathname } = new URL(`file:///${path}`);
9
+ return pathname;
10
+ }
11
+ exports.resolvePath = resolvePath;
12
+ class AbstractFs {
13
+ options;
14
+ constructor(options) {
15
+ this.options = options;
16
+ }
17
+ resolvePath(path) {
18
+ return (0, path_1.resolve)((0, path_1.join)(this.options.backend ?? ".", resolvePath(path)));
19
+ }
20
+ }
21
+ exports.AbstractFs = AbstractFs;
22
+ class LocalFs extends AbstractFs {
23
+ isLocal() {
24
+ return true;
25
+ }
26
+ async existsDir(path) {
27
+ return (0, fs_1.existsDir)(this.resolvePath(path));
28
+ }
29
+ async mkdir(path) {
30
+ await (0, fs_1.mkdirIfNotExists)(this.resolvePath(path));
31
+ }
32
+ async ensureEmptyDir(path) {
33
+ await (0, fs_1.ensureEmptyDir)(this.resolvePath(path));
34
+ }
35
+ async readFile(path) {
36
+ return (await (0, promises_1.readFile)(this.resolvePath(path))).toString();
37
+ }
38
+ async readFileIfExists(inPath) {
39
+ return (await (0, fs_1.existsFile)(this.resolvePath(inPath)))
40
+ ? await this.readFile(inPath)
41
+ : undefined;
42
+ }
43
+ async readdir(path) {
44
+ return await (0, promises_1.readdir)(this.resolvePath(path));
45
+ }
46
+ async writeFile(path, contents) {
47
+ await (0, promises_1.writeFile)(this.resolvePath(path), contents);
48
+ }
49
+ async rmAll(path) {
50
+ await (0, promises_1.rm)(this.resolvePath(path), { recursive: true });
51
+ }
52
+ async upload(source, target) {
53
+ await (0, promises_1.cp)(source, this.resolvePath(target));
54
+ }
55
+ async download(source, target) {
56
+ await (0, promises_1.cp)(this.resolvePath(source), target);
57
+ }
58
+ }
59
+ exports.LocalFs = LocalFs;