@tinacms/datalayer 1.0.0 → 1.0.1
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.
|
@@ -18,13 +18,15 @@ import type { Bridge } from './index';
|
|
|
18
18
|
*/
|
|
19
19
|
export declare class FilesystemBridge implements Bridge {
|
|
20
20
|
rootPath: string;
|
|
21
|
+
outputPath?: string;
|
|
21
22
|
constructor(rootPath: string);
|
|
23
|
+
addOutputPath(outputPath: string): void;
|
|
22
24
|
glob(pattern: string, extension: string): Promise<string[]>;
|
|
23
25
|
supportsBuilding(): boolean;
|
|
24
26
|
delete(filepath: string): Promise<void>;
|
|
25
27
|
get(filepath: string): Promise<string>;
|
|
26
28
|
putConfig(filepath: string, data: string): Promise<void>;
|
|
27
|
-
put(filepath: string, data: string): Promise<void>;
|
|
29
|
+
put(filepath: string, data: string, basePathOverride?: string): Promise<void>;
|
|
28
30
|
}
|
|
29
31
|
/**
|
|
30
32
|
* Same as the `FileSystemBridge` except it does not save files
|
|
@@ -21,4 +21,10 @@ export interface Bridge {
|
|
|
21
21
|
*/
|
|
22
22
|
supportsBuilding(): boolean;
|
|
23
23
|
putConfig(filepath: string, data: string): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Optionally, the bridge can perform
|
|
26
|
+
* operations in a separate path.
|
|
27
|
+
*/
|
|
28
|
+
outputPath?: string;
|
|
29
|
+
addOutputPath?(outputPath: string): void;
|
|
24
30
|
}
|
package/dist/index.js
CHANGED
|
@@ -81,13 +81,17 @@ var import_normalize_path = __toModule(require("normalize-path"));
|
|
|
81
81
|
var FilesystemBridge = class {
|
|
82
82
|
constructor(rootPath) {
|
|
83
83
|
this.rootPath = rootPath || "";
|
|
84
|
+
this.outputPath = rootPath || "";
|
|
85
|
+
}
|
|
86
|
+
addOutputPath(outputPath) {
|
|
87
|
+
this.outputPath = outputPath;
|
|
84
88
|
}
|
|
85
89
|
async glob(pattern, extension) {
|
|
86
|
-
const basePath = import_path.default.join(this.
|
|
90
|
+
const basePath = import_path.default.join(this.outputPath, ...pattern.split("/"));
|
|
87
91
|
const items = await (0, import_fast_glob.default)(import_path.default.join(basePath, "**", `/*${extension}`).replace(/\\/g, "/"), {
|
|
88
92
|
dot: true
|
|
89
93
|
});
|
|
90
|
-
const posixRootPath = (0, import_normalize_path.default)(this.
|
|
94
|
+
const posixRootPath = (0, import_normalize_path.default)(this.outputPath);
|
|
91
95
|
return items.map((item) => {
|
|
92
96
|
return item.replace(posixRootPath, "").replace(/^\/|\/$/g, "");
|
|
93
97
|
});
|
|
@@ -96,16 +100,22 @@ var FilesystemBridge = class {
|
|
|
96
100
|
return true;
|
|
97
101
|
}
|
|
98
102
|
async delete(filepath) {
|
|
99
|
-
await import_fs_extra.default.remove(import_path.default.join(this.
|
|
103
|
+
await import_fs_extra.default.remove(import_path.default.join(this.outputPath, filepath));
|
|
100
104
|
}
|
|
101
105
|
async get(filepath) {
|
|
102
|
-
return import_fs_extra.default.readFileSync(import_path.default.join(this.
|
|
106
|
+
return import_fs_extra.default.readFileSync(import_path.default.join(this.outputPath, filepath)).toString();
|
|
103
107
|
}
|
|
104
108
|
async putConfig(filepath, data) {
|
|
105
|
-
|
|
109
|
+
if (this.rootPath !== this.outputPath) {
|
|
110
|
+
await this.put(filepath, data);
|
|
111
|
+
await this.put(filepath, data, this.rootPath);
|
|
112
|
+
} else {
|
|
113
|
+
await this.put(filepath, data);
|
|
114
|
+
}
|
|
106
115
|
}
|
|
107
|
-
async put(filepath, data) {
|
|
108
|
-
|
|
116
|
+
async put(filepath, data, basePathOverride) {
|
|
117
|
+
const basePath = basePathOverride || this.outputPath;
|
|
118
|
+
await import_fs_extra.default.outputFileSync(import_path.default.join(basePath, filepath), data);
|
|
109
119
|
}
|
|
110
120
|
};
|
|
111
121
|
var AuditFileSystemBridge = class extends FilesystemBridge {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/datalayer",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"directory": "packages/@tinacms/datalayer"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@tinacms/scripts": "1.0.
|
|
50
|
+
"@tinacms/scripts": "1.0.1",
|
|
51
51
|
"@types/fs-extra": "^9.0.2",
|
|
52
52
|
"@types/jest": "^27.4.1",
|
|
53
53
|
"@types/js-yaml": "^3.12.5",
|