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.
- package/LICENSE +21 -21
- package/README.md +2 -2
- package/addon/window/index.js +91 -91
- package/bin/tools.js +18 -18
- package/config/config.default.js +287 -280
- package/core/index.js +12 -12
- package/core/lib/ee.js +218 -218
- package/core/lib/loader/context_loader.js +106 -106
- package/core/lib/loader/ee_loader.js +461 -457
- package/core/lib/loader/file_loader.js +325 -325
- package/core/lib/loader/mixin/addon.js +32 -32
- package/core/lib/loader/mixin/config.js +135 -135
- package/core/lib/loader/mixin/controller.js +125 -124
- package/core/lib/loader/mixin/service.js +28 -28
- package/core/lib/utils/base_context_class.js +34 -34
- package/core/lib/utils/function.js +30 -0
- package/core/lib/utils/index.js +127 -127
- package/core/lib/utils/sequencify.js +59 -59
- package/core/lib/utils/timing.js +77 -77
- package/index.js +49 -49
- package/lib/appLoader.js +48 -53
- package/lib/application.js +85 -84
- package/lib/baseApp.js +114 -131
- package/lib/eeApp.js +325 -359
- package/{lib/constant.js → module/const/index.js} +12 -9
- package/{lib/httpclient.js → module/httpclient/index.js} +170 -136
- package/module/jobs/child/forkProcess.js +99 -0
- package/module/jobs/child/index.js +33 -0
- package/module/jobs/index.js +55 -0
- package/module/jobs/renderer/index.js +140 -0
- package/module/jobs/renderer/loadView.js +40 -0
- package/module/loader/index.js +78 -0
- package/module/log/index.js +53 -0
- package/module/log/logger.js +61 -0
- package/module/message/index.js +13 -0
- package/module/message/ipcMain.js +160 -0
- package/module/message/ipcRender.js +0 -0
- package/{lib → module}/socket/httpServer.js +142 -142
- package/{lib → module}/socket/io.js +23 -23
- package/{lib → module}/socket/ipcServer.js +106 -108
- package/{lib → module}/socket/socketClient.js +51 -50
- package/{lib → module}/socket/socketServer.js +77 -76
- package/module/socket/start.js +22 -0
- package/{lib → module}/storage/index.js +35 -34
- package/module/storage/jsondb/adapters/Base.js +14 -0
- package/module/storage/jsondb/adapters/FileSync.js +32 -0
- package/{lib/storage/lowdb → module/storage/jsondb}/main.js +42 -46
- package/{lib/storage/lowdbStorage.js → module/storage/jsondbStorage.js} +98 -99
- package/{lib → module}/storage/sqliteStorage.js +123 -127
- package/module/utils/copyto.js +161 -0
- package/module/utils/helper.js +117 -0
- package/module/utils/index.js +120 -0
- package/module/utils/json.js +72 -0
- package/module/utils/ps.js +175 -0
- package/{utils → module/utils}/wrap.js +35 -37
- package/package.json +44 -48
- package/tools/encrypt.js +274 -274
- package/tools/replaceDist.js +61 -61
- package/utils/index.js +128 -246
- package/lib/logger.js +0 -47
- package/lib/socket/start.js +0 -22
- package/lib/storage/lowdb/adapters/Base.js +0 -15
- package/lib/storage/lowdb/adapters/FileAsync.js +0 -41
- package/lib/storage/lowdb/adapters/FileSync.js +0 -39
- package/lib/storage/lowdb/adapters/LocalStorage.js +0 -20
- package/lib/storage/lowdb/adapters/Memory.js +0 -8
- package/lib/storage/lowdb/adapters/_stringify.js +0 -4
- package/lib/storage/lowdb/common.js +0 -33
- package/lib/storage/lowdb/fp.js +0 -23
- package/lib/storage/lowdb/is-promise.js +0 -6
- package/lib/storage/lowdb/nano.js +0 -5
- 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
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
db.
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
assert(
|
|
66
|
-
assert(key
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
assert(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
let
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
if (
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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;
|