-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdeekeScriptZipBuild
More file actions
48 lines (39 loc) · 1.65 KB
/
deekeScriptZipBuild
File metadata and controls
48 lines (39 loc) · 1.65 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
41
42
43
44
45
46
47
48
const path = require('path'); // CommonJS 方式引入 path:ml-citation{ref="1,2" data="citationList"}
const fs = require('fs'); // 引入 fs 模块:ml-citation{ref="5" data="citationList"}
const AdmZip = require('adm-zip'); // 引入 adm-zip 库:ml-citation{ref="3,4" data="citationList"}
// 获取上层目录路径
// const parentDir = path.join(__dirname, '..');
const parentDir = __dirname;
console.log('开始执行打包');
fs.unlink(path.join(parentDir, 'deekeScript.zip'), (err) => {
if (err) {
//没有文件
} else {
//console.log('deekeScript.zip文件已删除');
}
});
// 创建 zip 实例
const zip = new AdmZip();
// 递归添加文件并排除目录
function addFilesToZip(directory) {
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('打包完成');