zyd-server-build2 1.0.16 → 1.0.18
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/index.js +42 -4
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -11,8 +11,7 @@ const count = [0, 0, 0]
|
|
|
11
11
|
const timer = []
|
|
12
12
|
const version = require('./package.json').version
|
|
13
13
|
let baseDst = ''
|
|
14
|
-
const
|
|
15
|
-
|
|
14
|
+
const pathLevel = []
|
|
16
15
|
async function build({ src, dst, ignoreDir = [], ignoreFile = [], copyright = "", noBuildFile = [], noBuildDir = [], noEncryptionPathFile = [], confused = 1, options = {}, encryptionPath = 0 }) {
|
|
17
16
|
if (!src || !dst) {
|
|
18
17
|
return
|
|
@@ -22,7 +21,13 @@ async function build({ src, dst, ignoreDir = [], ignoreFile = [], copyright = ""
|
|
|
22
21
|
const _src = src + "/" + file
|
|
23
22
|
let _dst = dst + "/" + file
|
|
24
23
|
if (encryptionPath && !ignore(noBuildFile, _src) && confused === 1 && path.extname(_src) === ".js" && !ignore(noEncryptionPathFile, _src)) {
|
|
25
|
-
|
|
24
|
+
const pathStr = dst.split(baseDst + '/')[1]?.split('/').map((_item, index) => {
|
|
25
|
+
if (!pathLevel[index]) {
|
|
26
|
+
pathLevel.push(generateComplexRandomString(5))
|
|
27
|
+
}
|
|
28
|
+
return pathLevel[index]
|
|
29
|
+
}).join('/')
|
|
30
|
+
_dst = `${baseDst}/z.${pathStr}/${generateComplexRandomString(5)}.${Math.random().toString(36).substring(2, 10)}.js`
|
|
26
31
|
}
|
|
27
32
|
const st = fs.statSync(_src)
|
|
28
33
|
if (st.isFile()) {
|
|
@@ -51,8 +56,16 @@ async function build({ src, dst, ignoreDir = [], ignoreFile = [], copyright = ""
|
|
|
51
56
|
compress: options,
|
|
52
57
|
mangle: {
|
|
53
58
|
// mangle options
|
|
59
|
+
// properties: {
|
|
60
|
+
// regex: /^_/ // 混淆以下划线开头的属性名
|
|
61
|
+
// },
|
|
62
|
+
// reserved: [], // 保留不被混淆的变量名列表
|
|
63
|
+
// keep_classnames: false, // 改为 false 允许混淆类名
|
|
64
|
+
// keep_fnames: false, // 改为 false 允许混淆函数名
|
|
54
65
|
},
|
|
55
66
|
format: {
|
|
67
|
+
ascii_only: true, // 这将把非ASCII字符(如中文)转换为Unicode转义序列
|
|
68
|
+
quote_style: 3 // 随机使用单引号和双引号
|
|
56
69
|
// format options (can also use `output` for backwards compatibility)
|
|
57
70
|
},
|
|
58
71
|
sourceMap: {
|
|
@@ -194,6 +207,29 @@ function generateComplexRandomString(length) {
|
|
|
194
207
|
return result;
|
|
195
208
|
}
|
|
196
209
|
|
|
210
|
+
function safeDelete(dir) {
|
|
211
|
+
try {
|
|
212
|
+
if (!fs.existsSync(dir)) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
// 先递归处理子目录
|
|
216
|
+
const files = fs.readdirSync(dir);
|
|
217
|
+
for (const file of files) {
|
|
218
|
+
const fullPath = path.join(dir, file);
|
|
219
|
+
if (fs.statSync(fullPath).isDirectory()) {
|
|
220
|
+
safeDelete(fullPath);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
// 处理完子目录后,再判断自己是否为空
|
|
224
|
+
if (fs.readdirSync(dir).length === 0) {
|
|
225
|
+
fs.rmdirSync(dir);
|
|
226
|
+
// console.log(`已删除: ${dir}`);
|
|
227
|
+
}
|
|
228
|
+
} catch (error) {
|
|
229
|
+
// console.error(`删除失败 [${dir}]:`, error.message);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
197
233
|
module.exports = async ({
|
|
198
234
|
src = ".",
|
|
199
235
|
dst = "./build",
|
|
@@ -235,8 +271,9 @@ module.exports = async ({
|
|
|
235
271
|
timer[0] = new Date()
|
|
236
272
|
exists(dst, noDeleteDir)
|
|
237
273
|
baseDst = dst.toString()
|
|
274
|
+
await execSync(`rm -rf ${dst}`)
|
|
238
275
|
await build({ src, dst, ignoreDir, ignoreFile, copyright, noBuildFile, noBuildDir, noEncryptionPathFile, options, encryptionPath })
|
|
239
|
-
process.nextTick(() => {
|
|
276
|
+
process.nextTick(async () => {
|
|
240
277
|
console.log("")
|
|
241
278
|
console.log(`number of files: \x1B[36m${count[0]}\x1B[0m`)
|
|
242
279
|
console.log(`Number of Obfuscated Files: \x1B[36m${count[1]}\x1B[0m`)
|
|
@@ -248,5 +285,6 @@ module.exports = async ({
|
|
|
248
285
|
│ build success √ │
|
|
249
286
|
└─────────────────┘
|
|
250
287
|
\x1B[0m\x1B[0m`)
|
|
288
|
+
safeDelete(dst)
|
|
251
289
|
})
|
|
252
290
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zyd-server-build2",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.18",
|
|
4
4
|
"description": "基于terser的js混淆build库,通过babel支持es6+",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,6 +23,6 @@
|
|
|
23
23
|
"@babel/node": "^7.20.7",
|
|
24
24
|
"@babel/plugin-proposal-decorators": "^7.21.0",
|
|
25
25
|
"@babel/preset-env": "^7.21.4",
|
|
26
|
-
"terser": "^5.
|
|
26
|
+
"terser": "^5.39.0"
|
|
27
27
|
}
|
|
28
28
|
}
|