ee-bin 1.5.0 → 1.7.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/index.js +135 -120
- package/lib/pargv.js +263 -263
- package/lib/utils.js +174 -111
- package/package.json +28 -24
- package/tools/encrypt.js +315 -315
- package/tools/iconGen.js +182 -182
- package/tools/incrUpdater.js +133 -0
- package/tools/move.js +84 -84
- package/tools/replaceDist.js +82 -82
- package/tools/serve.js +167 -163
package/lib/utils.js
CHANGED
|
@@ -1,111 +1,174 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const chalk = require('chalk');
|
|
6
|
-
const is = require('is-type-of');
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
let
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const chalk = require('chalk');
|
|
6
|
+
const is = require('is-type-of');
|
|
7
|
+
const { loadTsConfig } = require('config-file-ts');
|
|
8
|
+
const JsonLib = require('json5');
|
|
9
|
+
const mkdirp = require('mkdirp');
|
|
10
|
+
|
|
11
|
+
const _basePath = process.cwd();
|
|
12
|
+
|
|
13
|
+
function checkConfig(prop) {
|
|
14
|
+
const filepath = path.join(_basePath, prop);
|
|
15
|
+
if (fs.existsSync(filepath)) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function loadConfig(prop) {
|
|
23
|
+
const configFile = path.join(_basePath, prop);
|
|
24
|
+
if (!fs.existsSync(configFile)) {
|
|
25
|
+
const errorTips = 'config file ' + chalk.blue(`${configFile}`) + ' does not exist !';
|
|
26
|
+
throw new Error(errorTips)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let result;
|
|
30
|
+
if (configFile.endsWith(".json5") || configFile.endsWith(".json")) {
|
|
31
|
+
const data = fs.readFileSync(configFile, 'utf8');
|
|
32
|
+
return JsonLib.parse(data);
|
|
33
|
+
}
|
|
34
|
+
if (configFile.endsWith(".js") || configFile.endsWith(".cjs")) {
|
|
35
|
+
result = require(configFile);
|
|
36
|
+
if (result.default != null) {
|
|
37
|
+
result = result.default;
|
|
38
|
+
}
|
|
39
|
+
} else if (configFile.endsWith(".ts")) {
|
|
40
|
+
result = loadTsConfig(configFile);
|
|
41
|
+
}
|
|
42
|
+
if (is.function(result) && !is.class(result)) {
|
|
43
|
+
result = result();
|
|
44
|
+
}
|
|
45
|
+
return result || {}
|
|
46
|
+
};
|
|
47
|
+
|
|
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
|
+
/**
|
|
67
|
+
* get electron program
|
|
68
|
+
*/
|
|
69
|
+
function getElectronProgram() {
|
|
70
|
+
let electronPath
|
|
71
|
+
const electronModulePath = path.dirname(require.resolve('electron'))
|
|
72
|
+
const pathFile = path.join(electronModulePath, 'path.txt')
|
|
73
|
+
const executablePath = fs.readFileSync(pathFile, 'utf-8')
|
|
74
|
+
if (executablePath) {
|
|
75
|
+
electronPath = path.join(electronModulePath, 'dist', executablePath)
|
|
76
|
+
} else {
|
|
77
|
+
throw new Error('Check that electron is installed!')
|
|
78
|
+
}
|
|
79
|
+
return electronPath;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 版本号比较
|
|
84
|
+
*/
|
|
85
|
+
function compareVersion(v1, v2) {
|
|
86
|
+
v1 = v1.split('.')
|
|
87
|
+
v2 = v2.split('.')
|
|
88
|
+
const len = Math.max(v1.length, v2.length)
|
|
89
|
+
|
|
90
|
+
while (v1.length < len) {
|
|
91
|
+
v1.push('0')
|
|
92
|
+
}
|
|
93
|
+
while (v2.length < len) {
|
|
94
|
+
v2.push('0')
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
for (let i = 0; i < len; i++) {
|
|
98
|
+
const num1 = parseInt(v1[i])
|
|
99
|
+
const num2 = parseInt(v2[i])
|
|
100
|
+
|
|
101
|
+
if (num1 > num2) {
|
|
102
|
+
return 1
|
|
103
|
+
} else if (num1 < num2) {
|
|
104
|
+
return -1
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return 0
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function isWindows(prop) {
|
|
112
|
+
return process.platform === 'win32'
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Delete a file or folder
|
|
117
|
+
*/
|
|
118
|
+
function rm(name) {
|
|
119
|
+
// check
|
|
120
|
+
if (!fs.existsSync(name)) {
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const nodeVersion = (process.versions && process.versions.node) || null;
|
|
125
|
+
if (nodeVersion && compareVersion(nodeVersion, '14.14.0') == 1) {
|
|
126
|
+
fs.rmSync(name, {recursive: true});
|
|
127
|
+
} else {
|
|
128
|
+
fs.rmdirSync(name, {recursive: true});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 获取项目根目录package.json
|
|
134
|
+
*/
|
|
135
|
+
function getPackage () {
|
|
136
|
+
const homeDir = process.cwd();
|
|
137
|
+
const content = readJsonSync(path.join(homeDir, 'package.json'));
|
|
138
|
+
|
|
139
|
+
return content;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function readJsonSync (filepath) {
|
|
143
|
+
if (!fs.existsSync(filepath)) {
|
|
144
|
+
throw new Error(filepath + ' is not found');
|
|
145
|
+
}
|
|
146
|
+
return JSON.parse(fs.readFileSync(filepath));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function writeJsonSync (filepath, str, options) {
|
|
150
|
+
options = options || {};
|
|
151
|
+
if (!('space' in options)) {
|
|
152
|
+
options.space = 2;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
mkdirp.sync(path.dirname(filepath));
|
|
156
|
+
if (typeof str === 'object') {
|
|
157
|
+
str = JSON.stringify(str, options.replacer, options.space) + '\n';
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
fs.writeFileSync(filepath, str);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
module.exports = {
|
|
164
|
+
loadConfig,
|
|
165
|
+
checkConfig,
|
|
166
|
+
loadEncryptConfig,
|
|
167
|
+
getElectronProgram,
|
|
168
|
+
compareVersion,
|
|
169
|
+
isWindows,
|
|
170
|
+
rm,
|
|
171
|
+
getPackage,
|
|
172
|
+
readJsonSync,
|
|
173
|
+
writeJsonSync
|
|
174
|
+
}
|
package/package.json
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "ee-bin",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "ee bin",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
-
},
|
|
9
|
-
"author": "",
|
|
10
|
-
"license": "ISC",
|
|
11
|
-
"bin": {
|
|
12
|
-
"ee-bin": "index.js"
|
|
13
|
-
},
|
|
14
|
-
"dependencies": {
|
|
15
|
-
"bytenode": "^1.3.6",
|
|
16
|
-
"chalk": "^4.1.2",
|
|
17
|
-
"commander": "^11.0.0",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "ee-bin",
|
|
3
|
+
"version": "1.7.0-beta.1",
|
|
4
|
+
"description": "ee bin",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"author": "",
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"bin": {
|
|
12
|
+
"ee-bin": "index.js"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"bytenode": "^1.3.6",
|
|
16
|
+
"chalk": "^4.1.2",
|
|
17
|
+
"commander": "^11.0.0",
|
|
18
|
+
"config-file-ts": "^0.2.8-rc1",
|
|
19
|
+
"cross-spawn": "^7.0.3",
|
|
20
|
+
"fs-extra": "^10.0.0",
|
|
21
|
+
"globby": "^10.0.0",
|
|
22
|
+
"is-type-of": "^1.2.1",
|
|
23
|
+
"javascript-obfuscator": "^4.0.2",
|
|
24
|
+
"mkdirp": "^2.1.3",
|
|
25
|
+
"adm-zip": "^0.4.11",
|
|
26
|
+
"json5": "^2.2.3"
|
|
27
|
+
}
|
|
28
|
+
}
|