ee-bin 1.5.0-beta.1 → 1.6.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.
package/lib/utils.js CHANGED
@@ -1,111 +1,121 @@
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 _basePath = process.cwd();
9
-
10
- function checkConfig(prop) {
11
- const filepath = path.join(_basePath, prop);
12
- if (fs.existsSync(filepath)) {
13
- return true;
14
- }
15
-
16
- return false;
17
- }
18
-
19
- function loadConfig(prop) {
20
- const configFile = prop;
21
- const filepath = path.join(_basePath, configFile);
22
- if (!fs.existsSync(filepath)) {
23
- const errorTips = 'config file ' + chalk.blue(`${filepath}`) + ' does not exist !';
24
- throw new Error(errorTips)
25
- }
26
- const obj = require(filepath);
27
- if (!obj) return obj;
28
-
29
- let ret = obj;
30
- if (is.function(obj) && !is.class(obj)) {
31
- ret = obj();
32
- }
33
-
34
- return ret || {};
35
- };
36
-
37
- function loadEncryptConfig() {
38
- const configFile = './electron/config/encrypt.js';
39
- const filepath = path.join(_basePath, configFile);
40
- if (!fs.existsSync(filepath)) {
41
- const errorTips = 'config file ' + chalk.blue(`${filepath}`) + ' does not exist !';
42
- throw new Error(errorTips)
43
- }
44
- const obj = require(filepath);
45
- if (!obj) return obj;
46
-
47
- let ret = obj;
48
- if (is.function(obj) && !is.class(obj)) {
49
- ret = obj();
50
- }
51
-
52
- return ret || {};
53
- };
54
-
55
- /**
56
- * get electron program
57
- */
58
- function getElectronProgram() {
59
- let electronPath
60
- const electronModulePath = path.dirname(require.resolve('electron'))
61
- const pathFile = path.join(electronModulePath, 'path.txt')
62
- const executablePath = fs.readFileSync(pathFile, 'utf-8')
63
- if (executablePath) {
64
- electronPath = path.join(electronModulePath, 'dist', executablePath)
65
- } else {
66
- throw new Error('Check that electron is installed!')
67
- }
68
- return electronPath;
69
- };
70
-
71
- /**
72
- * 版本号比较
73
- */
74
- function compareVersion(v1, v2) {
75
- v1 = v1.split('.')
76
- v2 = v2.split('.')
77
- const len = Math.max(v1.length, v2.length)
78
-
79
- while (v1.length < len) {
80
- v1.push('0')
81
- }
82
- while (v2.length < len) {
83
- v2.push('0')
84
- }
85
-
86
- for (let i = 0; i < len; i++) {
87
- const num1 = parseInt(v1[i])
88
- const num2 = parseInt(v2[i])
89
-
90
- if (num1 > num2) {
91
- return 1
92
- } else if (num1 < num2) {
93
- return -1
94
- }
95
- }
96
-
97
- return 0
98
- }
99
-
100
- function isWindows(prop) {
101
- return process.platform === 'win32'
102
- }
103
-
104
- module.exports = {
105
- loadConfig,
106
- checkConfig,
107
- loadEncryptConfig,
108
- getElectronProgram,
109
- compareVersion,
110
- isWindows
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
+
10
+ const _basePath = process.cwd();
11
+
12
+ function checkConfig(prop) {
13
+ const filepath = path.join(_basePath, prop);
14
+ if (fs.existsSync(filepath)) {
15
+ return true;
16
+ }
17
+
18
+ return false;
19
+ }
20
+
21
+ function loadConfig(prop) {
22
+ const configFile = path.join(_basePath, prop);
23
+ if (!fs.existsSync(configFile)) {
24
+ const errorTips = 'config file ' + chalk.blue(`${configFile}`) + ' does not exist !';
25
+ throw new Error(errorTips)
26
+ }
27
+
28
+ let result;
29
+ if (configFile.endsWith(".json5") || configFile.endsWith(".json")) {
30
+ const data = fs.readFileSync(configFile, 'utf8');
31
+ return JsonLib.parse(data);
32
+ }
33
+ if (configFile.endsWith(".js") || configFile.endsWith(".cjs")) {
34
+ result = require(configFile);
35
+ if (result.default != null) {
36
+ result = result.default;
37
+ }
38
+ } else if (configFile.endsWith(".ts")) {
39
+ result = loadTsConfig(configFile);
40
+ }
41
+ if (is.function(result) && !is.class(result)) {
42
+ result = result();
43
+ }
44
+ return result || {}
45
+ };
46
+
47
+ function loadEncryptConfig() {
48
+ const configFile = './electron/config/encrypt.js';
49
+ const filepath = path.join(_basePath, configFile);
50
+ if (!fs.existsSync(filepath)) {
51
+ const errorTips = 'config file ' + chalk.blue(`${filepath}`) + ' does not exist !';
52
+ throw new Error(errorTips)
53
+ }
54
+ const obj = require(filepath);
55
+ if (!obj) return obj;
56
+
57
+ let ret = obj;
58
+ if (is.function(obj) && !is.class(obj)) {
59
+ ret = obj();
60
+ }
61
+
62
+ return ret || {};
63
+ };
64
+
65
+ /**
66
+ * get electron program
67
+ */
68
+ function getElectronProgram() {
69
+ let electronPath
70
+ const electronModulePath = path.dirname(require.resolve('electron'))
71
+ const pathFile = path.join(electronModulePath, 'path.txt')
72
+ const executablePath = fs.readFileSync(pathFile, 'utf-8')
73
+ if (executablePath) {
74
+ electronPath = path.join(electronModulePath, 'dist', executablePath)
75
+ } else {
76
+ throw new Error('Check that electron is installed!')
77
+ }
78
+ return electronPath;
79
+ };
80
+
81
+ /**
82
+ * 版本号比较
83
+ */
84
+ function compareVersion(v1, v2) {
85
+ v1 = v1.split('.')
86
+ v2 = v2.split('.')
87
+ const len = Math.max(v1.length, v2.length)
88
+
89
+ while (v1.length < len) {
90
+ v1.push('0')
91
+ }
92
+ while (v2.length < len) {
93
+ v2.push('0')
94
+ }
95
+
96
+ for (let i = 0; i < len; i++) {
97
+ const num1 = parseInt(v1[i])
98
+ const num2 = parseInt(v2[i])
99
+
100
+ if (num1 > num2) {
101
+ return 1
102
+ } else if (num1 < num2) {
103
+ return -1
104
+ }
105
+ }
106
+
107
+ return 0
108
+ }
109
+
110
+ function isWindows(prop) {
111
+ return process.platform === 'win32'
112
+ }
113
+
114
+ module.exports = {
115
+ loadConfig,
116
+ checkConfig,
117
+ loadEncryptConfig,
118
+ getElectronProgram,
119
+ compareVersion,
120
+ isWindows
121
+ }
package/package.json CHANGED
@@ -1,24 +1,26 @@
1
- {
2
- "name": "ee-bin",
3
- "version": "1.5.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
- "cross-spawn": "^7.0.3",
19
- "fs-extra": "^10.0.0",
20
- "globby": "^10.0.0",
21
- "is-type-of": "^1.2.1",
22
- "javascript-obfuscator": "^4.0.2"
23
- }
24
- }
1
+ {
2
+ "name": "ee-bin",
3
+ "version": "1.6.0",
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
+ "json5": "^2.2.3"
25
+ }
26
+ }