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.
- package/config/bin_default.js +112 -0
- package/{index.cjs → index.js} +52 -72
- package/lib/extend.js +78 -0
- package/lib/{utils.cjs → utils.js} +69 -34
- package/package.json +8 -6
- package/tools/encrypt.js +197 -0
- package/tools/{incrUpdater.cjs → incrUpdater.js} +27 -111
- package/tools/move.js +69 -0
- package/tools/{serve.cjs → serve.js} +64 -41
- package/tools/encrypt.cjs +0 -316
- package/tools/move.cjs +0 -85
- package/tools/replaceDist.cjs +0 -83
- /package/lib/{pargv.cjs → pargv.js} +0 -0
- /package/tools/{iconGen.cjs → iconGen.js} +0 -0
package/tools/encrypt.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const fsPro = require('fs-extra');
|
|
6
|
+
const is = require('is-type-of');
|
|
7
|
+
const bytenode = require('bytenode');
|
|
8
|
+
const JavaScriptObfuscator = require('javascript-obfuscator');
|
|
9
|
+
const globby = require('globby');
|
|
10
|
+
const chalk = require('chalk');
|
|
11
|
+
const { loadConfig } = require('../lib/utils');
|
|
12
|
+
|
|
13
|
+
const EncryptTypes = ['bytecode', 'confusion', 'strict'];
|
|
14
|
+
|
|
15
|
+
class Encrypt {
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
// cli args
|
|
18
|
+
const { config, out } = options;
|
|
19
|
+
this.basePath = process.cwd();
|
|
20
|
+
|
|
21
|
+
const cfg = loadConfig(config);
|
|
22
|
+
this.config = cfg.encrypt;
|
|
23
|
+
const outputFolder = out || this.config.encryptDir;
|
|
24
|
+
this.encryptDir = path.join(this.basePath, outputFolder);
|
|
25
|
+
this.filesExt = this.config.fileExt;
|
|
26
|
+
this.type = this.config.type;
|
|
27
|
+
this.bOpt = this.config.bytecodeOptions;
|
|
28
|
+
this.cOpt = this.config.confusionOptions;
|
|
29
|
+
this.cleanFiles = this.config.cleanFiles;
|
|
30
|
+
this.patterns = this.config.files || null;
|
|
31
|
+
this.specFiles = this.config.specificFiles;
|
|
32
|
+
|
|
33
|
+
this.codefiles = this._initCodeFiles();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 初始化需要加密的文件列表
|
|
38
|
+
*/
|
|
39
|
+
_initCodeFiles() {
|
|
40
|
+
if (!this.patterns) return;
|
|
41
|
+
|
|
42
|
+
const files = globby.sync(this.patterns, { cwd: this.basePath });
|
|
43
|
+
return files;
|
|
44
|
+
}
|
|
45
|
+
|
|
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
|
+
/**
|
|
78
|
+
* 加密代码
|
|
79
|
+
*/
|
|
80
|
+
encrypt() {
|
|
81
|
+
console.log(chalk.blue('[ee-bin] [encrypt] ') + 'start ciphering');
|
|
82
|
+
console.log(this.codefiles);
|
|
83
|
+
for (const file of this.codefiles) {
|
|
84
|
+
const fullpath = path.join(this.encryptCodeDir, file);
|
|
85
|
+
if (!fs.statSync(fullpath).isFile()) continue;
|
|
86
|
+
|
|
87
|
+
// 特殊文件处理
|
|
88
|
+
if (this.specFiles.includes(file)) {
|
|
89
|
+
this.generate(fullpath, 'confusion');
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
this.generate(fullpath);
|
|
94
|
+
}
|
|
95
|
+
console.log(chalk.blue('[ee-bin] [encrypt] ') + 'end ciphering');
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* 递归
|
|
100
|
+
*/
|
|
101
|
+
loop(dirPath) {
|
|
102
|
+
let files = [];
|
|
103
|
+
if (fs.existsSync(dirPath)) {
|
|
104
|
+
files = fs.readdirSync(dirPath);
|
|
105
|
+
files.forEach((file, index) => {
|
|
106
|
+
let curPath = dirPath + '/' + file;
|
|
107
|
+
if (fs.statSync(curPath).isDirectory()) {
|
|
108
|
+
this.loop(curPath);
|
|
109
|
+
} else {
|
|
110
|
+
const extname = path.extname(curPath);
|
|
111
|
+
if (this.filesExt.indexOf(extname) !== -1) {
|
|
112
|
+
this.generate(curPath);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 生成文件
|
|
121
|
+
*/
|
|
122
|
+
generate(curPath, type) {
|
|
123
|
+
let encryptType = type ? type : this.type;
|
|
124
|
+
|
|
125
|
+
let tips = chalk.blue('[ee-bin] [encrypt] ') + 'file: ' + chalk.green(`${curPath}`) + ' ' + chalk.cyan(`(${encryptType})`);
|
|
126
|
+
console.log(tips);
|
|
127
|
+
if (encryptType == 'strict') {
|
|
128
|
+
this.generateJSConfuseFile(curPath);
|
|
129
|
+
this.generateBytecodeFile(curPath);
|
|
130
|
+
} else if (encryptType == 'bytecode') {
|
|
131
|
+
this.generateBytecodeFile(curPath);
|
|
132
|
+
} else if (encryptType == 'confusion') {
|
|
133
|
+
this.generateJSConfuseFile(curPath);
|
|
134
|
+
} else {
|
|
135
|
+
// none
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 使用 javascript-obfuscator 生成压缩/混淆文件
|
|
141
|
+
*/
|
|
142
|
+
generateJSConfuseFile(file) {
|
|
143
|
+
let opt = Object.assign({
|
|
144
|
+
compact: true,
|
|
145
|
+
stringArray: true,
|
|
146
|
+
stringArrayThreshold: 1,
|
|
147
|
+
}, this.cOpt);
|
|
148
|
+
|
|
149
|
+
let code = fs.readFileSync(file, "utf8");
|
|
150
|
+
let result = JavaScriptObfuscator.obfuscate(code, opt);
|
|
151
|
+
fs.writeFileSync(file, result.getObfuscatedCode(), "utf8");
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 生成字节码文件
|
|
156
|
+
*/
|
|
157
|
+
generateBytecodeFile(curPath) {
|
|
158
|
+
if (path.extname(curPath) !== '.js') {
|
|
159
|
+
return
|
|
160
|
+
}
|
|
161
|
+
//let jscFile = curPath.replace(/.js/g, '.jsc');
|
|
162
|
+
let jscFile = curPath + 'c';
|
|
163
|
+
let opt = Object.assign({
|
|
164
|
+
filename: curPath,
|
|
165
|
+
output: jscFile,
|
|
166
|
+
electron: true
|
|
167
|
+
}, this.bOpt);
|
|
168
|
+
|
|
169
|
+
bytenode.compileFile(opt);
|
|
170
|
+
fsPro.removeSync(curPath);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
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();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function cleanEncrypt(options = {}) {
|
|
182
|
+
let files = options.dir !== undefined ? options.dir : ['./public/electron'];
|
|
183
|
+
files = is.string(files) ? [files] : files;
|
|
184
|
+
|
|
185
|
+
files.forEach((file) => {
|
|
186
|
+
const tmpFile = path.join(process.cwd(), file);
|
|
187
|
+
if (fs.existsSync(tmpFile)) {
|
|
188
|
+
fsPro.removeSync(tmpFile);
|
|
189
|
+
console.log(chalk.blue('[ee-bin] [encrypt] ') + 'clean up tmp files: ' + chalk.magenta(`${tmpFile}`));
|
|
190
|
+
}
|
|
191
|
+
})
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
module.exports = {
|
|
195
|
+
encrypt,
|
|
196
|
+
cleanEncrypt,
|
|
197
|
+
};
|
|
@@ -4,7 +4,7 @@ const path = require('path');
|
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
const crypto = require('crypto')
|
|
6
6
|
const chalk = require('chalk');
|
|
7
|
-
const
|
|
7
|
+
const { loadConfig, rm, getPackage, writeJsonSync } = require('../lib/utils');
|
|
8
8
|
const admZip = require('adm-zip')
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -12,15 +12,15 @@ const admZip = require('adm-zip')
|
|
|
12
12
|
* @class
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
class IncrUpdater {
|
|
16
|
+
|
|
17
17
|
/**
|
|
18
18
|
* 执行
|
|
19
19
|
*/
|
|
20
20
|
run(options = {}) {
|
|
21
21
|
console.log('[ee-bin] [updater] Start');
|
|
22
22
|
const { config, asarFile, platform } = options;
|
|
23
|
-
const binCfg =
|
|
23
|
+
const binCfg = loadConfig(config);
|
|
24
24
|
const cfg = binCfg.updater;
|
|
25
25
|
|
|
26
26
|
if (!cfg) {
|
|
@@ -28,20 +28,21 @@ module.exports = {
|
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
this.generateFile(cfg, asarFile, platform);
|
|
33
|
-
} else {
|
|
34
|
-
this.generateFileOld(cfg, asarFile);
|
|
35
|
-
}
|
|
31
|
+
this.generateFile(cfg, asarFile, platform);
|
|
36
32
|
|
|
37
33
|
console.log('[ee-bin] [updater] End');
|
|
38
|
-
}
|
|
34
|
+
}
|
|
39
35
|
|
|
40
36
|
/**
|
|
41
37
|
* 生成增量升级文件
|
|
42
38
|
*/
|
|
43
39
|
generateFile(config, asarFile, platform) {
|
|
44
40
|
const cfg = config[platform];
|
|
41
|
+
if (!cfg) {
|
|
42
|
+
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${platform} config does not exist`));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
45
46
|
let latestVersionInfo = {}
|
|
46
47
|
const homeDir = process.cwd();
|
|
47
48
|
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.green(`${platform} config:`), cfg);
|
|
@@ -66,7 +67,7 @@ module.exports = {
|
|
|
66
67
|
return;
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
const packageJson =
|
|
70
|
+
const packageJson = getPackage();
|
|
70
71
|
const version = packageJson.version;
|
|
71
72
|
let platformForFilename = platform;
|
|
72
73
|
if (platform.indexOf("_") !== -1) {
|
|
@@ -79,7 +80,7 @@ module.exports = {
|
|
|
79
80
|
zipName = path.basename(cfg.output.zip, '.zip') + `-${platformForFilename}-${version}.zip`;
|
|
80
81
|
const asarZipPath = path.join(homeDir, cfg.output.directory, zipName);
|
|
81
82
|
if (fs.existsSync(asarZipPath)) {
|
|
82
|
-
|
|
83
|
+
rm(asarZipPath);
|
|
83
84
|
}
|
|
84
85
|
const zip = new admZip();
|
|
85
86
|
// 添加 asar 文件
|
|
@@ -114,107 +115,17 @@ module.exports = {
|
|
|
114
115
|
const jsonName = path.basename(cfg.output.file, '.json') + `-${platformForFilename}.json`;
|
|
115
116
|
latestVersionInfo = item;
|
|
116
117
|
const updaterJsonFilePath = path.join(homeDir, cfg.output.directory, jsonName);
|
|
117
|
-
|
|
118
|
+
writeJsonSync(updaterJsonFilePath, latestVersionInfo);
|
|
118
119
|
|
|
119
120
|
// 删除缓存文件,防止生成的 zip 是旧版本
|
|
120
121
|
if (cfg.cleanCache) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
rm(path.join(homeDir, cfg.output.directory, 'mac'));
|
|
123
|
+
rm(path.join(homeDir, cfg.output.directory, 'mac-arm64'));
|
|
124
|
+
rm(path.join(homeDir, cfg.output.directory, 'win-unpacked'));
|
|
125
|
+
rm(path.join(homeDir, cfg.output.directory, 'win-ia32-unpacked'));
|
|
126
|
+
rm(path.join(homeDir, cfg.output.directory, 'linux-unpacked'));
|
|
126
127
|
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* 将废弃
|
|
131
|
-
*/
|
|
132
|
-
generateFileOld(cfg, asarFile) {
|
|
133
|
-
var latestVersionInfo = {}
|
|
134
|
-
const homeDir = process.cwd();
|
|
135
|
-
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.green('config:'), cfg);
|
|
136
|
-
|
|
137
|
-
let asarFilePath = "";
|
|
138
|
-
if (asarFile) {
|
|
139
|
-
asarFilePath = path.normalize(path.join(homeDir, asarFile));
|
|
140
|
-
} else if (Array.isArray(cfg.asarFile)) {
|
|
141
|
-
// 检查文件列表,如果存在就跳出
|
|
142
|
-
for (const filep of cfg.asarFile) {
|
|
143
|
-
asarFilePath = path.normalize(path.join(homeDir, filep));
|
|
144
|
-
if (fs.existsSync(asarFilePath)) {
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
} else {
|
|
149
|
-
asarFilePath = path.normalize(path.join(homeDir, cfg.asarFile));
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (!fs.existsSync(asarFilePath)) {
|
|
153
|
-
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${asarFilePath} does not exist`));
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const packageJson = Utils.getPackage();
|
|
158
|
-
const version = packageJson.version;
|
|
159
|
-
const platformForFilename = Utils.getPlatform("-");
|
|
160
|
-
const platformForKey = Utils.getPlatform("_");
|
|
161
|
-
|
|
162
|
-
// 生成 zip
|
|
163
|
-
let zipName = "";
|
|
164
|
-
if (cfg.output.noPlatform === true) {
|
|
165
|
-
zipName = path.basename(cfg.output.zip, '.zip') + `-${version}.zip`;
|
|
166
|
-
} else {
|
|
167
|
-
zipName = path.basename(cfg.output.zip, '.zip') + `-${platformForFilename}-${version}.zip`;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const asarZipPath = path.join(homeDir, cfg.output.directory, zipName);
|
|
171
|
-
if (fs.existsSync(asarZipPath) && cfg.cleanCache) {
|
|
172
|
-
Utils.rm(asarZipPath);
|
|
173
|
-
}
|
|
174
|
-
const zip = new admZip();
|
|
175
|
-
zip.addLocalFile(asarFilePath);
|
|
176
|
-
zip.writeZip(asarZipPath, (err) => {
|
|
177
|
-
if (err) {
|
|
178
|
-
console.log(chalk.blue('[ee-bin] [updater] create zip ') + chalk.red(`Error: ${err}`));
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
const sha1 = this.generateSha1(asarFilePath);
|
|
183
|
-
const date = this._getFormattedDate();
|
|
184
|
-
const fileStat = fs.statSync(asarFilePath);
|
|
185
|
-
|
|
186
|
-
const item = {
|
|
187
|
-
version: version,
|
|
188
|
-
file: zipName,
|
|
189
|
-
size: fileStat.size,
|
|
190
|
-
sha1: sha1,
|
|
191
|
-
releaseDate: date,
|
|
192
|
-
};
|
|
193
|
-
let jsonName = "";
|
|
194
|
-
if (cfg.output.noPlatform === true) {
|
|
195
|
-
jsonName = cfg.output.file;
|
|
196
|
-
latestVersionInfo = item;
|
|
197
|
-
} else {
|
|
198
|
-
// 生成与系统有关的文件
|
|
199
|
-
jsonName = path.basename(cfg.output.file, '.json') + `-${platformForFilename}.json`;
|
|
200
|
-
if (platformForKey !== "") {
|
|
201
|
-
latestVersionInfo[platformForKey] = item;
|
|
202
|
-
} else {
|
|
203
|
-
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${platformForFilename} is not supported`));
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const updaterJsonFilePath = path.join(homeDir, cfg.output.directory, jsonName);
|
|
208
|
-
Utils.writeJsonSync(updaterJsonFilePath, latestVersionInfo);
|
|
209
|
-
|
|
210
|
-
// 删除缓存文件,防止生成的 zip 是旧版本
|
|
211
|
-
if (cfg.cleanCache) {
|
|
212
|
-
Utils.rm(path.join(homeDir, cfg.output.directory, 'mac'));
|
|
213
|
-
Utils.rm(path.join(homeDir, cfg.output.directory, 'mac-arm64'));
|
|
214
|
-
Utils.rm(path.join(homeDir, cfg.output.directory, 'win-unpacked'));
|
|
215
|
-
Utils.rm(path.join(homeDir, cfg.output.directory, 'linux-unpacked'));
|
|
216
|
-
}
|
|
217
|
-
},
|
|
128
|
+
}
|
|
218
129
|
|
|
219
130
|
generateSha1(filepath = "") {
|
|
220
131
|
let sha1 = '';
|
|
@@ -239,7 +150,7 @@ module.exports = {
|
|
|
239
150
|
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${error}`));
|
|
240
151
|
}
|
|
241
152
|
return sha1;
|
|
242
|
-
}
|
|
153
|
+
}
|
|
243
154
|
|
|
244
155
|
_getFormattedDate() {
|
|
245
156
|
const date = new Date(); // 获取当前日期
|
|
@@ -248,5 +159,10 @@ module.exports = {
|
|
|
248
159
|
const day = date.getDate().toString().padStart(2, '0'); // 获取日
|
|
249
160
|
|
|
250
161
|
return `${year}-${month}-${day}`;
|
|
251
|
-
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
module.exports = {
|
|
166
|
+
IncrUpdater,
|
|
167
|
+
incrUpdater: new IncrUpdater()
|
|
252
168
|
}
|
package/tools/move.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const fsPro = require('fs-extra');
|
|
6
|
+
const chalk = require('chalk');
|
|
7
|
+
const { loadConfig, rm } = require('../lib/utils');
|
|
8
|
+
|
|
9
|
+
const homeDir = process.cwd();
|
|
10
|
+
|
|
11
|
+
// 移动资源
|
|
12
|
+
function move(options = {}) {
|
|
13
|
+
console.log('[ee-bin] [move] Start moving resources');
|
|
14
|
+
const { config, flag } = options;
|
|
15
|
+
const binCfg = loadConfig(config);
|
|
16
|
+
const moveConfig = binCfg.move;
|
|
17
|
+
|
|
18
|
+
let flags;
|
|
19
|
+
const flagString = flag.trim();
|
|
20
|
+
if (flagString.indexOf(',') !== -1) {
|
|
21
|
+
flags = flagString.split(',');
|
|
22
|
+
} else {
|
|
23
|
+
flags = [flagString];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
for (let i = 0; i < flags.length; i++) {
|
|
27
|
+
let f = flags[i];
|
|
28
|
+
let cfg = moveConfig[f];
|
|
29
|
+
|
|
30
|
+
if (!cfg) {
|
|
31
|
+
console.log(chalk.blue('[ee-bin] [move] ') + chalk.red(`Error: ${f} config does not exist` ));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const { src, dest, dist, target } = cfg;
|
|
36
|
+
const source = dist ? dist : src;
|
|
37
|
+
const destination = target ? target : dest;
|
|
38
|
+
|
|
39
|
+
console.log(chalk.blue('[ee-bin] [move] ') + chalk.green(`Move flag: ${f}`));
|
|
40
|
+
console.log(chalk.blue('[ee-bin] [move] ') + chalk.green('config:'), cfg);
|
|
41
|
+
|
|
42
|
+
const srcResource = path.join(homeDir, source);
|
|
43
|
+
if (!fs.existsSync(srcResource)) {
|
|
44
|
+
const errorTips = chalk.bgRed('Error') + ` ${source} resource does not exist !`;
|
|
45
|
+
console.error(errorTips);
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// clear the historical resource and copy it to the ee resource directory
|
|
50
|
+
const destResource = path.join(homeDir, destination);
|
|
51
|
+
if (fs.statSync(srcResource).isDirectory() && !fs.existsSync(destResource)) {
|
|
52
|
+
fs.mkdirSync(destResource, {recursive: true, mode: 0o777});
|
|
53
|
+
} else {
|
|
54
|
+
rm(destResource);
|
|
55
|
+
console.log('[ee-bin] [move] Clear history resources:', destResource);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
fsPro.copySync(srcResource, destResource);
|
|
59
|
+
|
|
60
|
+
// [todo] go project, special treatment of package.json, reserved only necessary
|
|
61
|
+
console.log(`[ee-bin] [move] Copy ${srcResource} to ${destResource}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
console.log('[ee-bin] [move] End');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = {
|
|
68
|
+
move
|
|
69
|
+
}
|
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const debug = require('debug')('ee-bin:serve');
|
|
3
4
|
const path = require('path');
|
|
4
|
-
const
|
|
5
|
+
const { loadConfig } = require('../lib/utils');
|
|
5
6
|
const is = require('is-type-of');
|
|
6
7
|
const chalk = require('chalk');
|
|
7
8
|
const crossSpawn = require('cross-spawn');
|
|
9
|
+
const { buildSync } = require('esbuild');
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
class ServeProcess {
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
constructor() {
|
|
14
|
+
this.execProcess = {};
|
|
15
|
+
}
|
|
12
16
|
|
|
13
17
|
/**
|
|
14
18
|
* 启动前端、主进程服务
|
|
15
19
|
*/
|
|
16
20
|
dev(options = {}) {
|
|
17
21
|
const { config, serve } = options;
|
|
22
|
+
const binCfg = loadConfig(config);
|
|
18
23
|
const binCmd = 'dev';
|
|
19
|
-
const binCfg = Utils.loadConfig(config);
|
|
20
24
|
const binCmdConfig = binCfg[binCmd];
|
|
21
25
|
|
|
22
26
|
let command = serve;
|
|
@@ -24,21 +28,27 @@ module.exports = {
|
|
|
24
28
|
command = Object.keys(binCmdConfig).join();
|
|
25
29
|
}
|
|
26
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
|
+
|
|
27
37
|
const opt = {
|
|
28
38
|
binCmd,
|
|
29
39
|
binCmdConfig,
|
|
30
40
|
command,
|
|
31
41
|
}
|
|
32
42
|
this.multiExec(opt);
|
|
33
|
-
}
|
|
43
|
+
}
|
|
34
44
|
|
|
35
45
|
/**
|
|
36
46
|
* 启动主进程服务
|
|
37
47
|
*/
|
|
38
48
|
start(options = {}) {
|
|
39
49
|
const { config } = options;
|
|
50
|
+
const binCfg = loadConfig(config);
|
|
40
51
|
const binCmd = 'start';
|
|
41
|
-
const binCfg = Utils.loadConfig(config);
|
|
42
52
|
const binCmdConfig = {
|
|
43
53
|
start: binCfg[binCmd]
|
|
44
54
|
};
|
|
@@ -49,63 +59,56 @@ module.exports = {
|
|
|
49
59
|
command: binCmd,
|
|
50
60
|
}
|
|
51
61
|
this.multiExec(opt);
|
|
52
|
-
}
|
|
62
|
+
}
|
|
53
63
|
|
|
54
64
|
sleep(ms) {
|
|
55
65
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
56
|
-
}
|
|
66
|
+
}
|
|
57
67
|
|
|
58
68
|
/**
|
|
59
69
|
* 构建
|
|
60
70
|
*/
|
|
61
71
|
build(options = {}) {
|
|
62
72
|
const { config, cmds } = options;
|
|
73
|
+
const binCfg = loadConfig(config);
|
|
63
74
|
const binCmd = 'build';
|
|
64
|
-
const binCfg = Utils.loadConfig(config);
|
|
65
75
|
const binCmdConfig = binCfg[binCmd];
|
|
66
76
|
|
|
67
77
|
if (!cmds || cmds == "") {
|
|
68
|
-
|
|
69
|
-
let tip = chalk.bgYellow('Warning') + ' Please modify the ' + chalk.blue('build') + ' config, See: ';
|
|
70
|
-
tip += chalk.underline('https://www.kaka996.com/pages/c492f8/');
|
|
78
|
+
const tip = chalk.bgYellow('Warning') + ' Please modify the ' + chalk.blue('build') + ' property in the bin file';
|
|
71
79
|
console.log(tip);
|
|
72
80
|
return
|
|
73
81
|
}
|
|
74
82
|
|
|
83
|
+
if (cmds.indexOf("electron") !== -1) {
|
|
84
|
+
this.bundle(false, binCfg.build.electron);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
75
88
|
const opt = {
|
|
76
89
|
binCmd,
|
|
77
90
|
binCmdConfig,
|
|
78
91
|
command: cmds,
|
|
79
92
|
}
|
|
80
93
|
this.multiExec(opt);
|
|
81
|
-
}
|
|
94
|
+
}
|
|
82
95
|
|
|
83
96
|
/**
|
|
84
97
|
* 执行自定义命令
|
|
85
98
|
*/
|
|
86
99
|
exec(options = {}) {
|
|
87
|
-
|
|
100
|
+
const { config, cmds } = options;
|
|
101
|
+
const binCfg = loadConfig(config);
|
|
88
102
|
const binCmd = 'exec';
|
|
89
|
-
const binCfg = Utils.loadConfig(config);
|
|
90
103
|
const binCmdConfig = binCfg[binCmd];
|
|
91
104
|
|
|
92
|
-
// if (typeof command !== "string" || !cmds) {
|
|
93
|
-
// console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + chalk.red(`Error: Please specify parameters for --cmds` ));
|
|
94
|
-
// return
|
|
95
|
-
// }
|
|
96
|
-
|
|
97
|
-
// 兼容
|
|
98
|
-
if (typeof command === "string") {
|
|
99
|
-
cmds = command;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
105
|
const opt = {
|
|
103
106
|
binCmd,
|
|
104
107
|
binCmdConfig,
|
|
105
108
|
command: cmds,
|
|
106
109
|
}
|
|
107
110
|
this.multiExec(opt);
|
|
108
|
-
}
|
|
111
|
+
}
|
|
109
112
|
|
|
110
113
|
/**
|
|
111
114
|
* 支持多个命令
|
|
@@ -113,18 +116,11 @@ module.exports = {
|
|
|
113
116
|
multiExec(opt = {}) {
|
|
114
117
|
//console.log('multiExec opt:', opt)
|
|
115
118
|
const { binCmd, binCmdConfig, command } = opt;
|
|
116
|
-
|
|
117
|
-
let cmds;
|
|
118
|
-
const cmdString = command.trim();
|
|
119
|
-
if (cmdString.indexOf(',') !== -1) {
|
|
120
|
-
cmds = cmdString.split(',');
|
|
121
|
-
} else {
|
|
122
|
-
cmds = [cmdString];
|
|
123
|
-
}
|
|
119
|
+
const cmds = this._formatCmds(command);
|
|
124
120
|
|
|
125
121
|
for (let i = 0; i < cmds.length; i++) {
|
|
126
122
|
let cmd = cmds[i];
|
|
127
|
-
|
|
123
|
+
const cfg = binCmdConfig[cmd];
|
|
128
124
|
|
|
129
125
|
if (!cfg) {
|
|
130
126
|
console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + chalk.red(`Error: [${binCmd} ${cmd}] config does not exist` ));
|
|
@@ -132,16 +128,16 @@ module.exports = {
|
|
|
132
128
|
}
|
|
133
129
|
|
|
134
130
|
// frontend 如果是 file:// 协议,则不启动
|
|
135
|
-
if (cmd == 'frontend' && cfg.protocol == 'file://') {
|
|
131
|
+
if (binCmd == 'dev' && cmd == 'frontend' && cfg.protocol == 'file://') {
|
|
136
132
|
continue;
|
|
137
133
|
}
|
|
138
134
|
|
|
139
135
|
console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + "Run " + chalk.green(`[${binCmd} ${cmd}]` + " command"));
|
|
140
136
|
console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + chalk.green('config:'), JSON.stringify(cfg));
|
|
141
137
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
138
|
+
const execDir = path.join(process.cwd(), cfg.directory);
|
|
139
|
+
const execArgs = is.string(cfg.args) ? [cfg.args] : cfg.args;
|
|
140
|
+
const stdio = cfg.stdio ? cfg.stdio: 'inherit';
|
|
145
141
|
|
|
146
142
|
const handler = cfg.sync ? crossSpawn.sync : crossSpawn;
|
|
147
143
|
|
|
@@ -158,10 +154,37 @@ module.exports = {
|
|
|
158
154
|
console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + chalk.green('Press "CTRL+C" to exit'));
|
|
159
155
|
return
|
|
160
156
|
}
|
|
161
|
-
console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + 'The ' + chalk.green(`[${binCmd} ${cmd}]`) + ' command
|
|
157
|
+
console.log(chalk.blue(`[ee-bin] [${binCmd}] `) + 'The ' + chalk.green(`[${binCmd} ${cmd}]`) + ' command has been executed and exited');
|
|
162
158
|
});
|
|
163
159
|
}
|
|
164
160
|
}
|
|
165
|
-
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// esbuild
|
|
164
|
+
bundle(isDev = false, bundleConfig) {
|
|
165
|
+
const esbuildOptions = bundleConfig[bundleConfig.language];
|
|
166
|
+
if (isDev) {
|
|
167
|
+
// [todo]
|
|
168
|
+
}
|
|
169
|
+
debug('esbuild options:%O', esbuildOptions);
|
|
170
|
+
buildSync(esbuildOptions);
|
|
171
|
+
}
|
|
166
172
|
|
|
173
|
+
// format commands
|
|
174
|
+
_formatCmds(command) {
|
|
175
|
+
let cmds;
|
|
176
|
+
const cmdString = command.trim();
|
|
177
|
+
if (cmdString.indexOf(',') !== -1) {
|
|
178
|
+
cmds = cmdString.split(',');
|
|
179
|
+
} else {
|
|
180
|
+
cmds = [cmdString];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return cmds;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
module.exports = {
|
|
188
|
+
ServeProcess,
|
|
189
|
+
serveProcess: new ServeProcess()
|
|
167
190
|
}
|