zyd-server-build2 1.0.11 → 1.0.12
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 +2 -1
- package/index.js +38 -11
- package/package.json +1 -1
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -11,14 +11,30 @@ const count = [0, 0, 0]
|
|
|
11
11
|
const timer = []
|
|
12
12
|
const version = require('./package.json').version
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
async function build({ src, dst, ignoreDir = [], ignoreFile = [], copyright = "", noBuildFile = [], noBuildDir = [], confused = 1, options = {}, encryptionPath = 0 }) {
|
|
15
15
|
if (!src || !dst) {
|
|
16
16
|
return
|
|
17
17
|
}
|
|
18
18
|
ignoreDir.length > 0 && ignoreDir.push(dst)
|
|
19
19
|
await fs.readdirSync(src).forEach(async file => {
|
|
20
20
|
const _src = src + "/" + file
|
|
21
|
-
|
|
21
|
+
let _dst = dst + "/" + file
|
|
22
|
+
if (encryptionPath && !ignore(noBuildFile, _src)) {
|
|
23
|
+
if (file.split(".").pop().toLocaleLowerCase() === 'js') {
|
|
24
|
+
if (dst.indexOf("/operating") !== -1) {
|
|
25
|
+
_dst = `${dst}/${generateComplexRandomString(5)}.${Math.random().toString(36).substring(2, 10)}.js`
|
|
26
|
+
} else {
|
|
27
|
+
_dst = `${dst}/operating/${generateComplexRandomString(5)}.${Math.random().toString(36).substring(2, 10)}.js`
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
if (dst.indexOf("/operating") !== -1) {
|
|
31
|
+
_dst = dst
|
|
32
|
+
} else {
|
|
33
|
+
_dst = dst + "/operating"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
22
38
|
const st = fs.statSync(_src)
|
|
23
39
|
if (st.isFile()) {
|
|
24
40
|
count[2] += st.size
|
|
@@ -79,12 +95,12 @@ const version = require('./package.json').version
|
|
|
79
95
|
return
|
|
80
96
|
}
|
|
81
97
|
makeDir(_dst)
|
|
82
|
-
await build({ src: _src, dst: _dst, ignoreDir, ignoreFile, copyright, noBuildFile, noBuildDir, confused: ignore(noBuildDir, _src) ? 0 : 1 })
|
|
98
|
+
await build({ src: _src, dst: _dst, ignoreDir, ignoreFile, copyright, noBuildFile, noBuildDir, confused: ignore(noBuildDir, _src) ? 0 : 1, encryptionPath })
|
|
83
99
|
}
|
|
84
100
|
})
|
|
85
101
|
}
|
|
86
102
|
|
|
87
|
-
function ignore
|
|
103
|
+
function ignore(arr, str) {
|
|
88
104
|
let d = false
|
|
89
105
|
arr.forEach(item => {
|
|
90
106
|
item === str && (d = true)
|
|
@@ -92,7 +108,7 @@ function ignore (arr, str) {
|
|
|
92
108
|
return d
|
|
93
109
|
}
|
|
94
110
|
|
|
95
|
-
function exists
|
|
111
|
+
function exists(dst, noDeleteDir) {
|
|
96
112
|
if (!fs.existsSync(dst)) {
|
|
97
113
|
makeDir(dst)
|
|
98
114
|
} else {
|
|
@@ -102,7 +118,7 @@ function exists (dst, noDeleteDir) {
|
|
|
102
118
|
}
|
|
103
119
|
}
|
|
104
120
|
|
|
105
|
-
function makeDir
|
|
121
|
+
function makeDir(dirpath) {
|
|
106
122
|
if (!fs.existsSync(dirpath)) {
|
|
107
123
|
var pathtmp;
|
|
108
124
|
dirpath.split("/").forEach(dirname => {
|
|
@@ -145,7 +161,7 @@ const delDir = (url, noDeleteDir) => {
|
|
|
145
161
|
}
|
|
146
162
|
|
|
147
163
|
|
|
148
|
-
function bytesToSize
|
|
164
|
+
function bytesToSize(bytes) {
|
|
149
165
|
if (bytes === 0) return '0 B';
|
|
150
166
|
var k = 1024;
|
|
151
167
|
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
@@ -159,12 +175,12 @@ function bytesToSize (bytes) {
|
|
|
159
175
|
* 阻塞函数
|
|
160
176
|
* @param {Number} milliSeconds 毫秒数
|
|
161
177
|
*/
|
|
162
|
-
function sleep
|
|
178
|
+
function sleep(milliSeconds) {
|
|
163
179
|
const startTime = new Date().getTime()
|
|
164
180
|
while (new Date().getTime() < startTime + milliSeconds) { }
|
|
165
181
|
}
|
|
166
182
|
|
|
167
|
-
function formatDuration
|
|
183
|
+
function formatDuration(ms) {
|
|
168
184
|
if (ms < 0) ms = -ms;
|
|
169
185
|
const time = {
|
|
170
186
|
day: Math.floor(ms / 86400000),
|
|
@@ -179,6 +195,16 @@ function formatDuration (ms) {
|
|
|
179
195
|
.join(', ');
|
|
180
196
|
}
|
|
181
197
|
|
|
198
|
+
function generateComplexRandomString(length) {
|
|
199
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
|
200
|
+
let result = '';
|
|
201
|
+
|
|
202
|
+
for (let i = 0; i < length; i++) {
|
|
203
|
+
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
204
|
+
}
|
|
205
|
+
return result;
|
|
206
|
+
}
|
|
207
|
+
|
|
182
208
|
module.exports = async ({
|
|
183
209
|
src = ".",
|
|
184
210
|
dst = "./build",
|
|
@@ -205,7 +231,8 @@ module.exports = async ({
|
|
|
205
231
|
global_defs: {
|
|
206
232
|
DEBUG: false
|
|
207
233
|
},
|
|
208
|
-
}
|
|
234
|
+
},
|
|
235
|
+
encryptionPath = 0
|
|
209
236
|
} = {}) => {
|
|
210
237
|
console.log(`\x1B[33m
|
|
211
238
|
┌─────────────────────┐
|
|
@@ -217,7 +244,7 @@ module.exports = async ({
|
|
|
217
244
|
console.log("\x1B[36m\x1B[1mStart build...\x1B[0m\x1B[0m\n")
|
|
218
245
|
timer[0] = new Date()
|
|
219
246
|
exists(dst, noDeleteDir)
|
|
220
|
-
await build({ src, dst, ignoreDir, ignoreFile, copyright, noBuildFile, noBuildDir, options })
|
|
247
|
+
await build({ src, dst, ignoreDir, ignoreFile, copyright, noBuildFile, noBuildDir, options, encryptionPath })
|
|
221
248
|
process.nextTick(() => {
|
|
222
249
|
console.log("")
|
|
223
250
|
console.log(`number of files: \x1B[36m${count[0]}\x1B[0m`)
|