zyd-server-build2 1.0.11 → 1.0.15
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/README.md +4 -2
- package/index.js +29 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -87,8 +87,10 @@ zsb({
|
|
|
87
87
|
global_defs: {
|
|
88
88
|
DEBUG: false
|
|
89
89
|
},
|
|
90
|
-
}
|
|
91
|
-
|
|
90
|
+
},
|
|
91
|
+
encryptionPath: 0, // 加密路径,1为加密,默认:0
|
|
92
|
+
noEncryptionPathFile: ["../server/middleware/index.js"] // 不需要加密的文件(完整路径),文件路径前需要包含src的内容,如实例,文件路径会被无改动打包到目标文件夹中
|
|
93
|
+
})
|
|
92
94
|
```
|
|
93
95
|
## License
|
|
94
96
|
[MIT](https://github.com/hfzhae/zyd-server-build/blob/main/LICENSE)
|
package/index.js
CHANGED
|
@@ -10,15 +10,20 @@ const path = require("path")
|
|
|
10
10
|
const count = [0, 0, 0]
|
|
11
11
|
const timer = []
|
|
12
12
|
const version = require('./package.json').version
|
|
13
|
+
let baseDst = ''
|
|
14
|
+
const operatingDir = generateComplexRandomString(5)
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
async function build({ src, dst, ignoreDir = [], ignoreFile = [], copyright = "", noBuildFile = [], noBuildDir = [], noEncryptionPathFile = [], confused = 1, options = {}, encryptionPath = 0 }) {
|
|
15
17
|
if (!src || !dst) {
|
|
16
18
|
return
|
|
17
19
|
}
|
|
18
20
|
ignoreDir.length > 0 && ignoreDir.push(dst)
|
|
19
21
|
await fs.readdirSync(src).forEach(async file => {
|
|
20
22
|
const _src = src + "/" + file
|
|
21
|
-
|
|
23
|
+
let _dst = dst + "/" + file
|
|
24
|
+
if (encryptionPath && !ignore(noBuildFile, _src) && confused === 1 && path.extname(_src) === ".js" && !ignore(noEncryptionPathFile, _src)) {
|
|
25
|
+
_dst = `${baseDst}/z.${operatingDir}/${generateComplexRandomString(5)}.${Math.random().toString(36).substring(2, 10)}.js`
|
|
26
|
+
}
|
|
22
27
|
const st = fs.statSync(_src)
|
|
23
28
|
if (st.isFile()) {
|
|
24
29
|
count[2] += st.size
|
|
@@ -79,12 +84,12 @@ const version = require('./package.json').version
|
|
|
79
84
|
return
|
|
80
85
|
}
|
|
81
86
|
makeDir(_dst)
|
|
82
|
-
await build({ src: _src, dst: _dst, ignoreDir, ignoreFile, copyright, noBuildFile, noBuildDir, confused: ignore(noBuildDir, _src) ? 0 : 1 })
|
|
87
|
+
await build({ src: _src, dst: _dst, ignoreDir, ignoreFile, copyright, noBuildFile, noBuildDir, noEncryptionPathFile, confused: ignore(noBuildDir, _src) ? 0 : 1, encryptionPath })
|
|
83
88
|
}
|
|
84
89
|
})
|
|
85
90
|
}
|
|
86
91
|
|
|
87
|
-
function ignore
|
|
92
|
+
function ignore(arr, str) {
|
|
88
93
|
let d = false
|
|
89
94
|
arr.forEach(item => {
|
|
90
95
|
item === str && (d = true)
|
|
@@ -92,7 +97,7 @@ function ignore (arr, str) {
|
|
|
92
97
|
return d
|
|
93
98
|
}
|
|
94
99
|
|
|
95
|
-
function exists
|
|
100
|
+
function exists(dst, noDeleteDir) {
|
|
96
101
|
if (!fs.existsSync(dst)) {
|
|
97
102
|
makeDir(dst)
|
|
98
103
|
} else {
|
|
@@ -102,7 +107,7 @@ function exists (dst, noDeleteDir) {
|
|
|
102
107
|
}
|
|
103
108
|
}
|
|
104
109
|
|
|
105
|
-
function makeDir
|
|
110
|
+
function makeDir(dirpath) {
|
|
106
111
|
if (!fs.existsSync(dirpath)) {
|
|
107
112
|
var pathtmp;
|
|
108
113
|
dirpath.split("/").forEach(dirname => {
|
|
@@ -145,7 +150,7 @@ const delDir = (url, noDeleteDir) => {
|
|
|
145
150
|
}
|
|
146
151
|
|
|
147
152
|
|
|
148
|
-
function bytesToSize
|
|
153
|
+
function bytesToSize(bytes) {
|
|
149
154
|
if (bytes === 0) return '0 B';
|
|
150
155
|
var k = 1024;
|
|
151
156
|
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
@@ -159,12 +164,12 @@ function bytesToSize (bytes) {
|
|
|
159
164
|
* 阻塞函数
|
|
160
165
|
* @param {Number} milliSeconds 毫秒数
|
|
161
166
|
*/
|
|
162
|
-
function sleep
|
|
167
|
+
function sleep(milliSeconds) {
|
|
163
168
|
const startTime = new Date().getTime()
|
|
164
169
|
while (new Date().getTime() < startTime + milliSeconds) { }
|
|
165
170
|
}
|
|
166
171
|
|
|
167
|
-
function formatDuration
|
|
172
|
+
function formatDuration(ms) {
|
|
168
173
|
if (ms < 0) ms = -ms;
|
|
169
174
|
const time = {
|
|
170
175
|
day: Math.floor(ms / 86400000),
|
|
@@ -179,6 +184,16 @@ function formatDuration (ms) {
|
|
|
179
184
|
.join(', ');
|
|
180
185
|
}
|
|
181
186
|
|
|
187
|
+
function generateComplexRandomString(length) {
|
|
188
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
189
|
+
let result = '';
|
|
190
|
+
|
|
191
|
+
for (let i = 0; i < length; i++) {
|
|
192
|
+
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
193
|
+
}
|
|
194
|
+
return result;
|
|
195
|
+
}
|
|
196
|
+
|
|
182
197
|
module.exports = async ({
|
|
183
198
|
src = ".",
|
|
184
199
|
dst = "./build",
|
|
@@ -187,6 +202,7 @@ module.exports = async ({
|
|
|
187
202
|
copyright = "",
|
|
188
203
|
noBuildFile = [],
|
|
189
204
|
noBuildDir = [],
|
|
205
|
+
noEncryptionPathFile = [],
|
|
190
206
|
noDeleteDir = [".git", "node_modules"],
|
|
191
207
|
options = {
|
|
192
208
|
drop_console: true, // 删除console
|
|
@@ -205,7 +221,8 @@ module.exports = async ({
|
|
|
205
221
|
global_defs: {
|
|
206
222
|
DEBUG: false
|
|
207
223
|
},
|
|
208
|
-
}
|
|
224
|
+
},
|
|
225
|
+
encryptionPath = 0
|
|
209
226
|
} = {}) => {
|
|
210
227
|
console.log(`\x1B[33m
|
|
211
228
|
┌─────────────────────┐
|
|
@@ -217,7 +234,8 @@ module.exports = async ({
|
|
|
217
234
|
console.log("\x1B[36m\x1B[1mStart build...\x1B[0m\x1B[0m\n")
|
|
218
235
|
timer[0] = new Date()
|
|
219
236
|
exists(dst, noDeleteDir)
|
|
220
|
-
|
|
237
|
+
baseDst = dst.toString()
|
|
238
|
+
await build({ src, dst, ignoreDir, ignoreFile, copyright, noBuildFile, noBuildDir, noEncryptionPathFile, options, encryptionPath })
|
|
221
239
|
process.nextTick(() => {
|
|
222
240
|
console.log("")
|
|
223
241
|
console.log(`number of files: \x1B[36m${count[0]}\x1B[0m`)
|