ee-bin 2.0.0-beta.2 → 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.
@@ -0,0 +1,181 @@
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
+ force: false,
20
+ sync: false,
21
+ },
22
+ electron: {
23
+ directory: './',
24
+ cmd: 'electron',
25
+ args: ['.', '--env=local'],
26
+ loadingPage: '/public/html/loading.html',
27
+ watch: false,
28
+ sync: false,
29
+ },
30
+ },
31
+
32
+ /**
33
+ * 构建
34
+ * ee-bin build
35
+ */
36
+ build: {
37
+ frontend: {
38
+ directory: './frontend',
39
+ cmd: 'npm',
40
+ args: ['run', 'build'],
41
+ },
42
+ electron: {
43
+ type: 'javascript',
44
+ bundler: 'esbuild',
45
+ bundleType: 'bundle', // copy | bundle
46
+ javascript: {
47
+ entryPoints: ['./electron/**/*.js'],
48
+ platform: 'node',
49
+ bundle: false,
50
+ minify: false,
51
+ outdir: 'public/electron',
52
+ packages: 'external',
53
+ sourcemap:false,
54
+ sourcesContent: false
55
+ },
56
+ typescript: {
57
+ entryPoints: ['./electron/**/*.ts'],
58
+ tsconfig: './tsconfig.json',
59
+ platform: 'node',
60
+ format: 'cjs',
61
+ bundle: false,
62
+ minify: false,
63
+ outdir: 'public/electron',
64
+ packages: 'external',
65
+ sourcemap:false,
66
+ sourcesContent: false
67
+ }
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
+ },
109
+ },
110
+
111
+ /**
112
+ * 移动资源
113
+ * ee-bin move
114
+ */
115
+ move: {
116
+ frontend_dist: {
117
+ src: './frontend/dist',
118
+ dest: './public/dist'
119
+ }
120
+ },
121
+
122
+ /**
123
+ * 预发布模式(prod)
124
+ * ee-bin start
125
+ */
126
+ start: {
127
+ directory: './',
128
+ cmd: 'electron',
129
+ args: ['.', '--env=prod']
130
+ },
131
+
132
+ /**
133
+ * 加密
134
+ */
135
+ encrypt: {
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
+ }
173
+ }
174
+ },
175
+
176
+ /**
177
+ * 执行自定义命令
178
+ * ee-bin exec
179
+ */
180
+ exec: {},
181
+ };
package/index.js ADDED
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env node
2
+
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');
8
+
9
+ /**
10
+ * dev
11
+ */
12
+ program
13
+ .command('dev')
14
+ .description('create frontend-serve and electron-serve')
15
+ .option('--config <folder>', 'config file')
16
+ .option('--serve <mode>', 'serve mode')
17
+ .action(function() {
18
+ serveProcess.dev(this.opts());
19
+ });
20
+
21
+ /**
22
+ * build
23
+ */
24
+ program
25
+ .command('build')
26
+ .description('building multiple resources')
27
+ .option('--config <folder>', 'config file')
28
+ .option('--cmds <flag>', 'custom commands')
29
+ .option('--env <env>', 'environment')
30
+ .action(function() {
31
+ serveProcess.build(this.opts());
32
+ });
33
+
34
+ /**
35
+ * start
36
+ */
37
+ program
38
+ .command('start')
39
+ .description('preview effect')
40
+ .option('--config <folder>', 'config file')
41
+ .action(function() {
42
+ serveProcess.start(this.opts());
43
+ });
44
+
45
+ /**
46
+ * exec
47
+ */
48
+ program
49
+ .command('exec')
50
+ .description('create frontend-serve and electron-serve')
51
+ .option('--config <folder>', 'config file')
52
+ .option('--cmds <flag>', 'custom commands')
53
+ .action(function() {
54
+ serveProcess.exec(this.opts());
55
+ });
56
+
57
+ /**
58
+ * move - Moves resources
59
+ */
60
+ program
61
+ .command('move')
62
+ .description('Move multip resources')
63
+ .option('--config <folder>', 'config file')
64
+ .option('--flag <flag>', 'Custom flag')
65
+ .action(function() {
66
+ move(this.opts());
67
+ });
68
+
69
+ /**
70
+ * encrypt - Code encryption
71
+ */
72
+ program
73
+ .command('encrypt')
74
+ .description('Code encryption')
75
+ .option('--config <folder>', 'config file')
76
+ .option('--out <folder>', 'output directory')
77
+ .action(function() {
78
+ encrypt(this.opts());
79
+ });
80
+
81
+ /**
82
+ * clean - Clear the encrypted code
83
+ */
84
+ program
85
+ .command('clean')
86
+ .description('Clear the encrypted code')
87
+ .option('-d, --dir <folder>', 'clean directory')
88
+ .action(function() {
89
+ cleanEncrypt(this.opts());
90
+ });
91
+
92
+ /**
93
+ * icon
94
+ */
95
+ program
96
+ .command('icon')
97
+ .description('Generate logo')
98
+ .option('-i, --input <file>', 'image file default /public/images/logo.png')
99
+ .option('-o, --output <folder>', 'output directory default /build/icons/')
100
+ .action(function() {
101
+ const iconGen = require('./tools/iconGen');
102
+ iconGen.run();
103
+ });
104
+
105
+ /**
106
+ * updater
107
+ */
108
+ program
109
+ .command('updater')
110
+ .description('updater commands')
111
+ .option('--config <folder>', 'config file')
112
+ .option('--asar-file <file>', 'asar file path')
113
+ .option('--platform <flag>', 'platform')
114
+ .action(function() {
115
+ incrUpdater.run(this.opts());
116
+ });
117
+
118
+ 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,6 +1,6 @@
1
1
  {
2
2
  "name": "ee-bin",
3
- "version": "2.0.0-beta.2",
3
+ "version": "4.0.0",
4
4
  "description": "ee bin",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -9,20 +9,23 @@
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",
18
+ "chokidar": "^4.0.3",
17
19
  "commander": "^11.0.0",
18
20
  "config-file-ts": "^0.2.8-rc1",
19
21
  "cross-spawn": "^7.0.3",
22
+ "debug": "^4.4.0",
23
+ "esbuild": "0.24.2",
20
24
  "fs-extra": "^10.0.0",
21
25
  "globby": "^10.0.0",
22
26
  "is-type-of": "^1.2.1",
23
27
  "javascript-obfuscator": "^4.0.2",
24
- "mkdirp": "^2.1.3",
25
- "adm-zip": "^0.4.11",
26
- "json5": "^2.2.3"
28
+ "json5": "^2.2.3",
29
+ "mkdirp": "^2.1.3"
27
30
  }
28
31
  }