-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdeekeScriptZipBuild.ts
More file actions
40 lines (32 loc) · 1.22 KB
/
Copy pathdeekeScriptZipBuild.ts
File metadata and controls
40 lines (32 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// zip.ts
import path from 'path';
import fs from 'fs';
import AdmZip from 'adm-zip';
// 获取上层目录路径
const parentDir = path.join(__dirname, '..');
console.log('开始执行打包');
// 创建 zip 实例
const zip = new AdmZip();
// 递归添加文件并排除目录
function addFilesToZip(directory: string) {
const files = fs.readdirSync(directory);
files.forEach(file => {
const fullPath = path.join(directory, file);
const relativePath = path.relative(parentDir, fullPath);
// 排除 DeekeScript 和 node_modules 目录
if (relativePath.startsWith('src') || relativePath.startsWith('.vscode') || relativePath.startsWith('.git') || relativePath.startsWith('@deekeScript') || relativePath.startsWith('node_modules')) {
console.log('排除目录:' + relativePath);
return;
}
// 处理子目录或文件
if (fs.statSync(fullPath).isDirectory()) {
addFilesToZip(fullPath); // 递归处理子目录
} else {
zip.addLocalFile(fullPath, path.dirname(relativePath));
}
});
}
// 执行压缩
addFilesToZip(parentDir);
zip.writeZip(path.join(parentDir, 'deekeScript.zip'));
console.log('打包完成');