zyd-server-build2 1.0.9 → 1.0.10

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.
Files changed (2) hide show
  1. package/index.js +46 -49
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -4,18 +4,19 @@
4
4
  * zz
5
5
  */
6
6
  const { minify } = require("terser")
7
- const { exec } = require('child_process')
7
+ const { execSync } = require('child_process')
8
8
  const fs = require("fs")
9
9
  const path = require("path")
10
10
  const count = [0, 0, 0]
11
11
  const timer = []
12
+ const version = require('./package.json').version
12
13
 
13
- function build ({ src, dst, ignoreDir = [], ignoreFile = [], copyright = "", noBuildFile = [], noBuildDir = [], confused = 1, options = {} }) {
14
+ async function build ({ src, dst, ignoreDir = [], ignoreFile = [], copyright = "", noBuildFile = [], noBuildDir = [], confused = 1, options = {} }) {
14
15
  if (!src || !dst) {
15
16
  return
16
17
  }
17
18
  ignoreDir.length > 0 && ignoreDir.push(dst)
18
- fs.readdirSync(src).forEach(file => {
19
+ await fs.readdirSync(src).forEach(async file => {
19
20
  const _src = src + "/" + file
20
21
  const _dst = dst + "/" + file
21
22
  const st = fs.statSync(_src)
@@ -35,40 +36,34 @@ function build ({ src, dst, ignoreDir = [], ignoreFile = [], copyright = "", noB
35
36
  writable = fs.createWriteStream(_dst);
36
37
  readable.pipe(writable);
37
38
  } else {
38
- exec(`npx babel ${_src} --out-file ${_dst}`, async (err, stdout, stderr) => {
39
- if (err) {
40
- console.error(`执行Babel命令时出错: ${err}`)
41
- return
42
- }
43
-
44
- readable = await fs.readFileSync(_dst, 'utf-8')
45
- const result = await minify(readable, {
46
- parse: {
47
- // parse options
48
- },
49
- compress: options,
50
- mangle: {
51
- // mangle options
52
- },
53
- format: {
54
- // format options (can also use `output` for backwards compatibility)
55
- },
56
- sourceMap: {
57
- // source map options
58
- },
59
- ecma: 2016, // specify one of: 5, 2015, 2016, etc.
60
- enclose: false, // or specify true, or "args:values"
61
- ie8: false,
62
- module: true,
63
- nameCache: null, // or specify a name cache object
64
- safari10: false,
65
- keep_classnames: true, // 默认 false。传 true来防止压缩器干掉对象名。对那些依赖
66
- keep_fnames: true, // 默认 false。传 true来防止压缩器干掉函数名。对那些依赖
67
- toplevel: false
68
- })
69
- await fs.writeFileSync(_dst, (copyright ? "/* " + copyright + " */" : "") + result.code)
70
- })
71
39
  console.log(_src, "\x1B[36m=>\x1B[0m", _dst, `\x1B[33m${bytesToSize(st.size)}\x1B[0m`, "\x1B[32mCode confused √\x1B[0m")
40
+ await execSync(`npx babel ${_src} --out-file ${_dst}`)
41
+ readable = await fs.readFileSync(_dst, 'utf-8')
42
+ const result = await minify(readable, {
43
+ parse: {
44
+ // parse options
45
+ },
46
+ compress: options,
47
+ mangle: {
48
+ // mangle options
49
+ },
50
+ format: {
51
+ // format options (can also use `output` for backwards compatibility)
52
+ },
53
+ sourceMap: {
54
+ // source map options
55
+ },
56
+ ecma: 2016, // specify one of: 5, 2015, 2016, etc.
57
+ enclose: false, // or specify true, or "args:values"
58
+ ie8: false,
59
+ module: true,
60
+ nameCache: null, // or specify a name cache object
61
+ safari10: false,
62
+ keep_classnames: true, // 默认 false。传 true来防止压缩器干掉对象名。对那些依赖
63
+ keep_fnames: true, // 默认 false。传 true来防止压缩器干掉函数名。对那些依赖
64
+ toplevel: false
65
+ })
66
+ await fs.writeFileSync(_dst, (copyright ? "/* " + copyright + " */" : "") + result.code)
72
67
  count[1]++
73
68
  }
74
69
  } else {
@@ -184,7 +179,7 @@ function formatDuration (ms) {
184
179
  .join(', ');
185
180
  }
186
181
 
187
- module.exports = ({
182
+ module.exports = async ({
188
183
  src = ".",
189
184
  dst = "./build",
190
185
  ignoreDir = ["./.git", "./node_modules"],
@@ -214,24 +209,26 @@ module.exports = ({
214
209
  } = {}) => {
215
210
  console.log(`\x1B[33m
216
211
  ┌─────────────────────┐
217
- │ Powered by zydsoft™ │
212
+ │ Powered by zydsoft® │
218
213
  │ zyd-server-build │
219
214
  └─────────────────────┘
220
- \x1B[0m`)
221
- console.log("\x1B[36m\x1B[1mStart build...\x1B[0m\x1B[0m")
215
+ \x1B[0m\x1B[37mversion:\x1B[0m\x1B[31m${version}\x1B[0m
216
+ `)
217
+ console.log("\x1B[36m\x1B[1mStart build...\x1B[0m\x1B[0m\n")
222
218
  timer[0] = new Date()
223
219
  exists(dst, noDeleteDir)
224
- build({ src, dst, ignoreDir, ignoreFile, copyright, noBuildFile, noBuildDir, options })
225
- console.log("")
226
- console.log(`number of files: \x1B[36m${count[0]}\x1B[0m`)
227
- console.log(`confusion number: \x1B[36m${count[1]}\x1B[0m`)
228
- console.log(`size: \x1B[36m${bytesToSize(count[2])}\x1B[0m`)
229
- console.log(`time consuming: \x1B[36m${formatDuration(new Date() - timer[0])}\x1B[0m`)
230
- // console.log("\x1B[1m\x1B[32mbuild success √\x1B[0m\x1B[0m")
231
- console.log(`\x1B[1m\x1B[32m
220
+ await build({ src, dst, ignoreDir, ignoreFile, copyright, noBuildFile, noBuildDir, options })
221
+ process.nextTick(() => {
222
+ console.log("")
223
+ console.log(`number of files: \x1B[36m${count[0]}\x1B[0m`)
224
+ console.log(`confusion number: \x1B[36m${count[1]}\x1B[0m`)
225
+ console.log(`size: \x1B[36m${bytesToSize(count[2])}\x1B[0m`)
226
+ console.log(`time consuming: \x1B[36m${formatDuration(new Date() - timer[0])}\x1B[0m`)
227
+ // console.log("\x1B[1m\x1B[32mbuild success √\x1B[0m\x1B[0m")
228
+ console.log(`\x1B[1m\x1B[32m
232
229
  ┌─────────────────┐
233
230
  │ build success √ │
234
231
  └─────────────────┘
235
232
  \x1B[0m\x1B[0m`)
236
- console.log('Please wait...')
233
+ })
237
234
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zyd-server-build2",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "基于terser的js混淆build库,通过babel支持es6+",
5
5
  "main": "index.js",
6
6
  "scripts": {