ee-bin 4.0.0-beta.1 → 4.0.0

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.
@@ -16,12 +16,16 @@ module.exports = {
16
16
  hostname: 'localhost',
17
17
  port: 8080,
18
18
  indexPath: 'index.html',
19
+ force: false,
20
+ sync: false,
19
21
  },
20
22
  electron: {
21
23
  directory: './',
22
24
  cmd: 'electron',
23
25
  args: ['.', '--env=local'],
24
26
  loadingPage: '/public/html/loading.html',
27
+ watch: false,
28
+ sync: false,
25
29
  },
26
30
  },
27
31
 
@@ -36,8 +40,9 @@ module.exports = {
36
40
  args: ['run', 'build'],
37
41
  },
38
42
  electron: {
43
+ type: 'javascript',
39
44
  bundler: 'esbuild',
40
- language: 'javascript',
45
+ bundleType: 'bundle', // copy | bundle
41
46
  javascript: {
42
47
  entryPoints: ['./electron/**/*.js'],
43
48
  platform: 'node',
@@ -60,7 +65,47 @@ module.exports = {
60
65
  sourcemap:false,
61
66
  sourcesContent: false
62
67
  }
63
- }
68
+ },
69
+ win32: {
70
+ cmd: 'electron-builder',
71
+ directory: './',
72
+ args: ['--config=./cmd/builder.json', '-w=nsis', '--ia32'],
73
+ },
74
+ win64: {
75
+ cmd: 'electron-builder',
76
+ directory: './',
77
+ args: ['--config=./cmd/builder.json', '-w=nsis', '--x64'],
78
+ },
79
+ win_e: {
80
+ cmd: 'electron-builder',
81
+ directory: './',
82
+ args: ['--config=./cmd/builder.json', '-w=portable', '--x64'],
83
+ },
84
+ win_7z: {
85
+ cmd: 'electron-builder',
86
+ directory: './',
87
+ args: ['--config=./cmd/builder.json', '-w=7z', '--x64'],
88
+ },
89
+ mac: {
90
+ cmd: 'electron-builder',
91
+ directory: './',
92
+ args: ['--config=./cmd/builder-mac.json', '-m'],
93
+ },
94
+ mac_arm64: {
95
+ cmd: 'electron-builder',
96
+ directory: './',
97
+ args: ['--config=./cmd/builder-mac-arm64.json', '-m', '--arm64'],
98
+ },
99
+ linux: {
100
+ cmd: 'electron-builder',
101
+ directory: './',
102
+ args: ['--config=./cmd/builder-linux.json', '-l=deb', '--x64'],
103
+ },
104
+ linux_arm64: {
105
+ cmd: 'electron-builder',
106
+ directory: './',
107
+ args: ['--config=./cmd/builder-linux.json', '-l=deb', '--arm64'],
108
+ },
64
109
  },
65
110
 
66
111
  /**
@@ -88,19 +133,43 @@ module.exports = {
88
133
  * 加密
89
134
  */
90
135
  encrypt: {
91
- type: 'none',
92
- files: [
93
- './public/electron/**/*.(js|json)',
94
- ],
95
- fileExt: ['.js'],
96
- cleanFiles: ['./public/electron'],
97
- specificFiles: ['./public/electron/preload/bridge.js'],
98
- encryptDir: './',
99
- confusionOptions: {
100
- compact: true,
101
- stringArray: true,
102
- stringArrayEncoding: ['none'],
103
- deadCodeInjection: false,
136
+ frontend: {
137
+ type: 'none',
138
+ files: [
139
+ './public/dist/**/*.(js|json)',
140
+ ],
141
+ fileExt: ['.js'],
142
+ cleanFiles: ['./public/dist'],
143
+ specificFiles: [],
144
+ encryptDir: './',
145
+ confusionOptions: {
146
+ compact: true,
147
+ stringArray: true,
148
+ stringArrayEncoding: ['none'],
149
+ deadCodeInjection: false,
150
+ stringArrayCallsTransform: true,
151
+ numbersToExpressions: true,
152
+ target: 'browser',
153
+ }
154
+ },
155
+ electron: {
156
+ type: 'none',
157
+ files: [
158
+ './public/electron/**/*.(js|json)',
159
+ ],
160
+ fileExt: ['.js'],
161
+ cleanFiles: ['./public/electron'],
162
+ specificFiles: ['./public/electron/preload/bridge.js'],
163
+ encryptDir: './',
164
+ confusionOptions: {
165
+ compact: true,
166
+ stringArray: true,
167
+ stringArrayEncoding: ['rc4'],
168
+ deadCodeInjection: false,
169
+ stringArrayCallsTransform: true,
170
+ numbersToExpressions: true,
171
+ target: 'node',
172
+ }
104
173
  }
105
174
  },
106
175
 
package/index.js CHANGED
@@ -26,6 +26,7 @@ program
26
26
  .description('building multiple resources')
27
27
  .option('--config <folder>', 'config file')
28
28
  .option('--cmds <flag>', 'custom commands')
29
+ .option('--env <env>', 'environment')
29
30
  .action(function() {
30
31
  serveProcess.build(this.opts());
31
32
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ee-bin",
3
- "version": "4.0.0-beta.1",
3
+ "version": "4.0.0",
4
4
  "description": "ee bin",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -15,6 +15,7 @@
15
15
  "adm-zip": "^0.4.11",
16
16
  "bytenode": "^1.3.6",
17
17
  "chalk": "^4.1.2",
18
+ "chokidar": "^4.0.3",
18
19
  "commander": "^11.0.0",
19
20
  "config-file-ts": "^0.2.8-rc1",
20
21
  "cross-spawn": "^7.0.3",
package/tools/encrypt.js CHANGED
@@ -9,17 +9,19 @@ const JavaScriptObfuscator = require('javascript-obfuscator');
9
9
  const globby = require('globby');
10
10
  const chalk = require('chalk');
11
11
  const { loadConfig } = require('../lib/utils');
12
+ const { extend } = require('../lib/extend');
12
13
 
13
14
  const EncryptTypes = ['bytecode', 'confusion', 'strict'];
14
15
 
15
16
  class Encrypt {
16
17
  constructor(options = {}) {
17
18
  // cli args
18
- const { config, out } = options;
19
+ const { config, out, target } = options;
19
20
  this.basePath = process.cwd();
21
+ this.target = target;
20
22
 
21
- const cfg = loadConfig(config);
22
- this.config = cfg.encrypt;
23
+ const conf = loadConfig(config).encrypt;
24
+ this.config = conf[target];
23
25
  const outputFolder = out || this.config.encryptDir;
24
26
  this.encryptDir = path.join(this.basePath, outputFolder);
25
27
  this.filesExt = this.config.fileExt;
@@ -43,45 +45,16 @@ class Encrypt {
43
45
  return files;
44
46
  }
45
47
 
46
- /**
47
- * 备份代码
48
- */
49
- backup() {
50
- // clean
51
- this.cleanCode();
52
-
53
- console.log(chalk.blue('[ee-bin] [encrypt] ') + 'backup start');
54
- this.codefiles.forEach((filepath) => {
55
- let source = path.join(this.basePath, filepath);
56
- if (fs.existsSync(source)) {
57
- let target = path.join(this.encryptCodeDir, filepath);
58
- fsPro.copySync(source, target);
59
- }
60
- })
61
-
62
- console.log(chalk.blue('[ee-bin] [encrypt] ') + 'backup end');
63
- return true;
64
- }
65
-
66
- /**
67
- * 清除加密代码
68
- */
69
- cleanCode() {
70
- this.cleanFiles.forEach((file) => {
71
- let tmpFile = path.join(this.basePath, file);
72
- fsPro.removeSync(tmpFile);
73
- console.log(chalk.blue('[ee-bin] [encrypt] ') + 'clean up tmp files:' + chalk.magenta(`${tmpFile}`));
74
- })
75
- }
76
-
77
48
  /**
78
49
  * 加密代码
79
50
  */
80
51
  encrypt() {
81
- console.log(chalk.blue('[ee-bin] [encrypt] ') + 'start ciphering');
82
- console.log(this.codefiles);
52
+ if (EncryptTypes.indexOf(this.type) == -1) return;
53
+ if (this.target == 'frontend' && (this.type == 'bytecode' || this.type == 'strict')) return;
54
+
55
+ console.log(chalk.blue('[ee-bin] [encrypt] ') + `start ciphering ${this.target}`);
83
56
  for (const file of this.codefiles) {
84
- const fullpath = path.join(this.encryptCodeDir, file);
57
+ const fullpath = path.join(this.encryptDir, file);
85
58
  if (!fs.statSync(fullpath).isFile()) continue;
86
59
 
87
60
  // 特殊文件处理
@@ -172,13 +145,22 @@ class Encrypt {
172
145
  }
173
146
 
174
147
  function encrypt(options = {}) {
175
- const enc = new Encrypt(options);
176
- if (EncryptTypes.indexOf(enc.type) == -1) return;
177
- //if (!enc.backup()) return;
178
- enc.encrypt();
148
+ const electronOpt = extend(true, {
149
+ target: 'electron',
150
+ }, options);
151
+ const electronEpt = new Encrypt(electronOpt);
152
+ electronEpt.encrypt();
153
+
154
+ const frontendOpt = extend(true, {
155
+ target: 'frontend',
156
+ }, options);
157
+ const frontendEpt = new Encrypt(frontendOpt);
158
+ frontendEpt.encrypt();
179
159
  }
180
160
 
181
161
  function cleanEncrypt(options = {}) {
162
+ // [todo] 删除前端和主进程代码
163
+ return;
182
164
  let files = options.dir !== undefined ? options.dir : ['./public/electron'];
183
165
  files = is.string(files) ? [files] : files;
184
166
 
package/tools/serve.js CHANGED
@@ -2,22 +2,29 @@
2
2
 
3
3
  const debug = require('debug')('ee-bin:serve');
4
4
  const path = require('path');
5
+ const fsPro = require('fs-extra');
5
6
  const { loadConfig } = require('../lib/utils');
6
7
  const is = require('is-type-of');
7
8
  const chalk = require('chalk');
8
9
  const crossSpawn = require('cross-spawn');
9
10
  const { buildSync } = require('esbuild');
11
+ const chokidar = require('chokidar');
10
12
 
11
13
  class ServeProcess {
12
14
 
13
15
  constructor() {
16
+ process.env.NODE_ENV = 'prod'; // dev / prod
14
17
  this.execProcess = {};
18
+ this.electronDir = './electron';
19
+ this.defaultBundleDir = './public/electron';
15
20
  }
16
21
 
17
22
  /**
18
23
  * 启动前端、主进程服务
19
24
  */
20
25
  dev(options = {}) {
26
+ // 设置一个环境变量
27
+ process.env.NODE_ENV = 'dev';
21
28
  const { config, serve } = options;
22
29
  const binCfg = loadConfig(config);
23
30
  const binCmd = 'dev';
@@ -27,18 +34,46 @@ class ServeProcess {
27
34
  if (!command) {
28
35
  command = Object.keys(binCmdConfig).join();
29
36
  }
30
-
31
- // build electron code
32
- const cmds = this._formatCmds(command);
33
- if (cmds.indexOf("electron") !== -1) {
34
- this.bundle(true, binCfg.build.electron);
35
- }
36
-
37
37
  const opt = {
38
38
  binCmd,
39
39
  binCmdConfig,
40
40
  command,
41
41
  }
42
+
43
+ // build electron main code
44
+ const cmds = this._formatCmds(command);
45
+ if (cmds.indexOf("electron") !== -1) {
46
+ // watche electron main code
47
+ const electronConfig = binCmdConfig.electron;
48
+ if (electronConfig.watch) {
49
+ const cmd = 'electron';
50
+ const watcher = chokidar.watch([this.electronDir], {
51
+ persistent: true
52
+ });
53
+ watcher.on('change', async (f) => {
54
+ console.log(chalk.blue('[ee-bin] [dev] ') + `File ${f} has been changed`);
55
+ console.log(chalk.blue('[ee-bin] [dev] ') + `Restart ${cmd}`);
56
+
57
+ // rebuild code
58
+ this.bundle(binCfg.build.electron);
59
+ let subPorcess = this.execProcess[cmd];
60
+ subPorcess.kill();
61
+ delete this.execProcess[cmd];
62
+
63
+ // restart electron command
64
+ let onlyElectronOpt = {
65
+ binCmd,
66
+ binCmdConfig,
67
+ command: cmd,
68
+ }
69
+ this.multiExec(onlyElectronOpt);
70
+ });
71
+ }
72
+
73
+ // When starting for the first time, build the code for the electron directory
74
+ this.bundle(binCfg.build.electron);
75
+ }
76
+
42
77
  this.multiExec(opt);
43
78
  }
44
79
 
@@ -69,7 +104,8 @@ class ServeProcess {
69
104
  * 构建
70
105
  */
71
106
  build(options = {}) {
72
- const { config, cmds } = options;
107
+ const { config, cmds, env } = options;
108
+ process.env.NODE_ENV = env;
73
109
  const binCfg = loadConfig(config);
74
110
  const binCmd = 'build';
75
111
  const binCmdConfig = binCfg[binCmd];
@@ -81,7 +117,7 @@ class ServeProcess {
81
117
  }
82
118
 
83
119
  if (cmds.indexOf("electron") !== -1) {
84
- this.bundle(false, binCfg.build.electron);
120
+ this.bundle(binCmdConfig.electron);
85
121
  return;
86
122
  }
87
123
 
@@ -161,13 +197,22 @@ class ServeProcess {
161
197
  }
162
198
 
163
199
  // esbuild
164
- bundle(isDev = false, bundleConfig) {
165
- const esbuildOptions = bundleConfig[bundleConfig.language];
166
- if (isDev) {
167
- // [todo]
200
+ bundle(bundleConfig) {
201
+ const { bundleType } = bundleConfig;
202
+ if (bundleType == 'copy') {
203
+ const srcResource = path.join(process.cwd(), this.electronDir);
204
+ const destResource = path.join(process.cwd(), this.defaultBundleDir);
205
+ fsPro.removeSync(destResource);
206
+ fsPro.copySync(srcResource, destResource);
207
+ } else {
208
+ const esbuildOptions = bundleConfig[bundleConfig.type];
209
+ // todo 不压缩
210
+ // if (this.isDev()) {
211
+ // esbuildOptions.minify = false;
212
+ // }
213
+ debug('esbuild options:%O', esbuildOptions);
214
+ buildSync(esbuildOptions);
168
215
  }
169
- debug('esbuild options:%O', esbuildOptions);
170
- buildSync(esbuildOptions);
171
216
  }
172
217
 
173
218
  // format commands
@@ -181,7 +226,12 @@ class ServeProcess {
181
226
  }
182
227
 
183
228
  return cmds;
184
- }
229
+ }
230
+
231
+ // env
232
+ isDev() {
233
+ return process.env.NODE_ENV === 'dev';
234
+ }
185
235
  }
186
236
 
187
237
  module.exports = {