@jam-comments/server-utilities 5.5.0 → 5.7.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.
- package/dist/cjs/markupFetcher.js +11 -5
- package/dist/cjs/nodeUtils.js +17 -13
- package/dist/esm/markupFetcher.js +11 -5
- package/dist/esm/nodeUtils.js +17 -13
- package/dist/types/nodeUtils.d.ts +4 -5
- package/package.json +1 -1
|
@@ -125,14 +125,20 @@ function markupFetcher(platform, fetchImplementation = fetch) {
|
|
|
125
125
|
return async ({ tz = undefined, path, domain, apiKey, schema, dateFormat, baseUrl = BASE_URL, environment = (0, utils_1.getEnvironment)(), copy = {}, }) => {
|
|
126
126
|
path = path || "/";
|
|
127
127
|
const savedFile = await (async () => {
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
try {
|
|
129
|
+
if (typeof process === "undefined") {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
const { tempDirectoryExists, readFile, getEmptyMarkup } = await Promise.resolve().then(() => __importStar(require("./nodeUtils")));
|
|
133
|
+
if (!(await tempDirectoryExists())) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
return (await readFile(path)) || getEmptyMarkup();
|
|
130
137
|
}
|
|
131
|
-
|
|
132
|
-
|
|
138
|
+
catch (e) {
|
|
139
|
+
console.error(e);
|
|
133
140
|
return null;
|
|
134
141
|
}
|
|
135
|
-
return (await readFile(path)) || getEmptyMarkup();
|
|
136
142
|
})();
|
|
137
143
|
const markup = savedFile
|
|
138
144
|
? savedFile
|
package/dist/cjs/nodeUtils.js
CHANGED
|
@@ -30,7 +30,6 @@ exports.readFile = readFile;
|
|
|
30
30
|
exports.getEmptyMarkup = getEmptyMarkup;
|
|
31
31
|
exports.tempDirectoryExists = tempDirectoryExists;
|
|
32
32
|
exports.saveFile = saveFile;
|
|
33
|
-
const fs_1 = require("fs");
|
|
34
33
|
const utils_1 = require("./utils");
|
|
35
34
|
async function getTempDirectory() {
|
|
36
35
|
const path = await Promise.resolve().then(() => __importStar(require("path")));
|
|
@@ -38,20 +37,23 @@ async function getTempDirectory() {
|
|
|
38
37
|
}
|
|
39
38
|
async function deleteTempDirectory() {
|
|
40
39
|
const tempDirectory = await getTempDirectory();
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
const fs = await Promise.resolve().then(() => __importStar(require("fs")));
|
|
41
|
+
if (fs.existsSync(tempDirectory)) {
|
|
42
|
+
fs.rmdirSync(tempDirectory, { recursive: true });
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
async function createTempDirectory(mkdirSyncImpl
|
|
45
|
+
async function createTempDirectory(mkdirSyncImpl, existsSyncImpl) {
|
|
46
46
|
const tempDirectory = await getTempDirectory();
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
const fs = await Promise.resolve().then(() => __importStar(require("fs")));
|
|
48
|
+
if (!(await tempDirectoryExists(existsSyncImpl || fs.existsSync))) {
|
|
49
|
+
(mkdirSyncImpl || fs.mkdirSync)(tempDirectory);
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
|
-
async function readFile(name, readFileSyncImpl
|
|
52
|
+
async function readFile(name, readFileSyncImpl) {
|
|
52
53
|
const fileName = (0, utils_1.toSavedFileName)(name);
|
|
54
|
+
const fs = await Promise.resolve().then(() => __importStar(require("fs")));
|
|
53
55
|
try {
|
|
54
|
-
return readFileSyncImpl(`${await getTempDirectory()}/${fileName}`, "utf8");
|
|
56
|
+
return (readFileSyncImpl || fs.readFileSync)(`${await getTempDirectory()}/${fileName}`, "utf8");
|
|
55
57
|
}
|
|
56
58
|
catch (error) {
|
|
57
59
|
return null;
|
|
@@ -60,14 +62,16 @@ async function readFile(name, readFileSyncImpl = fs_1.readFileSync) {
|
|
|
60
62
|
function getEmptyMarkup() {
|
|
61
63
|
return readFile("EMPTY");
|
|
62
64
|
}
|
|
63
|
-
async function tempDirectoryExists(existsSyncImpl
|
|
64
|
-
|
|
65
|
+
async function tempDirectoryExists(existsSyncImpl) {
|
|
66
|
+
const fs = await Promise.resolve().then(() => __importStar(require("fs")));
|
|
67
|
+
return (existsSyncImpl || fs.existsSync)(await getTempDirectory());
|
|
65
68
|
}
|
|
66
|
-
async function saveFile(name, data, writeFileImpl
|
|
69
|
+
async function saveFile(name, data, writeFileImpl) {
|
|
67
70
|
const fileName = (0, utils_1.toSavedFileName)(name);
|
|
68
71
|
const tempDirectory = await getTempDirectory();
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
const fs = await Promise.resolve().then(() => __importStar(require("fs")));
|
|
73
|
+
return new Promise((resolve) => {
|
|
74
|
+
(writeFileImpl || fs.writeFile)(`${tempDirectory}/${fileName}`, data, () => {
|
|
71
75
|
resolve();
|
|
72
76
|
});
|
|
73
77
|
});
|
|
@@ -95,14 +95,20 @@ export function markupFetcher(platform, fetchImplementation = fetch) {
|
|
|
95
95
|
return async ({ tz = undefined, path, domain, apiKey, schema, dateFormat, baseUrl = BASE_URL, environment = getEnvironment(), copy = {}, }) => {
|
|
96
96
|
path = path || "/";
|
|
97
97
|
const savedFile = await (async () => {
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
try {
|
|
99
|
+
if (typeof process === "undefined") {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
const { tempDirectoryExists, readFile, getEmptyMarkup } = await import("./nodeUtils");
|
|
103
|
+
if (!(await tempDirectoryExists())) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
return (await readFile(path)) || getEmptyMarkup();
|
|
100
107
|
}
|
|
101
|
-
|
|
102
|
-
|
|
108
|
+
catch (e) {
|
|
109
|
+
console.error(e);
|
|
103
110
|
return null;
|
|
104
111
|
}
|
|
105
|
-
return (await readFile(path)) || getEmptyMarkup();
|
|
106
112
|
})();
|
|
107
113
|
const markup = savedFile
|
|
108
114
|
? savedFile
|
package/dist/esm/nodeUtils.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, rmdirSync, writeFile } from "fs";
|
|
2
1
|
import { toSavedFileName } from "./utils";
|
|
3
2
|
export async function getTempDirectory() {
|
|
4
3
|
const path = await import("path");
|
|
@@ -6,20 +5,23 @@ export async function getTempDirectory() {
|
|
|
6
5
|
}
|
|
7
6
|
export async function deleteTempDirectory() {
|
|
8
7
|
const tempDirectory = await getTempDirectory();
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const fs = await import("fs");
|
|
9
|
+
if (fs.existsSync(tempDirectory)) {
|
|
10
|
+
fs.rmdirSync(tempDirectory, { recursive: true });
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
export async function createTempDirectory(mkdirSyncImpl
|
|
13
|
+
export async function createTempDirectory(mkdirSyncImpl, existsSyncImpl) {
|
|
14
14
|
const tempDirectory = await getTempDirectory();
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const fs = await import("fs");
|
|
16
|
+
if (!(await tempDirectoryExists(existsSyncImpl || fs.existsSync))) {
|
|
17
|
+
(mkdirSyncImpl || fs.mkdirSync)(tempDirectory);
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
|
-
export async function readFile(name, readFileSyncImpl
|
|
20
|
+
export async function readFile(name, readFileSyncImpl) {
|
|
20
21
|
const fileName = toSavedFileName(name);
|
|
22
|
+
const fs = await import("fs");
|
|
21
23
|
try {
|
|
22
|
-
return readFileSyncImpl(`${await getTempDirectory()}/${fileName}`, "utf8");
|
|
24
|
+
return (readFileSyncImpl || fs.readFileSync)(`${await getTempDirectory()}/${fileName}`, "utf8");
|
|
23
25
|
}
|
|
24
26
|
catch (error) {
|
|
25
27
|
return null;
|
|
@@ -28,14 +30,16 @@ export async function readFile(name, readFileSyncImpl = readFileSync) {
|
|
|
28
30
|
export function getEmptyMarkup() {
|
|
29
31
|
return readFile("EMPTY");
|
|
30
32
|
}
|
|
31
|
-
export async function tempDirectoryExists(existsSyncImpl
|
|
32
|
-
|
|
33
|
+
export async function tempDirectoryExists(existsSyncImpl) {
|
|
34
|
+
const fs = await import("fs");
|
|
35
|
+
return (existsSyncImpl || fs.existsSync)(await getTempDirectory());
|
|
33
36
|
}
|
|
34
|
-
export async function saveFile(name, data, writeFileImpl
|
|
37
|
+
export async function saveFile(name, data, writeFileImpl) {
|
|
35
38
|
const fileName = toSavedFileName(name);
|
|
36
39
|
const tempDirectory = await getTempDirectory();
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
const fs = await import("fs");
|
|
41
|
+
return new Promise((resolve) => {
|
|
42
|
+
(writeFileImpl || fs.writeFile)(`${tempDirectory}/${fileName}`, data, () => {
|
|
39
43
|
resolve();
|
|
40
44
|
});
|
|
41
45
|
});
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync } from "fs";
|
|
2
1
|
export declare function getTempDirectory(): Promise<string>;
|
|
3
2
|
export declare function deleteTempDirectory(): Promise<void>;
|
|
4
|
-
export declare function createTempDirectory(mkdirSyncImpl?: typeof mkdirSync, existsSyncImpl?: typeof existsSync): Promise<void>;
|
|
5
|
-
export declare function readFile(name:
|
|
3
|
+
export declare function createTempDirectory(mkdirSyncImpl?: typeof import("fs").mkdirSync, existsSyncImpl?: typeof import("fs").existsSync): Promise<void>;
|
|
4
|
+
export declare function readFile(name: string, readFileSyncImpl?: typeof import("fs").readFileSync): Promise<string>;
|
|
6
5
|
export declare function getEmptyMarkup(): Promise<string>;
|
|
7
|
-
export declare function tempDirectoryExists(existsSyncImpl?: typeof existsSync): Promise<boolean>;
|
|
8
|
-
export declare function saveFile(name: string, data: string, writeFileImpl?:
|
|
6
|
+
export declare function tempDirectoryExists(existsSyncImpl?: typeof import("fs").existsSync): Promise<boolean>;
|
|
7
|
+
export declare function saveFile(name: string, data: string, writeFileImpl?: typeof import("fs").writeFile): Promise<void>;
|