ee-core 2.12.0 → 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.
Files changed (159) hide show
  1. package/app/application.d.ts +5 -0
  2. package/app/application.js +31 -0
  3. package/app/boot.d.ts +5 -0
  4. package/app/boot.js +74 -0
  5. package/app/dir.d.ts +1 -0
  6. package/app/dir.js +27 -0
  7. package/app/events.d.ts +14 -0
  8. package/app/events.js +56 -0
  9. package/app/index.d.ts +2 -0
  10. package/app/index.js +7 -0
  11. package/config/config_loader.d.ts +13 -0
  12. package/config/config_loader.js +19 -23
  13. package/config/default_config.d.ts +95 -0
  14. package/config/default_config.js +111 -0
  15. package/config/index.d.ts +28 -0
  16. package/config/index.js +20 -37
  17. package/const/channel.d.ts +16 -0
  18. package/const/channel.js +26 -16
  19. package/controller/controller_loader.d.ts +9 -0
  20. package/controller/controller_loader.js +78 -0
  21. package/controller/index.d.ts +2 -0
  22. package/controller/index.js +18 -19
  23. package/core/index.d.ts +2 -0
  24. package/core/index.js +6 -5
  25. package/core/loader/file_loader.d.ts +66 -0
  26. package/core/{lib/loader → loader}/file_loader.js +39 -156
  27. package/core/utils/index.d.ts +12 -0
  28. package/core/utils/index.js +83 -0
  29. package/core/utils/timing.d.ts +22 -0
  30. package/core/{lib/utils → utils}/timing.js +3 -2
  31. package/cross/cross.d.ts +19 -0
  32. package/cross/cross.js +152 -0
  33. package/cross/crossProcess.d.ts +29 -0
  34. package/cross/{spawnProcess.js → crossProcess.js} +36 -53
  35. package/cross/index.d.ts +2 -0
  36. package/cross/index.js +6 -181
  37. package/electron/app/index.d.ts +5 -0
  38. package/electron/app/index.js +38 -54
  39. package/electron/index.d.ts +3 -0
  40. package/electron/index.js +13 -17
  41. package/electron/window/index.d.ts +6 -0
  42. package/electron/window/index.js +260 -65
  43. package/exception/index.d.ts +9 -0
  44. package/exception/index.js +42 -54
  45. package/html/index.d.ts +1 -0
  46. package/html/index.js +7 -10
  47. package/index.d.ts +2 -0
  48. package/index.js +4 -52
  49. package/jobs/child/app.d.ts +1 -0
  50. package/jobs/child/app.js +10 -10
  51. package/jobs/child/index.d.ts +13 -0
  52. package/jobs/child/index.js +14 -11
  53. package/jobs/child/jobProcess.d.ts +16 -0
  54. package/jobs/child/{forkProcess.js → jobProcess.js} +31 -62
  55. package/jobs/child-pool/index.d.ts +26 -0
  56. package/jobs/child-pool/index.js +25 -48
  57. package/jobs/index.d.ts +3 -0
  58. package/jobs/index.js +2 -4
  59. package/jobs/load-balancer/algorithm/index.d.ts +4 -0
  60. package/jobs/load-balancer/algorithm/minimumConnection.d.ts +2 -0
  61. package/jobs/load-balancer/algorithm/polling.d.ts +2 -0
  62. package/jobs/load-balancer/algorithm/random.d.ts +2 -0
  63. package/jobs/load-balancer/algorithm/specify.d.ts +2 -0
  64. package/jobs/load-balancer/algorithm/weights.d.ts +2 -0
  65. package/jobs/load-balancer/algorithm/weightsMinimumConnection.d.ts +2 -0
  66. package/jobs/load-balancer/algorithm/weightsPolling.d.ts +2 -0
  67. package/jobs/load-balancer/algorithm/weightsRandom.d.ts +2 -0
  68. package/jobs/load-balancer/consts.d.ts +8 -0
  69. package/jobs/load-balancer/index.d.ts +96 -0
  70. package/jobs/load-balancer/scheduler.d.ts +16 -0
  71. package/loader/index.d.ts +9 -0
  72. package/loader/index.js +73 -143
  73. package/log/index.d.ts +5 -0
  74. package/log/index.js +74 -57
  75. package/log/logger.d.ts +2 -0
  76. package/log/logger.js +75 -80
  77. package/message/childMessage.d.ts +10 -0
  78. package/message/childMessage.js +15 -25
  79. package/message/index.d.ts +3 -0
  80. package/message/index.js +7 -16
  81. package/package.json +8 -2
  82. package/ps/index.d.ts +37 -0
  83. package/ps/index.js +135 -238
  84. package/socket/httpServer.d.ts +8 -0
  85. package/socket/httpServer.js +55 -45
  86. package/socket/index.d.ts +10 -0
  87. package/socket/index.js +52 -69
  88. package/socket/ipcServer.d.ts +9 -0
  89. package/socket/ipcServer.js +87 -94
  90. package/socket/socketServer.d.ts +10 -0
  91. package/socket/socketServer.js +37 -25
  92. package/storage/index.d.ts +5 -0
  93. package/storage/index.js +5 -37
  94. package/storage/sqliteStorage.d.ts +16 -0
  95. package/storage/sqliteStorage.js +20 -20
  96. package/tsconfig.json +14 -0
  97. package/utils/extend.d.ts +2 -0
  98. package/utils/extend.js +10 -5
  99. package/utils/helper.d.ts +14 -0
  100. package/utils/helper.js +39 -53
  101. package/utils/index.d.ts +10 -0
  102. package/utils/index.js +47 -40
  103. package/utils/ip.d.ts +2 -0
  104. package/utils/ip.js +5 -45
  105. package/utils/is.d.ts +14 -0
  106. package/utils/is.js +107 -141
  107. package/utils/json.d.ts +5 -0
  108. package/utils/json.js +15 -7
  109. package/utils/pargv.d.ts +3 -0
  110. package/utils/pargv.js +5 -1
  111. package/utils/port/index.d.ts +1 -0
  112. package/utils/{get-port → port}/index.js +4 -26
  113. package/utils/wrap.d.ts +4 -0
  114. package/utils/wrap.js +8 -3
  115. package/addon/index.js +0 -35
  116. package/addon/window/index.js +0 -99
  117. package/bin/tools.js +0 -8
  118. package/config/cache.js +0 -62
  119. package/config/config.default.js +0 -331
  120. package/const/index.js +0 -9
  121. package/controller/baseContextClass.js +0 -25
  122. package/core/lib/ee.js +0 -216
  123. package/core/lib/loader/context_loader.js +0 -106
  124. package/core/lib/loader/ee_loader.js +0 -435
  125. package/core/lib/loader/mixin/addon.js +0 -32
  126. package/core/lib/loader/mixin/config.js +0 -130
  127. package/core/lib/loader/mixin/controller.js +0 -125
  128. package/core/lib/loader/mixin/service.js +0 -28
  129. package/core/lib/utils/base_context_class.js +0 -34
  130. package/core/lib/utils/function.js +0 -30
  131. package/core/lib/utils/index.js +0 -133
  132. package/core/lib/utils/sequencify.js +0 -59
  133. package/ee/appLoader.js +0 -48
  134. package/ee/application.js +0 -101
  135. package/ee/baseApp.js +0 -99
  136. package/ee/eeApp.js +0 -406
  137. package/ee/index.js +0 -58
  138. package/electron/window/winState.js +0 -186
  139. package/httpclient/index.js +0 -161
  140. package/jobs/baseJobClass.js +0 -16
  141. package/jobs/renderer/index.js +0 -141
  142. package/jobs/renderer/loadView.js +0 -41
  143. package/jobs/unification.js +0 -64
  144. package/main/index.js +0 -57
  145. package/old-utils/index.js +0 -91
  146. package/services/baseContextClass.js +0 -24
  147. package/services/index.js +0 -41
  148. package/socket/io.js +0 -28
  149. package/storage/jsondb/adapters/Base.js +0 -23
  150. package/storage/jsondb/adapters/FileSync.js +0 -64
  151. package/storage/jsondb/main.js +0 -55
  152. package/storage/jsondbStorage.js +0 -196
  153. package/utils/co.js +0 -237
  154. package/utils/copyto.js +0 -161
  155. package/utils/depd/index.js +0 -538
  156. package/utils/depd/lib/browser/index.js +0 -77
  157. package/utils/get-port/index.d.ts +0 -64
  158. package/utils/time/index.js +0 -20
  159. package/utils/time/ms.js +0 -162
@@ -0,0 +1,5 @@
1
+ import { SqliteStorage } from "./sqliteStorage";
2
+ import { Database } from "better-sqlite3";
3
+
4
+ export { Database };
5
+ export { SqliteStorage };
package/storage/index.js CHANGED
@@ -1,39 +1,7 @@
1
- const assert = require('assert');
2
- const _ = require('lodash');
3
- const DB = {};
1
+ 'use strict';
4
2
 
5
- // jsondb 要么每次new对象,要么所有地方都用同一个实例,否则会出现数据无法刷新的情况
3
+ const { SqliteStorage } = require('./sqliteStorage');
6
4
 
7
- DB.connection = function (database, options = {}) {
8
- let driver = options.driver || 'jsondb';
9
-
10
- // 兼容之前api
11
- driver = driver == 'lowdb' ? 'jsondb' : driver;
12
-
13
- let opt = options.default || {};
14
- if (!_.includes(['jsondb', 'sqlite'], driver)) {
15
- assert(database, `db driver ${driver} is not supported`);
16
- }
17
- if (_.isEmpty(database)) {
18
- assert(database, `db name ${database} Cannot be empty`);
19
- }
20
- let storage;
21
- switch (driver) {
22
- case 'jsondb':
23
- const JsondbStorage = require('./jsondbStorage');
24
- storage = new JsondbStorage(database);
25
- break;
26
- case 'sqlite':
27
- const SqliteStorage = require('./sqliteStorage');
28
- storage = new SqliteStorage(database, opt);
29
- break;
30
- default:
31
- }
32
-
33
- return storage;
34
- }
35
-
36
- // 兼容之前的api
37
- DB.JsonDB = DB;
38
-
39
- module.exports = DB;
5
+ module.exports = {
6
+ SqliteStorage
7
+ };
@@ -0,0 +1,16 @@
1
+
2
+ import { Database } from "better-sqlite3";
3
+ export declare class SqliteStorage {
4
+ constructor(name: any, opt?: {});
5
+ name: string;
6
+ mode: string;
7
+ dbDir: string;
8
+ fileName: string;
9
+ db: Database;
10
+ _initDB(opt?: {}): any;
11
+ _formatFileName(name: string): string;
12
+ _createDatabaseDir(): string;
13
+ getMode(name: string): string;
14
+ getDbDir(): string;
15
+ getFilePath(): string;
16
+ }
@@ -3,9 +3,9 @@
3
3
  const assert = require('assert');
4
4
  const fs = require('fs');
5
5
  const path = require('path');
6
- const Database = require('better-sqlite3');
7
- const Helper = require('../utils/helper');
8
- const Ps = require('../ps');
6
+ const BSqlite = require('better-sqlite3');
7
+ const { mkdir } = require('../utils/helper');
8
+ const { getDataDir } = require('../ps');
9
9
 
10
10
  class SqliteStorage {
11
11
  constructor (name, opt = {}) {
@@ -13,7 +13,7 @@ class SqliteStorage {
13
13
 
14
14
  this.name = name;
15
15
  this.mode = this.getMode(name);
16
- this.storageDir = this._createStorageDir();
16
+ this.dbDir = this._createDatabaseDir();
17
17
  this.fileName = this._formatFileName(name);
18
18
  this.db = this._initDB(opt);
19
19
  }
@@ -32,11 +32,11 @@ class SqliteStorage {
32
32
  dbPath = this.getFilePath();
33
33
  }
34
34
 
35
- const db = new Database(dbPath, options);
35
+ const db = new BSqlite(dbPath, options);
36
36
 
37
37
  // 如果是文件类型,判断文件是否创建成功
38
38
  if (this.mode != 'memory') {
39
- assert(fs.existsSync(dbPath), `error: storage ${dbPath} not exists`);
39
+ assert(fs.existsSync(dbPath), `error: db ${dbPath} not exists`);
40
40
  }
41
41
 
42
42
  return db;
@@ -57,19 +57,17 @@ class SqliteStorage {
57
57
  /**
58
58
  * 创建storage目录
59
59
  */
60
- _createStorageDir () {
61
- let storageDir = Ps.getStorageDir();
62
-
60
+ _createDatabaseDir () {
61
+ let dbDir = path.join(getDataDir(), 'db');
63
62
  if (this.mode == 'absolute') {
64
- storageDir = path.dirname(this.name);
63
+ dbDir = path.dirname(this.name);
65
64
  }
66
65
 
67
- if (!fs.existsSync(storageDir)) {
68
- Helper.mkdir(storageDir);
69
- Helper.chmodPath(storageDir, '777');
66
+ if (!fs.existsSync(dbDir)) {
67
+ mkdir(dbDir, { mode: 0o755 });
70
68
  }
71
69
 
72
- return storageDir;
70
+ return dbDir;
73
71
  }
74
72
 
75
73
  /**
@@ -84,7 +82,7 @@ class SqliteStorage {
84
82
  return mode;
85
83
  }
86
84
 
87
- assert(path.extname(name) == '.db', `error: storage ${name} file ext name must be .db`);
85
+ assert(path.extname(name) == '.db', `error: db ${name} file ext name must be .db`);
88
86
 
89
87
  // 路径模式
90
88
  name = name.replace(/[/\\]/g, '/');
@@ -105,20 +103,22 @@ class SqliteStorage {
105
103
  }
106
104
 
107
105
  /**
108
- * 获取storage目录
106
+ * 获取 db 文件目录
109
107
  */
110
- getStorageDir () {
111
- return this.storageDir;
108
+ getDbDir () {
109
+ return this.dbDir;
112
110
  }
113
111
 
114
112
  /**
115
113
  * 获取文件绝对路径
116
114
  */
117
115
  getFilePath () {
118
- const dbFile = path.join(this.storageDir, this.fileName);
116
+ const dbFile = path.join(this.dbDir, this.fileName);
119
117
 
120
118
  return dbFile;
121
119
  }
122
120
  }
123
121
 
124
- module.exports = SqliteStorage;
122
+ module.exports = {
123
+ SqliteStorage
124
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "skipLibCheck": true,
4
+ "allowJs": true,
5
+ "emitDeclarationOnly": true,
6
+ "declaration": true,
7
+ "outDir": "types",
8
+ },
9
+ "include": [
10
+ "index.js", "app", "config", "const", "controller", "core", "cross", "electron", "exception",
11
+ "html", "jobs", "loader", "log", "message", "ps", "socket", "storage", "utils",
12
+ ]
13
+ }
14
+
@@ -0,0 +1,2 @@
1
+ export declare function extend(...args: any[]): any;
2
+ export declare function isPlainObject(obj: any): any;
package/utils/extend.js CHANGED
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var hasOwn = Object.prototype.hasOwnProperty;
4
- var toStr = Object.prototype.toString;
3
+ const hasOwn = Object.prototype.hasOwnProperty;
4
+ const toStr = Object.prototype.toString;
5
5
 
6
- var isPlainObject = function isPlainObject(obj) {
6
+ function isPlainObject(obj) {
7
7
  if (!obj || toStr.call(obj) !== '[object Object]') {
8
8
  return false;
9
9
  }
@@ -23,8 +23,8 @@ var isPlainObject = function isPlainObject(obj) {
23
23
  return typeof key === 'undefined' || hasOwn.call(obj, key);
24
24
  };
25
25
 
26
- module.exports = function extend() {
27
- var options, name, src, copy, copyIsArray, clone;
26
+ function extend() {
27
+ var options, name, src, copy, clone;
28
28
  var target = arguments[0];
29
29
  var i = 1;
30
30
  var length = arguments.length;
@@ -71,3 +71,8 @@ module.exports = function extend() {
71
71
  // Return the modified object
72
72
  return target;
73
73
  };
74
+
75
+ module.exports = {
76
+ extend,
77
+ isPlainObject,
78
+ };
@@ -0,0 +1,14 @@
1
+ export declare function fnDebounce(): (fn: any, delayTime: any, isImediate: any, args: any) => any;
2
+ export declare function getRandomString(): string;
3
+ export declare function mkdir(filepath: string, opt?: {}): void;
4
+ export declare function chmodPath(path: string, mode: number | string): void;
5
+ export declare function compareVersion(v1: string, v2: string): 0 | 1 | -1;
6
+ export declare function middleware(fn: Function): any;
7
+ export declare function stringify(obj: any, ignore?: any[]): string;
8
+ export declare function validValue(value: any): boolean;
9
+ export declare function checkConfig(prop: any): boolean;
10
+ export declare function loadConfig(prop: any): any;
11
+ export declare function sleep(ms: number): Promise<any>;
12
+ export declare function replaceArgsValue(argv: any, key: any, value: any): any;
13
+ export declare function getValueFromArgv(argv: any, key: any): any;
14
+ export declare function fileIsExist(filepath: string): boolean;
package/utils/helper.js CHANGED
@@ -2,22 +2,13 @@ const fs = require('fs');
2
2
  const mkdirp = require('mkdirp');
3
3
  const convert = require('koa-convert');
4
4
  const is = require('is-type-of');
5
- const co = require('./co');
6
5
  const path = require('path');
7
6
  const chalk = require('chalk');
8
- const Pargv = require('./pargv');
7
+ const { parseArgv } = require('./pargv');
9
8
 
10
9
  const _basePath = process.cwd();
11
10
 
12
- /**
13
- * fnDebounce
14
- *
15
- * @param {Function} fn - 回调函数
16
- * @param {Time} delayTime - 延迟时间(ms)
17
- * @param {Boolean} isImediate - 是否需要立即调用
18
- * @param {type} args - 回调函数传入参数
19
- */
20
- exports.fnDebounce = function() {
11
+ function fnDebounce() {
21
12
  const fnObject = {};
22
13
  let timer;
23
14
 
@@ -43,25 +34,19 @@ exports.fnDebounce = function() {
43
34
  };
44
35
  }
45
36
 
46
- /**
47
- * 随机10位字符串
48
- */
49
- exports.getRandomString = function() {
37
+ // 随机10位字符串
38
+ function getRandomString() {
50
39
  return Math.random().toString(36).substring(2);
51
40
  };
52
41
 
53
- /**
54
- * 创建文件夹
55
- */
56
- exports.mkdir = function(filepath, opt = {}) {
42
+ // 创建文件夹
43
+ function mkdir(filepath, opt = {}) {
57
44
  mkdirp.sync(filepath, opt);
58
45
  return
59
46
  }
60
47
 
61
- /**
62
- * 修改文件权限
63
- */
64
- exports.chmodPath = function(path, mode) {
48
+ // 修改文件权限
49
+ function chmodPath(path, mode) {
65
50
  let files = [];
66
51
  if (fs.existsSync(path)) {
67
52
  files = fs.readdirSync(path);
@@ -77,10 +62,8 @@ exports.chmodPath = function(path, mode) {
77
62
  }
78
63
  };
79
64
 
80
- /**
81
- * 版本号比较
82
- */
83
- exports.compareVersion = function (v1, v2) {
65
+ // 版本号比较
66
+ function compareVersion(v1, v2) {
84
67
  v1 = v1.split('.')
85
68
  v2 = v2.split('.')
86
69
  const len = Math.max(v1.length, v2.length)
@@ -106,24 +89,12 @@ exports.compareVersion = function (v1, v2) {
106
89
  return 0
107
90
  }
108
91
 
109
- /**
110
- * 执行一个函数
111
- */
112
- exports.callFn = async function (fn, args, ctx) {
113
- args = args || [];
114
- if (!is.function(fn)) return;
115
- if (is.generatorFunction(fn)) fn = co.wrap(fn);
116
- return ctx ? fn.call(ctx, ...args) : fn(...args);
117
- }
118
-
119
- exports.middleware = function (fn) {
92
+ function middleware(fn) {
120
93
  return is.generatorFunction(fn) ? convert(fn) : fn;
121
94
  }
122
95
 
123
- /**
124
- * 序列化对象
125
- */
126
- exports.stringify = function(obj, ignore = []) {
96
+ // 序列化对象
97
+ function stringify(obj, ignore = []) {
127
98
  const result = {};
128
99
  Object.keys(obj).forEach(key => {
129
100
  if (!ignore.includes(key)) {
@@ -133,10 +104,8 @@ exports.stringify = function(obj, ignore = []) {
133
104
  return JSON.stringify(result);
134
105
  }
135
106
 
136
- /**
137
- * 是否有效值
138
- */
139
- exports.validValue = function(value) {
107
+ // 是否有效值
108
+ function validValue(value) {
140
109
  return (
141
110
  value !== undefined &&
142
111
  value !== null &&
@@ -144,7 +113,7 @@ exports.validValue = function(value) {
144
113
  );
145
114
  }
146
115
 
147
- exports.checkConfig = function(prop) {
116
+ function checkConfig(prop) {
148
117
  const filepath = path.join(_basePath, prop);
149
118
  if (fs.existsSync(filepath)) {
150
119
  return true;
@@ -153,7 +122,7 @@ exports.checkConfig = function(prop) {
153
122
  return false;
154
123
  }
155
124
 
156
- exports.loadConfig = function(prop) {
125
+ function loadConfig(prop) {
157
126
  const configFile = prop;
158
127
  const filepath = path.join(_basePath, configFile);
159
128
  if (!fs.existsSync(filepath)) {
@@ -171,11 +140,11 @@ exports.loadConfig = function(prop) {
171
140
  return ret || {};
172
141
  };
173
142
 
174
- exports.sleep = function(ms) {
143
+ function sleep(ms) {
175
144
  return new Promise(resolve => setTimeout(resolve, ms));
176
145
  };
177
146
 
178
- exports.replaceArgsValue = function(argv, key, value) {
147
+ function replaceArgsValue(argv, key, value) {
179
148
  key = key + "=";
180
149
  for (let i = 0; i < argv.length; i++) {
181
150
  let item = argv[i];
@@ -191,8 +160,8 @@ exports.replaceArgsValue = function(argv, key, value) {
191
160
  return argv;
192
161
  };
193
162
 
194
- exports.getValueFromArgv = function(argv, key) {
195
- const argvObj = Pargv(argv);
163
+ function getValueFromArgv(argv, key) {
164
+ const argvObj = parseArgv(argv);
196
165
  if (argvObj.hasOwnProperty(key)) {
197
166
  return argvObj[key];
198
167
  }
@@ -213,9 +182,26 @@ exports.getValueFromArgv = function(argv, key) {
213
182
  return value;
214
183
  };
215
184
 
216
- exports.fileIsExist = function(filepath) {
185
+ function fileIsExist(filepath) {
217
186
  if (fs.existsSync(filepath) && fs.statSync(filepath).isFile()) {
218
187
  return true;
219
188
  }
220
189
  return false;
190
+ };
191
+
192
+ module.exports = {
193
+ fnDebounce,
194
+ getRandomString,
195
+ mkdir,
196
+ chmodPath,
197
+ compareVersion,
198
+ middleware,
199
+ stringify,
200
+ validValue,
201
+ checkConfig,
202
+ loadConfig,
203
+ sleep,
204
+ replaceArgsValue,
205
+ getValueFromArgv,
206
+ fileIsExist
221
207
  };
@@ -0,0 +1,10 @@
1
+ export declare function getPackage(): any;
2
+ export declare function getMAC(iface: any): string;
3
+ export declare function isMAC(macAddress: string): boolean;
4
+ export declare function isFileProtocol(protocol: string): boolean;
5
+ export declare function isWebProtocol(protocol: string): boolean;
6
+ export declare function isJsProject(baseDir: string): boolean;
7
+ export declare function machineIdSync(original: boolean): any;
8
+ export declare function machineId(original: boolean): Promise<any>;
9
+ import is = require("./is");
10
+ export { is };
package/utils/index.js CHANGED
@@ -5,8 +5,9 @@ const path = require('path');
5
5
  const fs = require('fs');
6
6
  const { exec, execSync } = require('child_process');
7
7
  const { createHash } = require('crypto');
8
- const Ps = require('../ps');
9
- const UtilsJson = require('./json');
8
+ const { getBaseDir } = require('../ps');
9
+ const { readSync } = require('./json');
10
+ const is = require('./is');
10
11
 
11
12
  // machine id
12
13
  const { platform } = process;
@@ -16,27 +17,23 @@ const win32RegBinPath = {
16
17
  };
17
18
  const MachineGuid = {
18
19
  darwin: 'ioreg -rd1 -c IOPlatformExpertDevice',
19
- win32: `${win32RegBinPath[isWindowsProcessMixedOrNativeArchitecture()]}\\REG.exe ` +
20
+ win32: `${win32RegBinPath[_isWindowsProcessMixedOrNativeArchitecture()]}\\REG.exe ` +
20
21
  'QUERY HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography ' +
21
22
  '/v MachineGuid',
22
23
  linux: '( cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || hostname ) | head -n 1 || :',
23
24
  freebsd: 'kenv -q smbios.system.uuid || sysctl -n kern.hostuuid'
24
25
  };
25
26
 
26
- /**
27
- * 获取项目根目录package.json
28
- */
29
- exports.getPackage = function() {
30
- const json = UtilsJson.readSync(path.join(Ps.getHomeDir(), 'package.json'));
27
+ // 获取项目根目录package.json
28
+ function getPackage() {
29
+ const json = readSync(path.join(getBaseDir(), 'package.json'));
31
30
 
32
31
  return json;
33
32
  };
34
33
 
35
- /**
36
- * Get the first proper MAC address
37
- * @param iface If provided, restrict MAC address fetching to this interface
38
- */
39
- exports.getMAC = function(iface) {
34
+ // Get the first proper MAC address
35
+ // iface: If provided, restrict MAC address fetching to this interface
36
+ function getMAC(iface) {
40
37
  const zeroRegex = /(?:[0]{1,2}[:-]){5}[0]{1,2}/;
41
38
  const list = os.networkInterfaces();
42
39
  if (iface) {
@@ -67,38 +64,38 @@ exports.getMAC = function(iface) {
67
64
  throw new Error('failed to get the MAC address');
68
65
  }
69
66
 
70
- /**
71
- * Check if the input is a valid MAC address
72
- */
73
- exports.isMAC = function(macAddress) {
67
+ // Check if the input is a valid MAC address
68
+ function isMAC(macAddress) {
74
69
  const macRegex = /(?:[a-z0-9]{1,2}[:-]){5}[a-z0-9]{1,2}/i;
75
70
  return macRegex.test(macAddress);
76
71
  }
77
72
 
78
- /**
79
- * is encrypt
80
- */
81
- exports.isEncrypt = function(basePath) {
82
- const encryptDir = Ps.getEncryptDir(basePath);
83
- if (fs.existsSync(encryptDir)) {
73
+ function isFileProtocol(protocol) {
74
+ return protocol == 'file://';
75
+ }
76
+
77
+ function isWebProtocol(protocol) {
78
+ return ['http://', 'https://'].includes(protocol);
79
+ }
80
+
81
+ function isJsProject(baseDir) {
82
+ const entryFile1 = path.join(baseDir, 'electron/main.js');
83
+ const entryFile2 = path.join(baseDir, 'electron/index.js');
84
+ if (fs.existsSync(entryFile1) || fs.existsSync(entryFile2)) {
84
85
  return true;
85
86
  }
86
87
  return false;
87
88
  }
88
89
 
89
- /**
90
- * get machine id
91
- */
92
- exports.machineIdSync = function(original) {
93
- let id = expose(execSync(MachineGuid[platform]).toString());
94
- return original ? id : hash(id);
90
+ // get machine id
91
+ function machineIdSync(original) {
92
+ let id = _expose(execSync(MachineGuid[platform]).toString());
93
+ return original ? id : _hash(id);
95
94
  }
96
95
 
97
- /**
98
- * get machine id (promise)
99
- * original <Boolean>, If true return original value of machine id, otherwise return hashed value (sha-256), default: false
100
- */
101
- exports.machineId = function(original) {
96
+ // get machine id (promise)
97
+ // original <Boolean>, If true return original value of machine id, otherwise return hashed value (sha-256), default: false
98
+ function machineId(original) {
102
99
  return new Promise((resolve, reject) => {
103
100
  return exec(MachineGuid[platform], {}, (err, stdout, stderr) => {
104
101
  if (err) {
@@ -106,13 +103,13 @@ exports.machineId = function(original) {
106
103
  new Error(`Error while obtaining machine id: ${err.stack}`)
107
104
  );
108
105
  }
109
- let id = expose(stdout.toString());
110
- return resolve(original ? id : hash(id));
106
+ let id = _expose(stdout.toString());
107
+ return resolve(original ? id : _hash(id));
111
108
  });
112
109
  });
113
110
  }
114
111
 
115
- function isWindowsProcessMixedOrNativeArchitecture() {
112
+ function _isWindowsProcessMixedOrNativeArchitecture() {
116
113
  // detect if the node binary is the same arch as the Windows OS.
117
114
  // or if this is 32 bit node on 64 bit windows.
118
115
  if(process.platform !== 'win32') {
@@ -124,11 +121,11 @@ function isWindowsProcessMixedOrNativeArchitecture() {
124
121
  return 'native';
125
122
  }
126
123
 
127
- function hash(guid) {
124
+ function _hash(guid) {
128
125
  return createHash('sha256').update(guid).digest('hex');
129
126
  }
130
127
 
131
- function expose(result) {
128
+ function _expose(result) {
132
129
  switch (platform) {
133
130
  case 'darwin':
134
131
  return result
@@ -156,5 +153,15 @@ function expose(result) {
156
153
  }
157
154
  }
158
155
 
159
-
156
+ module.exports = {
157
+ getPackage,
158
+ getMAC,
159
+ isMAC,
160
+ isFileProtocol,
161
+ isWebProtocol,
162
+ isJsProject,
163
+ machineIdSync,
164
+ machineId,
165
+ is
166
+ }
160
167
 
package/utils/ip.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare function publicIpv4(options: any): Promise<any>;
2
+ export declare function publicIpv6(options: any): Promise<any>;
package/utils/ip.js CHANGED
@@ -128,7 +128,7 @@ const queryHttps = (version, options) => {
128
128
  try {
129
129
  const gotPromise = hc.request(url, requestOptions);
130
130
  gotPromise.cancel = () => {
131
- // todo
131
+ // ..
132
132
  }
133
133
  cancel = gotPromise.cancel;
134
134
 
@@ -178,9 +178,7 @@ const queryAll = (version, options) => {
178
178
  return promise;
179
179
  };
180
180
 
181
- /**
182
- * 查询 public ipv4
183
- */
181
+ // 查询 public ipv4
184
182
  function publicIpv4(options) {
185
183
  options = {
186
184
  ...defaults,
@@ -198,9 +196,7 @@ function publicIpv4(options) {
198
196
  return queryAll('v4', options);
199
197
  }
200
198
 
201
- /**
202
- * 查询public ipv6
203
- */
199
+ // 查询public ipv6
204
200
  function publicIpv6(options) {
205
201
  options = {
206
202
  ...defaults,
@@ -218,44 +214,8 @@ function publicIpv6(options) {
218
214
  return queryAll('v6', options);
219
215
  }
220
216
 
221
- /**
222
- * todo 未来趋势是ipv6优先,以后再放开
223
- */
224
- const publicIp = createPublicIp(publicIpv4, publicIpv6);
225
- function createPublicIp(publicIpv4, publicIpv6) {
226
- return function publicIp(options) {
227
- const ipv4Promise = publicIpv4(options);
228
- const ipv6Promise = publicIpv6(options);
229
-
230
- const promise = (async () => {
231
- try {
232
- const ipv6 = await ipv6Promise;
233
- ipv4Promise.cancel();
234
- return ipv6;
235
- } catch (ipv6Error) {
236
- //Log.coreLogger.error('[ee-core] [utils/ip] publicIp ipv6Error:', ipv6Error);
237
- try {
238
- return await ipv4Promise;
239
- } catch (ipv4Error) {
240
- //Log.coreLogger.error('[ee-core] [utils/ip] publicIp ipv4Error:', ipv4Error);
241
- }
242
- }
243
- })();
244
-
245
- promise.cancel = () => {
246
- ipv4Promise.cancel();
247
- ipv6Promise.cancel();
248
- };
249
-
250
- return promise;
251
- };
252
- }
253
-
254
- const IP = {
255
- //publicIp,
217
+ module.exports = {
256
218
  publicIpv4,
257
219
  publicIpv6
258
- }
259
-
260
- module.exports = IP;
220
+ };
261
221
 
package/utils/is.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ export declare function renderer(): boolean;
2
+ export declare function main(): boolean;
3
+ export declare function osx(): boolean;
4
+ export declare function macOS(): boolean;
5
+ export declare function windows(): boolean;
6
+ export declare function linux(): boolean;
7
+ export declare function x86(): boolean;
8
+ export declare function x64(): boolean;
9
+ export declare function sandbox(): boolean;
10
+ export declare function mas(): boolean;
11
+ export declare function windowsStore(): boolean;
12
+ export declare function all(...args: any[]): boolean;
13
+ export declare function none(...args: any[]): boolean;
14
+ export declare function one(...args: any[]): boolean;