ee-core 1.5.2-beta.1 → 2.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.
Files changed (72) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +2 -2
  3. package/addon/window/index.js +91 -91
  4. package/bin/tools.js +18 -18
  5. package/config/config.default.js +287 -280
  6. package/core/index.js +12 -12
  7. package/core/lib/ee.js +218 -218
  8. package/core/lib/loader/context_loader.js +106 -106
  9. package/core/lib/loader/ee_loader.js +461 -457
  10. package/core/lib/loader/file_loader.js +325 -325
  11. package/core/lib/loader/mixin/addon.js +32 -32
  12. package/core/lib/loader/mixin/config.js +135 -135
  13. package/core/lib/loader/mixin/controller.js +125 -124
  14. package/core/lib/loader/mixin/service.js +28 -28
  15. package/core/lib/utils/base_context_class.js +34 -34
  16. package/core/lib/utils/function.js +30 -0
  17. package/core/lib/utils/index.js +127 -127
  18. package/core/lib/utils/sequencify.js +59 -59
  19. package/core/lib/utils/timing.js +77 -77
  20. package/index.js +49 -49
  21. package/lib/appLoader.js +48 -53
  22. package/lib/application.js +85 -84
  23. package/lib/baseApp.js +114 -131
  24. package/lib/eeApp.js +325 -359
  25. package/{lib/constant.js → module/const/index.js} +12 -9
  26. package/{lib/httpclient.js → module/httpclient/index.js} +170 -136
  27. package/module/jobs/child/forkProcess.js +99 -0
  28. package/module/jobs/child/index.js +33 -0
  29. package/module/jobs/index.js +55 -0
  30. package/module/jobs/renderer/index.js +140 -0
  31. package/module/jobs/renderer/loadView.js +40 -0
  32. package/module/loader/index.js +78 -0
  33. package/module/log/index.js +53 -0
  34. package/module/log/logger.js +61 -0
  35. package/module/message/index.js +13 -0
  36. package/module/message/ipcMain.js +160 -0
  37. package/module/message/ipcRender.js +0 -0
  38. package/{lib → module}/socket/httpServer.js +142 -142
  39. package/{lib → module}/socket/io.js +23 -23
  40. package/{lib → module}/socket/ipcServer.js +106 -108
  41. package/{lib → module}/socket/socketClient.js +51 -50
  42. package/{lib → module}/socket/socketServer.js +77 -76
  43. package/module/socket/start.js +22 -0
  44. package/{lib → module}/storage/index.js +35 -34
  45. package/module/storage/jsondb/adapters/Base.js +14 -0
  46. package/module/storage/jsondb/adapters/FileSync.js +32 -0
  47. package/{lib/storage/lowdb → module/storage/jsondb}/main.js +42 -46
  48. package/{lib/storage/lowdbStorage.js → module/storage/jsondbStorage.js} +98 -99
  49. package/{lib → module}/storage/sqliteStorage.js +123 -127
  50. package/module/utils/copyto.js +161 -0
  51. package/module/utils/helper.js +117 -0
  52. package/module/utils/index.js +120 -0
  53. package/module/utils/json.js +72 -0
  54. package/module/utils/ps.js +175 -0
  55. package/{utils → module/utils}/wrap.js +35 -37
  56. package/package.json +44 -48
  57. package/tools/encrypt.js +274 -274
  58. package/tools/replaceDist.js +61 -61
  59. package/utils/index.js +128 -246
  60. package/lib/logger.js +0 -47
  61. package/lib/socket/start.js +0 -22
  62. package/lib/storage/lowdb/adapters/Base.js +0 -15
  63. package/lib/storage/lowdb/adapters/FileAsync.js +0 -41
  64. package/lib/storage/lowdb/adapters/FileSync.js +0 -39
  65. package/lib/storage/lowdb/adapters/LocalStorage.js +0 -20
  66. package/lib/storage/lowdb/adapters/Memory.js +0 -8
  67. package/lib/storage/lowdb/adapters/_stringify.js +0 -4
  68. package/lib/storage/lowdb/common.js +0 -33
  69. package/lib/storage/lowdb/fp.js +0 -23
  70. package/lib/storage/lowdb/is-promise.js +0 -6
  71. package/lib/storage/lowdb/nano.js +0 -5
  72. package/utils/common.js +0 -91
@@ -0,0 +1,32 @@
1
+ const Base = require('./Base')
2
+ const fs = require('fs')
3
+
4
+ class FileSync extends Base {
5
+
6
+ read() {
7
+ if (fs.existsSync(this.source)) {
8
+ // Read database
9
+ try {
10
+ const data = fs.readFileSync(this.source, {encoding: 'utf8'})
11
+
12
+ // Handle blank file
13
+ return data ? this.deserialize(data) : this.defaultValue
14
+ } catch (e) {
15
+ if (e instanceof SyntaxError) {
16
+ e.message = `Malformed JSON in file: ${this.source}\n${e.message}`
17
+ }
18
+ throw e
19
+ }
20
+ } else {
21
+ // Initialize
22
+ fs.writeFileSync(this.source, this.serialize(this.defaultValue))
23
+ return this.defaultValue
24
+ }
25
+ }
26
+
27
+ write(data) {
28
+ return fs.writeFileSync(this.source, this.serialize(data))
29
+ }
30
+ }
31
+
32
+ module.exports = FileSync
@@ -1,46 +1,42 @@
1
- const lodash = require('lodash')
2
- const isPromise = require('is-promise')
3
-
4
- module.exports = function(adapter) {
5
- if (typeof adapter !== 'object') {
6
- throw new Error(
7
- 'An adapter must be provided, see https://github.com/typicode/lowdb/#usage'
8
- )
9
- }
10
-
11
- // Create a fresh copy of lodash
12
- const _ = lodash.runInContext()
13
- const db = _.chain({})
14
-
15
- // Add write function to lodash
16
- // Calls save before returning result
17
- _.prototype.write = _.wrap(_.prototype.value, function(func) {
18
- const funcRes = func.apply(this)
19
- return db.write(funcRes)
20
- })
21
-
22
- function plant(state) {
23
- db.__wrapped__ = state
24
- return db
25
- }
26
-
27
- // Lowdb API
28
- // Expose _ for mixins
29
- db._ = _
30
-
31
- db.read = () => {
32
- const r = adapter.read()
33
- return isPromise(r) ? r.then(plant) : plant(r)
34
- }
35
-
36
- db.write = returnValue => {
37
- const w = adapter.write(db.getState())
38
- return isPromise(w) ? w.then(() => returnValue) : returnValue
39
- }
40
-
41
- db.getState = () => db.__wrapped__
42
-
43
- db.setState = state => plant(state)
44
-
45
- return db.read()
46
- }
1
+ const lodash = require('lodash');
2
+ const assert = require('assert');
3
+ const is = require('is-type-of');
4
+
5
+ module.exports = function(adapter) {
6
+ assert(typeof adapter === 'object', 'An adapter must be provided');
7
+
8
+ // Create a fresh copy of lodash
9
+ const _ = lodash.runInContext()
10
+ const db = _.chain({})
11
+
12
+ // Add write function to lodash
13
+ // Calls save before returning result
14
+ _.prototype.write = _.wrap(_.prototype.value, function(func) {
15
+ const funcRes = func.apply(this)
16
+ return db.write(funcRes)
17
+ })
18
+
19
+ function plant(state) {
20
+ db.__wrapped__ = state
21
+ return db
22
+ }
23
+
24
+ // Expose _ for mixins
25
+ db._ = _
26
+
27
+ db.read = () => {
28
+ const r = adapter.read()
29
+ return is.promise(r) ? r.then(plant) : plant(r)
30
+ }
31
+
32
+ db.write = returnValue => {
33
+ const w = adapter.write(db.getState())
34
+ return is.promise(w) ? w.then(() => returnValue) : returnValue
35
+ }
36
+
37
+ db.getState = () => db.__wrapped__
38
+
39
+ db.setState = state => plant(state)
40
+
41
+ return db.read()
42
+ }
@@ -1,99 +1,98 @@
1
- 'use strict';
2
-
3
- const assert = require('assert');
4
- const fs = require('fs');
5
- const path = require('path');
6
- const lowdb = require('./lowdb/main');
7
- const FileSync = require('./lowdb/adapters/FileSync');
8
- const _ = require('lodash');
9
- const constant = require('../constant');
10
- const utilsCommon = require('../../utils/common');
11
-
12
- class LowdbStorage {
13
- constructor (name, opt = {}) {
14
- assert(name, `db name ${name} Cannot be empty`);
15
-
16
- this.name = name;
17
-
18
- // 数据库key列表
19
- this.storageKey = constant.storageKey;
20
-
21
- const storageDir = utilsCommon.getStorageDir();
22
- if (!fs.existsSync(storageDir)) {
23
- utilsCommon.mkdir(storageDir);
24
- utilsCommon.chmodPath(storageDir, '777');
25
- }
26
-
27
- this.db = this.table(name);
28
- }
29
-
30
- /**
31
- * 创建 table
32
- */
33
- table (name) {
34
- assert(name, 'table name is required');
35
-
36
- const dbFile = this.getFilePath(name);
37
- const adapter = new FileSync(dbFile);
38
- const db = lowdb(adapter);
39
-
40
- assert(fs.existsSync(dbFile), `error: storage ${dbFile} not exists`);
41
-
42
- return db;
43
- }
44
-
45
- /**
46
- * 获取db文件名
47
- */
48
- getFileName (name) {
49
- return name + ".json";
50
- }
51
-
52
- /**
53
- * 获取文件绝对路径
54
- */
55
- getFilePath (name) {
56
- const storageDir = utilsCommon.getStorageDir();
57
- const dbFile = path.join(storageDir, this.getFileName(name));
58
- return dbFile;
59
- }
60
-
61
- /**
62
- * 为指定的 name 设置一个对应的值
63
- */
64
- setItem (key, value) {
65
- assert(_.isString(key), `key must be a string`);
66
- assert(key.length != 0, `key cannot be empty`);
67
- assert(!this.storageKey.hasOwnProperty(key), `${key} is not allowed`);
68
-
69
- let cacheKey = this.storageKey.cache;
70
- if (!this.db.has(cacheKey).value()) {
71
- this.db.set(cacheKey, {}).write();
72
- }
73
-
74
- let keyId = cacheKey + "." + key;
75
- this.db
76
- .set(keyId, value)
77
- .write();
78
-
79
- return true;
80
- }
81
-
82
- /**
83
- * 根据指定的名字 name 获取对应的值
84
- */
85
- getItem (key) {
86
- assert(_.isString(key), `key must be a string`);
87
- assert(key.length != 0, `key cannot be empty`);
88
-
89
- let cacheKey = this.storageKey.cache;
90
- let keyId = cacheKey + "." + key;
91
- const data = this.db
92
- .get(keyId)
93
- .value();
94
-
95
- return data;
96
- }
97
- }
98
-
99
- module.exports = LowdbStorage;
1
+ const assert = require('assert');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const Jsondb = require('./jsondb/main');
5
+ const FileSync = require('./jsondb/adapters/FileSync');
6
+ const _ = require('lodash');
7
+ const Constants = require('../const');
8
+ const Helper = require('../utils/helper');
9
+ const Ps = require('../utils/ps');
10
+
11
+ class JsondbStorage {
12
+ constructor (name, opt = {}) {
13
+ assert(name, `db name ${name} Cannot be empty`);
14
+
15
+ this.name = name;
16
+
17
+ // 数据库key列表
18
+ this.storageKey = Constants.storageKey;
19
+
20
+ const storageDir = Ps.getStorageDir();
21
+ if (!fs.existsSync(storageDir)) {
22
+ Helper.mkdir(storageDir);
23
+ Helper.chmodPath(storageDir, '777');
24
+ }
25
+
26
+ this.db = this.table(name);
27
+ }
28
+
29
+ /**
30
+ * 创建 table
31
+ */
32
+ table (name) {
33
+ assert(name, 'table name is required');
34
+
35
+ const dbFile = this.getFilePath(name);
36
+ const adapter = new FileSync(dbFile);
37
+ const db = Jsondb(adapter);
38
+
39
+ assert(fs.existsSync(dbFile), `error: storage ${dbFile} not exists`);
40
+
41
+ return db;
42
+ }
43
+
44
+ /**
45
+ * 获取db文件名
46
+ */
47
+ getFileName (name) {
48
+ return name + ".json";
49
+ }
50
+
51
+ /**
52
+ * 获取文件绝对路径
53
+ */
54
+ getFilePath (name) {
55
+ const storageDir = Ps.getStorageDir();
56
+ const dbFile = path.join(storageDir, this.getFileName(name));
57
+ return dbFile;
58
+ }
59
+
60
+ /**
61
+ * 为指定的 name 设置一个对应的值
62
+ */
63
+ setItem (key, value) {
64
+ assert(_.isString(key), `key must be a string`);
65
+ assert(key.length != 0, `key cannot be empty`);
66
+ assert(!this.storageKey.hasOwnProperty(key), `${key} is not allowed`);
67
+
68
+ let cacheKey = this.storageKey.cache;
69
+ if (!this.db.has(cacheKey).value()) {
70
+ this.db.set(cacheKey, {}).write();
71
+ }
72
+
73
+ let keyId = cacheKey + "." + key;
74
+ this.db
75
+ .set(keyId, value)
76
+ .write();
77
+
78
+ return true;
79
+ }
80
+
81
+ /**
82
+ * 根据指定的名字 name 获取对应的值
83
+ */
84
+ getItem (key) {
85
+ assert(_.isString(key), `key must be a string`);
86
+ assert(key.length != 0, `key cannot be empty`);
87
+
88
+ let cacheKey = this.storageKey.cache;
89
+ let keyId = cacheKey + "." + key;
90
+ const data = this.db
91
+ .get(keyId)
92
+ .value();
93
+
94
+ return data;
95
+ }
96
+ }
97
+
98
+ module.exports = JsondbStorage;
@@ -1,128 +1,124 @@
1
- 'use strict';
2
-
3
- const assert = require('assert');
4
- const fs = require('fs');
5
- const path = require('path');
6
- const Database = require('better-sqlite3');
7
- const utilsCommon = require('../../utils/common');
8
-
9
- class SqliteStorage {
10
- constructor (name, opt = {}) {
11
- assert(name, `db name ${name} Cannot be empty`);
12
-
13
- this.name = name;
14
- this.mode = this.getMode(name);
15
-
16
- const storageDir = this._createStorageDir();
17
- this.storageDir = storageDir;
18
-
19
- const fileName = this._formatFileName(name);
20
- this.fileName = fileName;
21
-
22
- this.db = this._initDB(opt);
23
- }
24
-
25
- /**
26
- * 初始化db
27
- */
28
- _initDB (opt = {}) {
29
- let options = Object.assign({
30
- timeout: 5000,
31
- }, opt);
32
-
33
- // 存储类型:db文件、内存(:memory:)
34
- let dbPath = this.name;
35
- if (this.mode != 'memory') {
36
- dbPath = this.getFilePath();
37
- }
38
-
39
- const db = new Database(dbPath, options);
40
-
41
- // 如果是文件类型,判断文件是否创建成功
42
- if (this.mode != 'memory') {
43
- assert(fs.existsSync(dbPath), `error: storage ${dbPath} not exists`);
44
- }
45
-
46
- return db;
47
- }
48
-
49
- /**
50
- * 获取文件名
51
- */
52
- _formatFileName (name) {
53
- let fileName = name;
54
- if (this.mode != 'memory') {
55
- fileName = path.basename(name);
56
- }
57
-
58
- return fileName;
59
- }
60
-
61
- /**
62
- * 创建storage目录
63
- */
64
- _createStorageDir () {
65
- let storageDir = utilsCommon.getStorageDir();
66
-
67
- if (this.mode == 'absolute') {
68
- storageDir = path.dirname(this.name);
69
- }
70
-
71
- if (!fs.existsSync(storageDir)) {
72
- utilsCommon.mkdir(storageDir);
73
- utilsCommon.chmodPath(storageDir, '777');
74
- }
75
-
76
- return storageDir;
77
- }
78
-
79
- /**
80
- * 获取file path 模式
81
- */
82
- getMode (name) {
83
- let mode = '';
84
-
85
- // 内存模式
86
- if (name == ':memory:') {
87
- mode = 'memory';
88
- return mode;
89
- }
90
-
91
- assert(path.extname(name) == '.db', `error: storage ${name} file ext name must be .db`);
92
-
93
- // 路径模式
94
- name = name.replace(/[/\\]/g, '/');
95
- if (name.indexOf('/') !== -1) {
96
- const isAbsolute = path.isAbsolute(name);
97
- if (isAbsolute) {
98
- mode = 'absolute';
99
- } else {
100
- mode = 'relative';
101
- }
102
- return mode;
103
- }
104
-
105
- // 仅文件名
106
- mode = 'onlyName';
107
-
108
- return mode;
109
- }
110
-
111
- /**
112
- * 获取storage目录
113
- */
114
- getStorageDir () {
115
- return this.storageDir;
116
- }
117
-
118
- /**
119
- * 获取文件绝对路径
120
- */
121
- getFilePath () {
122
- const dbFile = path.join(this.storageDir, this.fileName);
123
-
124
- return dbFile;
125
- }
126
- }
127
-
1
+ 'use strict';
2
+
3
+ const assert = require('assert');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const Database = require('better-sqlite3');
7
+ const Helper = require('../utils/helper');
8
+ const Ps = require('../utils/ps');
9
+
10
+ class SqliteStorage {
11
+ constructor (name, opt = {}) {
12
+ assert(name, `db name ${name} Cannot be empty`);
13
+
14
+ this.name = name;
15
+ this.mode = this.getMode(name);
16
+ this.storageDir = this._createStorageDir();
17
+ this.fileName = this._formatFileName(name);
18
+ this.db = this._initDB(opt);
19
+ }
20
+
21
+ /**
22
+ * 初始化db
23
+ */
24
+ _initDB (opt = {}) {
25
+ let options = Object.assign({
26
+ timeout: 5000,
27
+ }, opt);
28
+
29
+ // 存储类型:db文件、内存(:memory:)
30
+ let dbPath = this.name;
31
+ if (this.mode != 'memory') {
32
+ dbPath = this.getFilePath();
33
+ }
34
+
35
+ const db = new Database(dbPath, options);
36
+
37
+ // 如果是文件类型,判断文件是否创建成功
38
+ if (this.mode != 'memory') {
39
+ assert(fs.existsSync(dbPath), `error: storage ${dbPath} not exists`);
40
+ }
41
+
42
+ return db;
43
+ }
44
+
45
+ /**
46
+ * 获取文件名
47
+ */
48
+ _formatFileName (name) {
49
+ let fileName = name;
50
+ if (this.mode != 'memory') {
51
+ fileName = path.basename(name);
52
+ }
53
+
54
+ return fileName;
55
+ }
56
+
57
+ /**
58
+ * 创建storage目录
59
+ */
60
+ _createStorageDir () {
61
+ let storageDir = Ps.getStorageDir();
62
+
63
+ if (this.mode == 'absolute') {
64
+ storageDir = path.dirname(this.name);
65
+ }
66
+
67
+ if (!fs.existsSync(storageDir)) {
68
+ Helper.mkdir(storageDir);
69
+ Helper.chmodPath(storageDir, '777');
70
+ }
71
+
72
+ return storageDir;
73
+ }
74
+
75
+ /**
76
+ * 获取file path 模式
77
+ */
78
+ getMode (name) {
79
+ let mode = '';
80
+
81
+ // 内存模式
82
+ if (name == ':memory:') {
83
+ mode = 'memory';
84
+ return mode;
85
+ }
86
+
87
+ assert(path.extname(name) == '.db', `error: storage ${name} file ext name must be .db`);
88
+
89
+ // 路径模式
90
+ name = name.replace(/[/\\]/g, '/');
91
+ if (name.indexOf('/') !== -1) {
92
+ const isAbsolute = path.isAbsolute(name);
93
+ if (isAbsolute) {
94
+ mode = 'absolute';
95
+ } else {
96
+ mode = 'relative';
97
+ }
98
+ return mode;
99
+ }
100
+
101
+ // 仅文件名
102
+ mode = 'onlyName';
103
+
104
+ return mode;
105
+ }
106
+
107
+ /**
108
+ * 获取storage目录
109
+ */
110
+ getStorageDir () {
111
+ return this.storageDir;
112
+ }
113
+
114
+ /**
115
+ * 获取文件绝对路径
116
+ */
117
+ getFilePath () {
118
+ const dbFile = path.join(this.storageDir, this.fileName);
119
+
120
+ return dbFile;
121
+ }
122
+ }
123
+
128
124
  module.exports = SqliteStorage;