Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit 16aee37

Browse files
committed
新增 测试代码
1 parent dc55d69 commit 16aee37

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/common/compress.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,13 @@ async function nodeDecompress(sourceZip: string, destDir: string, fileCode: stri
5252
}
5353

5454
export async function compress(sourceZip: string, files: string[], fileCode?: string) {
55-
if (system === "linux") {
56-
return await linuxZip(sourceZip, files);
57-
}
55+
if (system === "linux" && haveLinuxZip()) return await linuxZip(sourceZip, files);
56+
5857
return await nodeCompress(sourceZip, files, fileCode);
5958
}
6059

6160
export async function decompress(zipPath: string, dest: string, fileCode?: string) {
62-
if (system === "linux") {
63-
if (haveLinuxUnzip()) {
64-
return await linuxUnzip(zipPath, dest);
65-
}
66-
}
61+
if (system === "linux" && haveLinuxUnzip()) return await linuxUnzip(zipPath, dest);
6762
return await nodeDecompress(zipPath, dest, fileCode);
6863
}
6964

@@ -104,6 +99,11 @@ function haveLinuxUnzip() {
10499
return result?.toString("utf-8").toLowerCase().includes("extended help for unzip");
105100
}
106101

102+
function haveLinuxZip() {
103+
const result = child_process.execSync("zip -h2");
104+
return result?.toString("utf-8").toLowerCase().includes("extended help for zip");
105+
}
106+
107107
async function linuxUnzip(sourceZip: string, destDir: string) {
108108
return new Promise((resolve, reject) => {
109109
const process = child_process.spawn("unzip", [sourceZip, "-d", destDir], {
@@ -119,6 +119,7 @@ async function linuxUnzip(sourceZip: string, destDir: string) {
119119

120120
// zip -r a.zip css css_v1 js
121121
async function linuxZip(sourceZip: string, files: string[]) {
122+
console.log("DO:", files);
122123
return new Promise((resolve, reject) => {
123124
const p = ["-r", sourceZip];
124125
p.concat(files);

0 commit comments

Comments
 (0)