ee-bin 2.0.0-beta.1 → 4.0.0-beta.1

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.
@@ -0,0 +1,112 @@
1
+ /**
2
+ * ee-bin 配置
3
+ * 仅适用于开发环境
4
+ */
5
+ module.exports = {
6
+ /**
7
+ * development serve ("frontend" "electron" )
8
+ * ee-bin dev
9
+ */
10
+ dev: {
11
+ frontend: {
12
+ directory: './frontend',
13
+ cmd: 'npm',
14
+ args: ['run', 'dev'],
15
+ protocol: 'http://',
16
+ hostname: 'localhost',
17
+ port: 8080,
18
+ indexPath: 'index.html',
19
+ },
20
+ electron: {
21
+ directory: './',
22
+ cmd: 'electron',
23
+ args: ['.', '--env=local'],
24
+ loadingPage: '/public/html/loading.html',
25
+ },
26
+ },
27
+
28
+ /**
29
+ * 构建
30
+ * ee-bin build
31
+ */
32
+ build: {
33
+ frontend: {
34
+ directory: './frontend',
35
+ cmd: 'npm',
36
+ args: ['run', 'build'],
37
+ },
38
+ electron: {
39
+ bundler: 'esbuild',
40
+ language: 'javascript',
41
+ javascript: {
42
+ entryPoints: ['./electron/**/*.js'],
43
+ platform: 'node',
44
+ bundle: false,
45
+ minify: false,
46
+ outdir: 'public/electron',
47
+ packages: 'external',
48
+ sourcemap:false,
49
+ sourcesContent: false
50
+ },
51
+ typescript: {
52
+ entryPoints: ['./electron/**/*.ts'],
53
+ tsconfig: './tsconfig.json',
54
+ platform: 'node',
55
+ format: 'cjs',
56
+ bundle: false,
57
+ minify: false,
58
+ outdir: 'public/electron',
59
+ packages: 'external',
60
+ sourcemap:false,
61
+ sourcesContent: false
62
+ }
63
+ }
64
+ },
65
+
66
+ /**
67
+ * 移动资源
68
+ * ee-bin move
69
+ */
70
+ move: {
71
+ frontend_dist: {
72
+ src: './frontend/dist',
73
+ dest: './public/dist'
74
+ }
75
+ },
76
+
77
+ /**
78
+ * 预发布模式(prod)
79
+ * ee-bin start
80
+ */
81
+ start: {
82
+ directory: './',
83
+ cmd: 'electron',
84
+ args: ['.', '--env=prod']
85
+ },
86
+
87
+ /**
88
+ * 加密
89
+ */
90
+ 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,
104
+ }
105
+ },
106
+
107
+ /**
108
+ * 执行自定义命令
109
+ * ee-bin exec
110
+ */
111
+ exec: {},
112
+ };
@@ -1,123 +1,104 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const { program } = require('commander');
4
+ const { move } = require('./tools/move');
5
+ const { encrypt, cleanEncrypt } = require('./tools/encrypt');
6
+ const { serveProcess } = require('./tools/serve');
7
+ const { incrUpdater } = require('./tools/incrUpdater');
4
8
 
5
9
  /**
6
- * move - Moves resources
7
- */
8
- program
9
- .command('move')
10
- .description('Move multip resources')
11
- .option('--config <folder>', 'config file', './electron/config/bin.js')
12
- .option('--flag <flag>', 'Custom flag')
13
- .action(function() {
14
- const moveScript = require('./tools/move');
15
- moveScript.run(this.opts());
16
- });
17
-
18
- /**
19
- * (deprecated) rd - Moves front-end resources to a specified directory
10
+ * dev
20
11
  */
21
12
  program
22
- .command('rd')
23
- .description('Move frontend resources to public/dist')
24
- .option('--config <folder>', 'config file', './electron/config/bin.js')
25
- .option('--dist <folder>', 'title to use before name')
26
- .option('--target <folder>', 'title to use before name')
13
+ .command('dev')
14
+ .description('create frontend-serve and electron-serve')
15
+ .option('--config <folder>', 'config file')
16
+ .option('--serve <mode>', 'serve mode')
27
17
  .action(function() {
28
- const replaceDist = require('./tools/replaceDist');
29
- replaceDist.run(this.opts());
18
+ serveProcess.dev(this.opts());
30
19
  });
31
20
 
32
21
  /**
33
- * encrypt - Code encryption
22
+ * build
34
23
  */
35
24
  program
36
- .command('encrypt')
37
- .description('Code encryption')
25
+ .command('build')
26
+ .description('building multiple resources')
38
27
  .option('--config <folder>', 'config file')
39
- .option('--out <folder>', 'output directory', './public')
28
+ .option('--cmds <flag>', 'custom commands')
40
29
  .action(function() {
41
- const encrypt = require('./tools/encrypt');
42
- encrypt.run(this.opts());
30
+ serveProcess.build(this.opts());
43
31
  });
44
32
 
45
33
  /**
46
- * clean - Clear the encrypted code
34
+ * start
47
35
  */
48
36
  program
49
- .command('clean')
50
- .description('Clear the encrypted code')
51
- .option('-d, --dir <folder>', 'clean directory')
37
+ .command('start')
38
+ .description('preview effect')
39
+ .option('--config <folder>', 'config file')
52
40
  .action(function() {
53
- const encrypt = require('./tools/encrypt');
54
- encrypt.clean(this.opts());
41
+ serveProcess.start(this.opts());
55
42
  });
56
43
 
57
44
  /**
58
- * icon
45
+ * exec
59
46
  */
60
47
  program
61
- .command('icon')
62
- .description('Generate logo')
63
- .option('-i, --input <file>', 'image file default /public/images/logo.png')
64
- .option('-o, --output <folder>', 'output directory default /build/icons/')
48
+ .command('exec')
49
+ .description('create frontend-serve and electron-serve')
50
+ .option('--config <folder>', 'config file')
51
+ .option('--cmds <flag>', 'custom commands')
65
52
  .action(function() {
66
- const iconGen = require('./tools/iconGen');
67
- iconGen.run();
53
+ serveProcess.exec(this.opts());
68
54
  });
69
55
 
70
56
  /**
71
- * dev
57
+ * move - Moves resources
72
58
  */
73
59
  program
74
- .command('dev')
75
- .description('create frontend-serve and electron-serve')
76
- .option('--config <folder>', 'config file', './electron/config/bin.js')
77
- .option('--serve <mode>', 'serve mode')
60
+ .command('move')
61
+ .description('Move multip resources')
62
+ .option('--config <folder>', 'config file')
63
+ .option('--flag <flag>', 'Custom flag')
78
64
  .action(function() {
79
- const serve = require('./tools/serve');
80
- serve.dev(this.opts());
65
+ move(this.opts());
81
66
  });
82
67
 
83
68
  /**
84
- * build
69
+ * encrypt - Code encryption
85
70
  */
86
71
  program
87
- .command('build')
88
- .description('building multiple resources')
89
- .option('--config <folder>', 'config file', './electron/config/bin.js')
90
- .option('--cmds <flag>', 'custom commands')
72
+ .command('encrypt')
73
+ .description('Code encryption')
74
+ .option('--config <folder>', 'config file')
75
+ .option('--out <folder>', 'output directory')
91
76
  .action(function() {
92
- const serve = require('./tools/serve');
93
- serve.build(this.opts());
77
+ encrypt(this.opts());
94
78
  });
95
79
 
96
80
  /**
97
- * start
81
+ * clean - Clear the encrypted code
98
82
  */
99
83
  program
100
- .command('start')
101
- .description('preview effect')
102
- .option('--config <folder>', 'config file', './electron/config/bin.js')
84
+ .command('clean')
85
+ .description('Clear the encrypted code')
86
+ .option('-d, --dir <folder>', 'clean directory')
103
87
  .action(function() {
104
- const serve = require('./tools/serve');
105
- serve.start(this.opts());
88
+ cleanEncrypt(this.opts());
106
89
  });
107
90
 
108
91
  /**
109
- * exec
92
+ * icon
110
93
  */
111
94
  program
112
- .command('exec')
113
- .description('create frontend-serve and electron-serve')
114
- .option('--config <folder>', 'config file', './electron/config/bin.js')
115
- .option('--command <command>', 'Custom command')
116
- .option('--cmds <flag>', 'custom commands')
95
+ .command('icon')
96
+ .description('Generate logo')
97
+ .option('-i, --input <file>', 'image file default /public/images/logo.png')
98
+ .option('-o, --output <folder>', 'output directory default /build/icons/')
117
99
  .action(function() {
118
- // command 选项是关键字,不再使用,改为 cmds
119
- const serve = require('./tools/serve');
120
- serve.exec(this.opts());
100
+ const iconGen = require('./tools/iconGen');
101
+ iconGen.run();
121
102
  });
122
103
 
123
104
  /**
@@ -126,12 +107,11 @@ program
126
107
  program
127
108
  .command('updater')
128
109
  .description('updater commands')
129
- .option('--config <folder>', 'config file', './electron/config/bin.js')
110
+ .option('--config <folder>', 'config file')
130
111
  .option('--asar-file <file>', 'asar file path')
131
112
  .option('--platform <flag>', 'platform')
132
113
  .action(function() {
133
- const updater = require('./tools/incrUpdater');
134
- updater.run(this.opts());
114
+ incrUpdater.run(this.opts());
135
115
  });
136
116
 
137
117
  program.parse();
package/lib/extend.js ADDED
@@ -0,0 +1,78 @@
1
+ 'use strict';
2
+
3
+ const hasOwn = Object.prototype.hasOwnProperty;
4
+ const toStr = Object.prototype.toString;
5
+
6
+ function isPlainObject(obj) {
7
+ if (!obj || toStr.call(obj) !== '[object Object]') {
8
+ return false;
9
+ }
10
+
11
+ var hasOwnConstructor = hasOwn.call(obj, 'constructor');
12
+ var hasIsPrototypeOf = obj.constructor && obj.constructor.prototype && hasOwn.call(obj.constructor.prototype, 'isPrototypeOf');
13
+ // Not own constructor property must be Object
14
+ if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) {
15
+ return false;
16
+ }
17
+
18
+ // Own properties are enumerated firstly, so to speed up,
19
+ // if last one is own, then all properties are own.
20
+ var key;
21
+ for (key in obj) { /**/ }
22
+
23
+ return typeof key === 'undefined' || hasOwn.call(obj, key);
24
+ };
25
+
26
+ function extend() {
27
+ var options, name, src, copy, clone;
28
+ var target = arguments[0];
29
+ var i = 1;
30
+ var length = arguments.length;
31
+ var deep = false;
32
+
33
+ // Handle a deep copy situation
34
+ if (typeof target === 'boolean') {
35
+ deep = target;
36
+ target = arguments[1] || {};
37
+ // skip the boolean and the target
38
+ i = 2;
39
+ } else if ((typeof target !== 'object' && typeof target !== 'function') || target == null) {
40
+ target = {};
41
+ }
42
+
43
+ for (; i < length; ++i) {
44
+ options = arguments[i];
45
+ // Only deal with non-null/undefined values
46
+ if (options == null) continue;
47
+
48
+ // Extend the base object
49
+ for (name in options) {
50
+ if (name === '__proto__') continue;
51
+
52
+ src = target[name];
53
+ copy = options[name];
54
+
55
+ // Prevent never-ending loop
56
+ if (target === copy) continue;
57
+
58
+ // Recurse if we're merging plain objects
59
+ if (deep && copy && isPlainObject(copy)) {
60
+ clone = src && isPlainObject(src) ? src : {};
61
+ // Never move original objects, clone them
62
+ target[name] = extend(deep, clone, copy);
63
+
64
+ // Don't bring in undefined values
65
+ } else if (typeof copy !== 'undefined') {
66
+ target[name] = copy;
67
+ }
68
+ }
69
+ }
70
+
71
+ // Return the modified object
72
+ return target;
73
+ };
74
+
75
+ module.exports = {
76
+ extend,
77
+ isPlainObject,
78
+ };
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const debug = require('debug')('ee-bin:lib:utils');
3
4
  const path = require('path');
4
5
  const fs = require('fs');
5
6
  const chalk = require('chalk');
@@ -7,22 +8,26 @@ const is = require('is-type-of');
7
8
  const { loadTsConfig } = require('config-file-ts');
8
9
  const JsonLib = require('json5');
9
10
  const mkdirp = require('mkdirp');
11
+ const OS = require('os');
12
+ const defaultConfig = require('../config/bin_default');
13
+ const { extend } = require('./extend');
10
14
 
11
15
  const _basePath = process.cwd();
16
+ const userBin = './cmd/bin.js';
12
17
 
13
- function checkConfig(prop) {
14
- const filepath = path.join(_basePath, prop);
15
- if (fs.existsSync(filepath)) {
16
- return true;
17
- }
18
+ function loadConfig(binFile) {
19
+ const binPath = binFile ? binFile : userBin;
20
+ const userConfig = loadFile(binPath);
21
+ const result = extend(true, defaultConfig, userConfig);
22
+ debug('[loadConfig] bin:%j', result)
18
23
 
19
- return false;
20
- }
24
+ return result
25
+ };
21
26
 
22
- function loadConfig(prop) {
23
- const configFile = path.join(_basePath, prop);
27
+ function loadFile(filepath) {
28
+ const configFile = path.join(_basePath, filepath);
24
29
  if (!fs.existsSync(configFile)) {
25
- const errorTips = 'config file ' + chalk.blue(`${configFile}`) + ' does not exist !';
30
+ const errorTips = 'file ' + chalk.blue(`${configFile}`) + ' does not exist !';
26
31
  throw new Error(errorTips)
27
32
  }
28
33
 
@@ -45,24 +50,6 @@ function loadConfig(prop) {
45
50
  return result || {}
46
51
  };
47
52
 
48
- function loadEncryptConfig() {
49
- const configFile = './electron/config/encrypt.js';
50
- const filepath = path.join(_basePath, configFile);
51
- if (!fs.existsSync(filepath)) {
52
- const errorTips = 'config file ' + chalk.blue(`${filepath}`) + ' does not exist !';
53
- throw new Error(errorTips)
54
- }
55
- const obj = require(filepath);
56
- if (!obj) return obj;
57
-
58
- let ret = obj;
59
- if (is.function(obj) && !is.class(obj)) {
60
- ret = obj();
61
- }
62
-
63
- return ret || {};
64
- };
65
-
66
53
  /**
67
54
  * get electron program
68
55
  */
@@ -108,10 +95,30 @@ function compareVersion(v1, v2) {
108
95
  return 0
109
96
  }
110
97
 
111
- function isWindows(prop) {
98
+ function isWindows() {
112
99
  return process.platform === 'win32'
113
100
  }
114
101
 
102
+ function isOSX() {
103
+ return process.platform === 'darwin'
104
+ }
105
+
106
+ function isMacOS() {
107
+ return isOSX()
108
+ }
109
+
110
+ function isLinux() {
111
+ return process.platform === 'linux'
112
+ }
113
+
114
+ function isx86() {
115
+ return process.arch === 'ia32'
116
+ }
117
+
118
+ function isx64() {
119
+ return process.arch === 'x64'
120
+ }
121
+
115
122
  /**
116
123
  * Delete a file or folder
117
124
  */
@@ -133,9 +140,7 @@ function rm(name) {
133
140
  * 获取项目根目录package.json
134
141
  */
135
142
  function getPackage () {
136
- const homeDir = process.cwd();
137
- const content = readJsonSync(path.join(homeDir, 'package.json'));
138
-
143
+ const content = readJsonSync(path.join(_basePath, 'package.json'));
139
144
  return content;
140
145
  }
141
146
 
@@ -160,13 +165,43 @@ function writeJsonSync (filepath, str, options) {
160
165
  fs.writeFileSync(filepath, str);
161
166
  };
162
167
 
168
+ function getPlatform(delimiter = "_", isDiffArch = false) {
169
+ let os = "";
170
+ if (isWindows()) {
171
+ os = "windows";
172
+ if (isDiffArch) {
173
+ const arch = isx64() ? "64" : "32";
174
+ os += delimiter + arch;
175
+ }
176
+ } else if (isMacOS()) {
177
+ let isAppleSilicon = false;
178
+ const cpus = OS.cpus();
179
+ for (let cpu of cpus) {
180
+ if (cpu.model.includes('Apple')) {
181
+ isAppleSilicon = true;
182
+ break;
183
+ }
184
+ }
185
+ const core = isAppleSilicon? "apple" : "intel";
186
+ os = "macos" + delimiter + core;
187
+ } else if (isLinux()) {
188
+ os = "linux";
189
+ }
190
+
191
+ return os;
192
+ }
193
+
163
194
  module.exports = {
164
195
  loadConfig,
165
- checkConfig,
166
- loadEncryptConfig,
167
196
  getElectronProgram,
168
197
  compareVersion,
169
198
  isWindows,
199
+ isOSX,
200
+ isMacOS,
201
+ isLinux,
202
+ isx86,
203
+ isx64,
204
+ getPlatform,
170
205
  rm,
171
206
  getPackage,
172
207
  readJsonSync,
package/package.json CHANGED
@@ -1,28 +1,30 @@
1
1
  {
2
2
  "name": "ee-bin",
3
- "version": "2.0.0-beta.1",
3
+ "version": "4.0.0-beta.1",
4
4
  "description": "ee bin",
5
- "main": "index.cjs",
5
+ "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
8
8
  },
9
9
  "author": "",
10
10
  "license": "ISC",
11
11
  "bin": {
12
- "ee-bin": "index.cjs"
12
+ "ee-bin": "index.js"
13
13
  },
14
14
  "dependencies": {
15
+ "adm-zip": "^0.4.11",
15
16
  "bytenode": "^1.3.6",
16
17
  "chalk": "^4.1.2",
17
18
  "commander": "^11.0.0",
18
19
  "config-file-ts": "^0.2.8-rc1",
19
20
  "cross-spawn": "^7.0.3",
21
+ "debug": "^4.4.0",
22
+ "esbuild": "0.24.2",
20
23
  "fs-extra": "^10.0.0",
21
24
  "globby": "^10.0.0",
22
25
  "is-type-of": "^1.2.1",
23
26
  "javascript-obfuscator": "^4.0.2",
24
- "mkdirp": "^2.1.3",
25
- "adm-zip": "^0.4.11",
26
- "json5": "^2.2.3"
27
+ "json5": "^2.2.3",
28
+ "mkdirp": "^2.1.3"
27
29
  }
28
30
  }