ee-core 1.5.2-beta.2 → 2.0.0-beta.2

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 (61) hide show
  1. package/config/config.default.js +8 -1
  2. package/core/lib/ee.js +1 -1
  3. package/core/lib/loader/ee_loader.js +23 -45
  4. package/core/lib/loader/mixin/config.js +6 -11
  5. package/core/lib/loader/mixin/controller.js +3 -2
  6. package/core/lib/utils/function.js +30 -0
  7. package/core/lib/utils/index.js +6 -0
  8. package/index.js +2 -2
  9. package/lib/appLoader.js +0 -5
  10. package/lib/application.js +12 -9
  11. package/lib/baseApp.js +9 -26
  12. package/lib/eeApp.js +18 -52
  13. package/{lib/constant.js → module/const/index.js} +3 -0
  14. package/module/exception/index.js +16 -0
  15. package/{lib/httpclient.js → module/httpclient/index.js} +45 -11
  16. package/module/jobs/child/app.js +23 -0
  17. package/module/jobs/child/forkProcess.js +104 -0
  18. package/module/jobs/child/index.js +35 -0
  19. package/module/jobs/index.js +56 -0
  20. package/module/jobs/renderer/index.js +140 -0
  21. package/module/jobs/renderer/loadView.js +40 -0
  22. package/module/loader/index.js +130 -0
  23. package/module/log/index.js +53 -0
  24. package/module/log/logger.js +61 -0
  25. package/module/message/index.js +13 -0
  26. package/module/message/ipcMain.js +160 -0
  27. package/module/message/ipcRender.js +0 -0
  28. package/{lib → module}/socket/ipcServer.js +6 -8
  29. package/{lib → module}/socket/socketClient.js +4 -3
  30. package/{lib → module}/socket/socketServer.js +4 -3
  31. package/module/socket/start.js +22 -0
  32. package/{lib → module}/storage/index.js +16 -13
  33. package/module/storage/jsondb/adapters/Base.js +14 -0
  34. package/module/storage/jsondb/adapters/FileSync.js +32 -0
  35. package/{lib/storage/lowdb → module/storage/jsondb}/main.js +6 -10
  36. package/{lib/storage/lowdbStorage.js → module/storage/jsondbStorage.js} +12 -14
  37. package/{lib → module}/storage/sqliteStorage.js +7 -11
  38. package/module/utils/copyto.js +161 -0
  39. package/module/utils/helper.js +117 -0
  40. package/module/utils/index.js +120 -0
  41. package/module/utils/json.js +72 -0
  42. package/module/utils/ps.js +196 -0
  43. package/{utils → module/utils}/wrap.js +0 -2
  44. package/package.json +3 -7
  45. package/tools/encrypt.js +2 -2
  46. package/utils/index.js +17 -135
  47. package/lib/logger.js +0 -47
  48. package/lib/socket/start.js +0 -22
  49. package/lib/storage/lowdb/adapters/Base.js +0 -15
  50. package/lib/storage/lowdb/adapters/FileAsync.js +0 -41
  51. package/lib/storage/lowdb/adapters/FileSync.js +0 -39
  52. package/lib/storage/lowdb/adapters/LocalStorage.js +0 -20
  53. package/lib/storage/lowdb/adapters/Memory.js +0 -8
  54. package/lib/storage/lowdb/adapters/_stringify.js +0 -4
  55. package/lib/storage/lowdb/common.js +0 -33
  56. package/lib/storage/lowdb/fp.js +0 -23
  57. package/lib/storage/lowdb/isPromise.js +0 -6
  58. package/lib/storage/lowdb/nano.js +0 -5
  59. package/utils/common.js +0 -91
  60. /package/{lib → module}/socket/httpServer.js +0 -0
  61. /package/{lib → module}/socket/io.js +0 -0
package/utils/index.js CHANGED
@@ -1,35 +1,28 @@
1
- 'use strict';
1
+ /**
2
+ * 该模块不在增加新功能,请使用 /module/utils/index 模块
3
+ */
2
4
 
3
5
  const path = require('path');
4
- const constant = require('../lib/constant');
5
- const convert = require('koa-convert');
6
- const is = require('is-type-of');
7
- const co = require('co');
8
- const utility = require('utility');
9
6
  const eis = require('electron-is');
10
- const utilsCommon = require('./common');
7
+ const UtilsJson = require('../module/utils/json');
8
+ const UtilsPs = require('../module/utils/ps');
9
+ const UtilsHelper = require('../module/utils/helper');
10
+ const Copy = require('../module/utils/copyto');
11
+ const Storage = require('../module/storage');
12
+ const Constants = require('../module/const');
11
13
 
12
14
  /**
13
- * 创建文件夹
15
+ * other module
14
16
  */
15
- exports.mkdir = function (dirpath, dirname) {
16
- return utilsCommon.mkdir(dirpath, dirname);
17
- }
18
-
19
- /**
20
- * 修改文件权限
21
- */
22
- exports.chmodPath = function (path, mode) {
23
- return utilsCommon.chmodPath(path, mode);
24
- }
17
+ Copy(UtilsPs)
18
+ .and(UtilsHelper)
19
+ .to(exports);
25
20
 
26
21
  /**
27
22
  * 获取项目根目录package.json
28
23
  */
29
24
  exports.getPackage = function() {
30
- const cdb = this.getCoreDB();
31
- const config = cdb.getItem('config');
32
- const json = utility.readJSONSync(path.join(config.homeDir, 'package.json'));
25
+ const json = UtilsJson.readSync(path.join(this.getHomeDir(), 'package.json'));
33
26
 
34
27
  return json;
35
28
  };
@@ -38,20 +31,10 @@ exports.getPackage = function() {
38
31
  * 获取 coredb
39
32
  */
40
33
  exports.getCoreDB = function() {
41
- const coreDB = require('../lib/storage/index').JsonDB.connection('system');
34
+ const coreDB = Storage.connection('system');
42
35
  return coreDB;
43
36
  }
44
37
 
45
- /**
46
- * 获取 当前环境
47
- */
48
- exports.getEnv = function() {
49
- const cdb = this.getCoreDB();
50
- const env = cdb.getItem('config').env;
51
-
52
- return env;
53
- }
54
-
55
38
  /**
56
39
  * 获取 ee配置
57
40
  */
@@ -62,75 +45,6 @@ exports.getEeConfig = function() {
62
45
  return config;
63
46
  }
64
47
 
65
- /**
66
- * 获取 数据库存储路径
67
- */
68
- exports.getStorageDir = function() {
69
- const cdb = this.getCoreDB();
70
- const env = cdb.getItem('config').env;
71
-
72
- const appDir = env === 'local' || env === 'unittest' ? this.getHomeDir() : this.getAppUserDataDir();
73
- const storageDir = path.join(appDir, 'data');
74
-
75
- return storageDir;
76
- }
77
-
78
- /**
79
- * 获取 应用程序数据目录 (开发环境时,为项目根目录)
80
- */
81
- exports.getAppUserDataDir = function() {
82
- const cdb = this.getCoreDB();
83
- const config = cdb.getItem('config');
84
- const env = config.env;
85
- const dir = env === 'local' || env === 'unittest' ? config.homeDir : config.appUserDataDir;
86
- return dir;
87
- }
88
-
89
- /**
90
- * 获取 日志目录
91
- */
92
- exports.getLogDir = function() {
93
- const cdb = this.getCoreDB();
94
- const logPath = cdb.getItem('config').logger.dir;
95
- return logPath;
96
- }
97
-
98
- /**
99
- * 获取 home目录
100
- */
101
- exports.getHomeDir = function() {
102
- const cdb = this.getCoreDB();
103
- const homePath = cdb.getItem('config').homeDir;
104
- return homePath;
105
- }
106
-
107
- /**
108
- * 获取 base目录
109
- */
110
- exports.getBaseDir = function() {
111
- const cdb = this.getCoreDB();
112
- const basePath = cdb.getItem('config').baseDir;
113
- return basePath;
114
- }
115
-
116
- /**
117
- * 获取 root目录
118
- */
119
- exports.getRootDir = function() {
120
- const cdb = this.getCoreDB();
121
- const rootPath = cdb.getItem('config').root;
122
- return rootPath;
123
- }
124
-
125
- /**
126
- * 获取 appUserData目录
127
- */
128
- exports.getAppUserDataDir = function() {
129
- const cdb = this.getCoreDB();
130
- const dataPath = cdb.getItem('config').appUserDataDir;
131
- return dataPath;
132
- }
133
-
134
48
  /**
135
49
  * 获取 app version
136
50
  */
@@ -140,15 +54,6 @@ exports.getAppVersion = function() {
140
54
  return v;
141
55
  }
142
56
 
143
- /**
144
- * 获取 exec目录
145
- */
146
- exports.getExecDir = function() {
147
- const cdb = this.getCoreDB();
148
- const execPath = cdb.getItem('config').execDir;
149
- return execPath;
150
- }
151
-
152
57
  /**
153
58
  * 获取 插件配置
154
59
  */
@@ -198,16 +103,14 @@ exports.getSocketPort = function() {
198
103
  * 获取 socket channel
199
104
  */
200
105
  exports.getSocketChannel = function() {
201
- return constant.socketIo.channel;
106
+ return Constants.socketIo.channel;
202
107
  }
203
108
 
204
109
  /**
205
110
  * 获取 额外资源目录
206
111
  */
207
112
  exports.getExtraResourcesDir = function() {
208
- const cdb = this.getCoreDB();
209
- const config = cdb.getItem('config');
210
- const execDir = config.execDir;
113
+ const execDir = this.getExecDir();
211
114
 
212
115
  // 资源路径不同
213
116
  let dir = '';
@@ -223,25 +126,4 @@ exports.getExtraResourcesDir = function() {
223
126
  dir = path.join(execDir, "build", "extraResources");
224
127
  }
225
128
  return dir;
226
- }
227
-
228
- /**
229
- * 执行一个函数
230
- */
231
- exports.callFn = async function (fn, args, ctx) {
232
- args = args || [];
233
- if (!is.function(fn)) return;
234
- if (is.generatorFunction(fn)) fn = co.wrap(fn);
235
- return ctx ? fn.call(ctx, ...args) : fn(...args);
236
- }
237
-
238
- exports.middleware = function (fn) {
239
- return is.generatorFunction(fn) ? convert(fn) : fn;
240
- }
241
-
242
- /**
243
- * 版本号比较
244
- */
245
- exports.compareVersion = function (v1, v2) {
246
- return utilsCommon.compareVersion(v1, v2);
247
129
  }
package/lib/logger.js DELETED
@@ -1,47 +0,0 @@
1
- 'use strict';
2
-
3
- const debug = require('debug')('ee-core:logger');
4
- const Loggers = require('egg-logger').EggLoggers;
5
- const assert = require('assert');
6
-
7
- class Logger {
8
- constructor (config) {
9
- debug('Loaded logger');
10
- assert(Object.keys(config).length != 0, `logger config is null`);
11
- this.eggLogger = this.init(config);
12
- }
13
-
14
- /**
15
- * 单例
16
- */
17
- static getInstance (config = {}) {
18
- if (typeof this.instance === 'object') {
19
- return this.instance.eggLogger;
20
- }
21
-
22
- this.instance = new Logger(config);
23
-
24
- // 返回egg-logger实例
25
- return this.instance.eggLogger;
26
- }
27
-
28
- /**
29
- * 初始化模块
30
- */
31
- init(config) {
32
- const loggerConfig = config.logger;
33
- loggerConfig.type = 'application'; // application、agent
34
-
35
- if (config.env === 'prod' && loggerConfig.level === 'DEBUG' && !loggerConfig.allowDebugAtProd) {
36
- loggerConfig.level = 'INFO';
37
- }
38
-
39
- const loggers = new Loggers(config);
40
-
41
- loggers.coreLogger.info('[ee-core:logger] init all loggers with options: %j', loggerConfig);
42
-
43
- return loggers;
44
- };
45
- }
46
-
47
- module.exports = Logger;
@@ -1,22 +0,0 @@
1
- 'use strict';
2
-
3
- const socketServer = require('./socketServer');
4
- const ipcServer = require('./ipcServer');
5
- const httpServer = require('./httpServer');
6
-
7
- /**
8
- * server
9
- */
10
- module.exports = (app) => {
11
-
12
- // 启动 socket server
13
- new socketServer(app);
14
-
15
- // 启动 http server
16
- new httpServer(app);
17
-
18
- // 启动 electron ipc server
19
- new ipcServer(app);
20
-
21
- }
22
-
@@ -1,15 +0,0 @@
1
- const stringify = require('./_stringify')
2
-
3
- class Base {
4
- constructor(
5
- source,
6
- { defaultValue = {}, serialize = stringify, deserialize = JSON.parse } = {}
7
- ) {
8
- this.source = source
9
- this.defaultValue = defaultValue
10
- this.serialize = serialize
11
- this.deserialize = deserialize
12
- }
13
- }
14
-
15
- module.exports = Base
@@ -1,41 +0,0 @@
1
- // Not using async/await on purpose to avoid adding regenerator-runtime
2
- // to lowdb dependencies
3
- const fs = require('graceful-fs')
4
- const pify = require('pify')
5
- const steno = require('steno')
6
- const Base = require('./Base')
7
-
8
- const readFile = pify(fs.readFile)
9
- const writeFile = pify(steno.writeFile)
10
-
11
- class FileAsync extends Base {
12
- read() {
13
- // fs.exists is deprecated but not fs.existsSync
14
- if (fs.existsSync(this.source)) {
15
- // Read database
16
- return readFile(this.source, 'utf-8')
17
- .then(data => {
18
- // Handle blank file
19
- const trimmed = data.trim()
20
- return trimmed ? this.deserialize(trimmed) : this.defaultValue
21
- })
22
- .catch(e => {
23
- if (e instanceof SyntaxError) {
24
- e.message = `Malformed JSON in file: ${this.source}\n${e.message}`
25
- }
26
- throw e
27
- })
28
- } else {
29
- // Initialize
30
- return writeFile(this.source, this.serialize(this.defaultValue)).then(
31
- () => this.defaultValue
32
- )
33
- }
34
- }
35
-
36
- write(data) {
37
- return writeFile(this.source, this.serialize(data))
38
- }
39
- }
40
-
41
- module.exports = FileAsync
@@ -1,39 +0,0 @@
1
- const fs = require('graceful-fs')
2
- const Base = require('./Base')
3
- const fileSystem = require('fs')
4
-
5
- //const readFile = fs.readFileSync
6
- const writeFile = fs.writeFileSync
7
-
8
- // Same code as in FileAsync, minus `await`
9
- class FileSync extends Base {
10
- read() {
11
- // fs.exists is deprecated but not fs.existsSync
12
- if (fs.existsSync(this.source)) {
13
- // Read database
14
- try {
15
- // 使用 fileSystem的readFileSync
16
- //const data = readFile(this.source, 'utf-8').trim()
17
- const data = fileSystem.readFileSync(this.source, {encoding: 'utf-8'})
18
-
19
- // Handle blank file
20
- return data ? this.deserialize(data) : this.defaultValue
21
- } catch (e) {
22
- if (e instanceof SyntaxError) {
23
- e.message = `Malformed JSON in file: ${this.source}\n${e.message}`
24
- }
25
- throw e
26
- }
27
- } else {
28
- // Initialize
29
- writeFile(this.source, this.serialize(this.defaultValue))
30
- return this.defaultValue
31
- }
32
- }
33
-
34
- write(data) {
35
- return writeFile(this.source, this.serialize(data))
36
- }
37
- }
38
-
39
- module.exports = FileSync
@@ -1,20 +0,0 @@
1
- /* global localStorage */
2
- const Base = require('./Base')
3
-
4
- class LocalStorage extends Base {
5
- read() {
6
- const data = localStorage.getItem(this.source)
7
- if (data) {
8
- return this.deserialize(data)
9
- } else {
10
- localStorage.setItem(this.source, this.serialize(this.defaultValue))
11
- return this.defaultValue
12
- }
13
- }
14
-
15
- write(data) {
16
- localStorage.setItem(this.source, this.serialize(data))
17
- }
18
- }
19
-
20
- module.exports = LocalStorage
@@ -1,8 +0,0 @@
1
- const Base = require('./Base')
2
-
3
- module.exports = class Memory extends Base {
4
- read() {
5
- return this.defaultValue
6
- }
7
- write() {}
8
- }
@@ -1,4 +0,0 @@
1
- // Pretty stringify
2
- module.exports = function stringify(obj) {
3
- return JSON.stringify(obj, null, 2)
4
- }
@@ -1,33 +0,0 @@
1
- const isPromise = require('./isPromise')
2
-
3
- const init = (db, key, adapter) => {
4
- db.read = () => {
5
- const r = adapter.read()
6
-
7
- return isPromise(r) ? r.then(db.plant) : db.plant(r)
8
- }
9
-
10
- db.write = (value = db.getState()) => {
11
- const w = adapter.write(db.getState())
12
-
13
- return isPromise(w) ? w.then(() => value) : value
14
- }
15
-
16
- db.plant = state => {
17
- db[key] = state
18
- return db
19
- }
20
-
21
- db.getState = () => db[key]
22
-
23
- db.setState = state => {
24
- db.plant(state)
25
- return db
26
- }
27
-
28
- return db.read()
29
- }
30
-
31
- module.exports = {
32
- init
33
- }
@@ -1,23 +0,0 @@
1
- const flow = require('lodash/flow')
2
- const get = require('lodash/get')
3
- const set = require('lodash/set')
4
- const common = require('./common')
5
-
6
- module.exports = function(adapter) {
7
- function db(path, defaultValue) {
8
- function getValue(funcs) {
9
- const result = get(db.getState(), path, defaultValue)
10
- return flow(funcs)(result)
11
- }
12
-
13
- getValue.write = (...funcs) => {
14
- const result = getValue(...funcs)
15
- set(db.getState(), path, result)
16
- return db.write()
17
- }
18
-
19
- return getValue
20
- }
21
-
22
- return common.init(db, '__state__', adapter)
23
- }
@@ -1,6 +0,0 @@
1
- module.exports = isPromise;
2
- module.exports.default = isPromise;
3
-
4
- function isPromise(obj) {
5
- return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
6
- }
@@ -1,5 +0,0 @@
1
- const common = require('./common')
2
-
3
- module.exports = function(adapter) {
4
- return common.init({}, '__state__', adapter)
5
- }
package/utils/common.js DELETED
@@ -1,91 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * ee-core使用
5
- */
6
-
7
- const fs = require('fs');
8
- const path = require('path');
9
-
10
- /**
11
- * 版本号比较
12
- */
13
- exports.compareVersion = function (v1, v2) {
14
- v1 = v1.split('.')
15
- v2 = v2.split('.')
16
- const len = Math.max(v1.length, v2.length)
17
-
18
- while (v1.length < len) {
19
- v1.push('0')
20
- }
21
- while (v2.length < len) {
22
- v2.push('0')
23
- }
24
-
25
- for (let i = 0; i < len; i++) {
26
- const num1 = parseInt(v1[i])
27
- const num2 = parseInt(v2[i])
28
-
29
- if (num1 > num2) {
30
- return 1
31
- } else if (num1 < num2) {
32
- return -1
33
- }
34
- }
35
-
36
- return 0
37
- }
38
-
39
- /**
40
- * 创建文件夹
41
- */
42
- exports.mkdir = function(dirpath, dirname) {
43
- // 判断是否是第一次调用
44
- if (typeof dirname === 'undefined') {
45
- if (fs.existsSync(dirpath)) {
46
- return;
47
- }
48
- this.mkdir(dirpath, path.dirname(dirpath));
49
- } else {
50
- // 判断第二个参数是否正常,避免调用时传入错误参数
51
- if (dirname !== path.dirname(dirpath)) {
52
- this.mkdir(dirpath);
53
- return;
54
- }
55
- if (fs.existsSync(dirname)) {
56
- fs.mkdirSync(dirpath);
57
- } else {
58
- this.mkdir(dirname, path.dirname(dirname));
59
- fs.mkdirSync(dirpath);
60
- }
61
- }
62
- };
63
-
64
- /**
65
- * 修改文件权限
66
- */
67
- exports.chmodPath = function(path, mode) {
68
- let files = [];
69
- if (fs.existsSync(path)) {
70
- files = fs.readdirSync(path);
71
- files.forEach((file, index) => {
72
- const curPath = path + '/' + file;
73
- if (fs.statSync(curPath).isDirectory()) {
74
- this.chmodPath(curPath, mode); // 递归删除文件夹
75
- } else {
76
- fs.chmodSync(curPath, mode);
77
- }
78
- });
79
- fs.chmodSync(path, mode);
80
- }
81
- };
82
-
83
- /**
84
- * 获取数据存储路径
85
- */
86
- exports.getStorageDir = function () {
87
- let env = process.env.EE_SERVER_ENV;
88
- const appDir = env === 'local' || env === 'unittest' ? process.env.EE_HOME : process.env.EE_APP_USER_DATA;
89
- const storageDir = path.join(appDir, 'data');
90
- return storageDir;
91
- }
File without changes
File without changes