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

Commit dc55d69

Browse files
committed
新增 zip 压缩功能
1 parent a0423a1 commit dc55d69

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/common/compress.ts

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

5454
export async function compress(sourceZip: string, files: string[], fileCode?: string) {
55-
// TODO 与系统集成的解压缩功能
56-
// if (system === "win32") {
57-
// await _7zipCompress(sourceZip, files);
58-
// } else {
59-
60-
// }
55+
if (system === "linux") {
56+
return await linuxZip(sourceZip, files);
57+
}
6158
return await nodeCompress(sourceZip, files, fileCode);
6259
}
6360

@@ -119,3 +116,19 @@ async function linuxUnzip(sourceZip: string, destDir: string) {
119116
});
120117
});
121118
}
119+
120+
// zip -r a.zip css css_v1 js
121+
async function linuxZip(sourceZip: string, files: string[]) {
122+
return new Promise((resolve, reject) => {
123+
const p = ["-r", sourceZip];
124+
p.concat(files);
125+
const process = child_process.spawn("zip", p, {
126+
cwd: path.normalize(path.dirname(sourceZip))
127+
});
128+
if (!process || !process.pid) return reject(false);
129+
process.on("exit", (code) => {
130+
if (code) return reject(false);
131+
return resolve(true);
132+
});
133+
});
134+
}

0 commit comments

Comments
 (0)