xjs-common 9.0.3 → 9.1.0-alpha.3
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/func/u-file.d.ts
CHANGED
|
@@ -34,6 +34,13 @@ export declare namespace UFile {
|
|
|
34
34
|
* @returns exportable file path.
|
|
35
35
|
*/
|
|
36
36
|
function reserveFilePath(dir: MaybeArray<string>, fname: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* decompress zip file. this depends on os enviroment due to using the os command.
|
|
39
|
+
* currently this supports only windows (installed `tar` or `unzip` in gnu compiler) and linux systems (installed `unzip`).
|
|
40
|
+
* @param zipPath zip file to be unzipped.
|
|
41
|
+
* @param destDir directory that the decompress files export to.
|
|
42
|
+
*/
|
|
43
|
+
function unzip(zipPath: MaybeArray<string>, destDir?: MaybeArray<string>): void;
|
|
37
44
|
function joinPath(...p: MaybeArray<string>[]): string;
|
|
38
45
|
}
|
|
39
46
|
export {};
|
package/dist/func/u-file.js
CHANGED
|
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.UFile = void 0;
|
|
27
|
+
const child_process_1 = require("child_process");
|
|
27
28
|
const fs = __importStar(require("fs"));
|
|
28
29
|
const path = __importStar(require("path"));
|
|
29
30
|
const u_type_1 = require("./u-type");
|
|
@@ -55,7 +56,7 @@ var UFile;
|
|
|
55
56
|
}
|
|
56
57
|
UFile.rm = rm;
|
|
57
58
|
function exists(p) {
|
|
58
|
-
return fs.existsSync(joinPath(p));
|
|
59
|
+
return !!p && fs.existsSync(joinPath(p));
|
|
59
60
|
}
|
|
60
61
|
UFile.exists = exists;
|
|
61
62
|
/**
|
|
@@ -113,6 +114,51 @@ var UFile;
|
|
|
113
114
|
return dest;
|
|
114
115
|
}
|
|
115
116
|
UFile.reserveFilePath = reserveFilePath;
|
|
117
|
+
/**
|
|
118
|
+
* decompress zip file. this depends on os enviroment due to using the os command.
|
|
119
|
+
* currently this supports only windows (installed `tar` or `unzip` in gnu compiler) and linux systems (installed `unzip`).
|
|
120
|
+
* @param zipPath zip file to be unzipped.
|
|
121
|
+
* @param destDir directory that the decompress files export to.
|
|
122
|
+
*/
|
|
123
|
+
function unzip(zipPath, destDir) {
|
|
124
|
+
if (!exists(zipPath))
|
|
125
|
+
throw new xjs_err_1.XjsErr(s_errCode, "There is no file on the zip path.");
|
|
126
|
+
if (!!destDir && !exists(destDir))
|
|
127
|
+
throw new xjs_err_1.XjsErr(s_errCode, "The destination directory is not found.");
|
|
128
|
+
let cmd = "unzip", options = null, availableCmd = true;
|
|
129
|
+
if (destDir)
|
|
130
|
+
options = `-d "${destDir}"`;
|
|
131
|
+
const check = () => { try {
|
|
132
|
+
(0, child_process_1.execSync)(`${cmd} --help`, { stdio: "ignore" });
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
availableCmd = false;
|
|
136
|
+
} };
|
|
137
|
+
check();
|
|
138
|
+
if (process.platform === "win32") {
|
|
139
|
+
if (!availableCmd) {
|
|
140
|
+
cmd = "tar";
|
|
141
|
+
options = "-xf";
|
|
142
|
+
availableCmd = true;
|
|
143
|
+
if (destDir)
|
|
144
|
+
options = `-C "${destDir}" ${options}`;
|
|
145
|
+
check();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else if (process.platform === "linux") {
|
|
149
|
+
}
|
|
150
|
+
else
|
|
151
|
+
throw new xjs_err_1.XjsErr(s_errCode, "The os running on is not supported for xjs unzip.");
|
|
152
|
+
if (!availableCmd)
|
|
153
|
+
throw new xjs_err_1.XjsErr(s_errCode, `"${cmd}" command is not installed.`);
|
|
154
|
+
try {
|
|
155
|
+
(0, child_process_1.execSync)([cmd, options, `"${zipPath}"`].filter(e => e).join(" "), { stdio: "ignore" });
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
throw new xjs_err_1.XjsErr(s_errCode, "Something went wrong at unzip.", e);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
UFile.unzip = unzip;
|
|
116
162
|
function joinPath(...p) {
|
|
117
163
|
return path.join(...p.flatMap(u_type_1.UType.takeAsArray));
|
|
118
164
|
}
|
package/dist/obj/xjs-err.d.ts
CHANGED
package/dist/obj/xjs-err.js
CHANGED
|
@@ -3,9 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.XjsErr = void 0;
|
|
4
4
|
class XjsErr extends Error {
|
|
5
5
|
code;
|
|
6
|
-
|
|
6
|
+
origin;
|
|
7
|
+
constructor(code, msg, origin) {
|
|
7
8
|
super(`[XJS] ${msg}`);
|
|
8
9
|
this.code = code;
|
|
10
|
+
this.origin = origin;
|
|
9
11
|
}
|
|
10
12
|
}
|
|
11
13
|
exports.XjsErr = XjsErr;
|
|
@@ -216,7 +216,9 @@ class HttpResolverContext {
|
|
|
216
216
|
const stream = fs.createWriteStream(dest);
|
|
217
217
|
res.pipe(stream);
|
|
218
218
|
stream.on("finish", () => stream.close());
|
|
219
|
-
resolve({ headers: res.headers });
|
|
219
|
+
stream.on("close", () => resolve({ headers: res.headers }));
|
|
220
|
+
stream.on("error", reject);
|
|
221
|
+
return;
|
|
220
222
|
}
|
|
221
223
|
catch (e) {
|
|
222
224
|
if (e instanceof xjs_err_1.XjsErr)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xjs-common",
|
|
3
|
-
"version": "9.0.3",
|
|
3
|
+
"version": "9.1.0-alpha.3",
|
|
4
4
|
"description": "library modules for nodejs + typescript that bundled general-purpose implementations.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,4 +28,4 @@
|
|
|
28
28
|
"ts-node": "^10.9.1",
|
|
29
29
|
"typescript": "^4.9.5"
|
|
30
30
|
}
|
|
31
|
-
}
|
|
31
|
+
}
|