ee-core 1.2.7 → 1.2.8-beta.4

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 (43) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +2 -2
  3. package/bin/tools.js +22 -22
  4. package/config/config.default.js +250 -247
  5. package/core/index.js +12 -12
  6. package/core/lib/ee.js +209 -209
  7. package/core/lib/loader/context_loader.js +105 -105
  8. package/core/lib/loader/ee_loader.js +451 -451
  9. package/core/lib/loader/file_loader.js +262 -262
  10. package/core/lib/loader/mixin/config.js +138 -138
  11. package/core/lib/loader/mixin/controller.js +123 -123
  12. package/core/lib/loader/mixin/service.js +29 -29
  13. package/core/lib/utils/base_context_class.js +34 -34
  14. package/core/lib/utils/index.js +100 -100
  15. package/core/lib/utils/sequencify.js +59 -59
  16. package/core/lib/utils/timing.js +77 -77
  17. package/index.js +49 -49
  18. package/lib/appLoader.js +45 -45
  19. package/lib/application.js +80 -80
  20. package/lib/baseApp.js +118 -118
  21. package/lib/constant.js +28 -28
  22. package/lib/eeApp.js +326 -326
  23. package/lib/helper.js +51 -51
  24. package/lib/httpclient.js +136 -136
  25. package/lib/logger.js +46 -46
  26. package/lib/socket/httpServer.js +102 -104
  27. package/lib/socket/io.js +23 -23
  28. package/lib/socket/ipcServer.js +128 -128
  29. package/lib/socket/socketClient.js +50 -50
  30. package/lib/socket/socketServer.js +76 -76
  31. package/lib/socket/start.js +22 -22
  32. package/lib/storage/index.js +33 -21
  33. package/lib/storage/lowdbStorage.js +98 -143
  34. package/lib/storage/sqliteStorage.js +59 -0
  35. package/package.json +45 -45
  36. package/resource/loading.html +21 -21
  37. package/resource/view_example.html +21 -21
  38. package/tools/codeCompress.js +204 -204
  39. package/tools/replaceDist.js +76 -76
  40. package/utils/common.js +91 -30
  41. package/utils/index.js +207 -207
  42. package/utils/wrap.js +37 -37
  43. package/lib/storage/appStorage.js +0 -14
@@ -1,77 +1,77 @@
1
- 'use strict';
2
-
3
- const assert = require('assert');
4
- const { Server } = require('socket.io');
5
- const constant = require('../constant');
6
- const EggConsoleLogger = require('egg-logger').EggConsoleLogger;
7
- const is = require('is-type-of');
8
-
9
- /**
10
- * 类文件,顶部new egglogger 后,出现代码无法正常加载
11
- */
12
- class SocketServer {
13
- constructor (app) {
14
- this.app = app;
15
- const options = this.app.config.socketServer;
16
- this.consoleLogger = new EggConsoleLogger();
17
-
18
- if (!options.enable) {
19
- return;
20
- }
21
-
22
- let port = process.env.EE_SOCKET_PORT ? parseInt(process.env.EE_SOCKET_PORT) : parseInt(this.getSocketPort());
23
- assert(typeof port === 'number', 'socekt port required, and must be a number');
24
- this.consoleLogger.info('[ee-core:socket:server] socket server port is:', port);
25
-
26
- // let opt = Object.assign({}, options);
27
- // delete opt.enable;
28
- this.io = new Server(port, options);
29
- this.connec();
30
- }
31
-
32
- connec () {
33
- const self = this;
34
- this.consoleLogger.info('[ee-core:socket:server] connection .....');
35
- this.io.on('connection', (socket) => {
36
- const channel = constant.socketIo.channel.partySoftware;
37
- socket.on(channel, async (message, callback) => {
38
- self.consoleLogger.info('[ee-core:socket:server] socket id:' + socket.id + ' message cmd: ' + message.cmd);
39
-
40
- try {
41
- // 找函数
42
- const cmd = message.cmd;
43
- const args = message.params;
44
- let fn = null;
45
- if (is.string(cmd)) {
46
- const actions = cmd.split('.');
47
- let obj = self.app;
48
- actions.forEach(key => {
49
- obj = obj[key];
50
- if (!obj) throw new Error(`class or function '${key}' not exists`);
51
- });
52
- fn = obj;
53
- }
54
- if (!fn) throw new Error('function not exists');
55
-
56
- const result = await fn.call(self.app, args);
57
- callback(result);
58
- } catch (err) {
59
- self.app.console.error('[ee-core:socket:server] throw error:', err);
60
- }
61
- });
62
- });
63
- }
64
-
65
- getCoreDB () {
66
- const coreDB = require('../storage/index').JsonDB.connection('system');
67
- return coreDB;
68
- }
69
-
70
- getSocketPort () {
71
- const cdb = this.getCoreDB();
72
- const port = cdb.getItem('config').socketServer.port;
73
- return port;
74
- }
75
- }
76
-
1
+ 'use strict';
2
+
3
+ const assert = require('assert');
4
+ const { Server } = require('socket.io');
5
+ const constant = require('../constant');
6
+ const EggConsoleLogger = require('egg-logger').EggConsoleLogger;
7
+ const is = require('is-type-of');
8
+
9
+ /**
10
+ * socket server
11
+ */
12
+ class SocketServer {
13
+ constructor (app) {
14
+ this.app = app;
15
+ const options = this.app.config.socketServer;
16
+ this.consoleLogger = new EggConsoleLogger();
17
+
18
+ if (!options.enable) {
19
+ return;
20
+ }
21
+
22
+ let port = process.env.EE_SOCKET_PORT ? parseInt(process.env.EE_SOCKET_PORT) : parseInt(this.getSocketPort());
23
+ assert(typeof port === 'number', 'socekt port required, and must be a number');
24
+ this.consoleLogger.info('[ee-core:socket:server] socket server port is:', port);
25
+
26
+ // let opt = Object.assign({}, options);
27
+ // delete opt.enable;
28
+ this.io = new Server(port, options);
29
+ this.connec();
30
+ }
31
+
32
+ connec () {
33
+ const self = this;
34
+ this.consoleLogger.info('[ee-core:socket:server] connection .....');
35
+ this.io.on('connection', (socket) => {
36
+ const channel = constant.socketIo.channel.partySoftware;
37
+ socket.on(channel, async (message, callback) => {
38
+ self.consoleLogger.info('[ee-core:socket:server] socket id:' + socket.id + ' message cmd: ' + message.cmd);
39
+
40
+ try {
41
+ // 找函数
42
+ const cmd = message.cmd;
43
+ const args = message.params;
44
+ let fn = null;
45
+ if (is.string(cmd)) {
46
+ const actions = cmd.split('.');
47
+ let obj = self.app;
48
+ actions.forEach(key => {
49
+ obj = obj[key];
50
+ if (!obj) throw new Error(`class or function '${key}' not exists`);
51
+ });
52
+ fn = obj;
53
+ }
54
+ if (!fn) throw new Error('function not exists');
55
+
56
+ const result = await fn.call(self.app, args);
57
+ callback(result);
58
+ } catch (err) {
59
+ self.app.console.error('[ee-core:socket:server] throw error:', err);
60
+ }
61
+ });
62
+ });
63
+ }
64
+
65
+ getCoreDB () {
66
+ const coreDB = require('../storage/index').JsonDB.connection('system');
67
+ return coreDB;
68
+ }
69
+
70
+ getSocketPort () {
71
+ const cdb = this.getCoreDB();
72
+ const port = cdb.getItem('config').socketServer.port;
73
+ return port;
74
+ }
75
+ }
76
+
77
77
  module.exports = SocketServer;
@@ -1,22 +1,22 @@
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
+ '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,22 +1,34 @@
1
- 'use strict';
2
-
3
- const JsonDB = {};
4
-
5
- JsonDB.connection = function (database) {
6
-
7
- // console.log('this::::::', this);
8
- // todo
9
- // if (typeof this.instance === 'object') {
10
- // return this.instance;
11
- // }
12
-
13
- const LowdbStorage = require('./lowdbStorage');
14
- const storage = new LowdbStorage(database);
15
-
16
- // this.instance = storage;
17
- return storage;
18
- }
19
-
20
- module.exports = {
21
- JsonDB
1
+ 'use strict';
2
+
3
+ const assert = require('assert');
4
+ const _ = require('lodash');
5
+ const JsonDB = {};
6
+
7
+ JsonDB.connection = function (database, options = {}) {
8
+ let driver = options.driver || 'lowdb';
9
+ let opt = options.default || {};
10
+ if (!_.includes(['lowdb', 'sqlite'], driver)) {
11
+ assert(database, `db driver ${driver} is not supported`);
12
+ }
13
+ if (_.isEmpty(database)) {
14
+ assert(database, `db name ${database} Cannot be empty`);
15
+ }
16
+ let storage;
17
+ switch (driver) {
18
+ case 'lowdb':
19
+ const LowdbStorage = require('./lowdbStorage');
20
+ storage = new LowdbStorage(database);
21
+ break;
22
+ case 'sqlite':
23
+ const SqliteStorage = require('./sqliteStorage');
24
+ storage = new SqliteStorage(database, opt);
25
+ break;
26
+ default:
27
+ }
28
+
29
+ return storage;
30
+ }
31
+
32
+ module.exports = {
33
+ JsonDB
22
34
  };
@@ -1,144 +1,99 @@
1
- 'use strict';
2
-
3
- const assert = require('assert');
4
- const fs = require('fs');
5
- const path = require('path');
6
- const lowdb = require('lowdb');
7
- const FileSync = require('lowdb/adapters/FileSync');
8
- const _ = require('lodash');
9
- const constant = require('../constant');
10
-
11
- class LowdbStorage {
12
- constructor (name, opt = {}) {
13
- assert(name, `db name ${name} Cannot be empty`);
14
-
15
- this.name = name;
16
-
17
- // 数据库key列表
18
- this.storageKey = constant.storageKey;
19
-
20
- const storageDir = this.getStorageDir();
21
- if (!fs.existsSync(storageDir)) {
22
- this.mkdir(storageDir);
23
- this.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 = lowdb(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
- * 获取db文件名
53
- */
54
- getFilePath (name) {
55
- const storageDir = this.getStorageDir();
56
- const dbFile = path.join(storageDir, this.getFileName(name));
57
- return dbFile;
58
- }
59
-
60
- /**
61
- * 获取数据存储路径
62
- */
63
- getStorageDir () {
64
- let env = process.env.EE_SERVER_ENV;
65
- const appDir = env === 'local' || env === 'unittest' ? process.env.EE_HOME : process.env.EE_APP_USER_DATA;
66
- const storageDir = path.join(appDir, 'data');
67
- return storageDir;
68
- }
69
-
70
- /**
71
- * 为指定的 name 设置一个对应的值
72
- */
73
- setItem (key, value) {
74
- assert(_.isString(key), `key must be a string`);
75
- assert(key.length != 0, `key cannot be empty`);
76
- assert(!this.storageKey.hasOwnProperty(key), `${key} is not allowed`);
77
-
78
- let cacheKey = this.storageKey.cache;
79
- if (!this.db.has(cacheKey).value()) {
80
- this.db.set(cacheKey, {}).write();
81
- }
82
-
83
- let keyId = cacheKey + "." + key;
84
- this.db
85
- .set(keyId, value)
86
- .write();
87
-
88
- return true;
89
- }
90
-
91
- /**
92
- * 根据指定的名字 name 获取对应的值
93
- */
94
- getItem (key) {
95
- assert(_.isString(key), `key must be a string`);
96
- assert(key.length != 0, `key cannot be empty`);
97
-
98
- let cacheKey = this.storageKey.cache;
99
- let keyId = cacheKey + "." + key;
100
- const data = this.db
101
- .get(keyId)
102
- .value();
103
-
104
- return data;
105
- }
106
-
107
- mkdir (dirpath, dirname) {
108
- if (typeof dirname === 'undefined') {
109
- if (fs.existsSync(dirpath)) {
110
- return;
111
- }
112
- this.mkdir(dirpath, path.dirname(dirpath));
113
- } else {
114
- if (dirname !== path.dirname(dirpath)) {
115
- this.mkdir(dirpath);
116
- return;
117
- }
118
- if (fs.existsSync(dirname)) {
119
- fs.mkdirSync(dirpath);
120
- } else {
121
- this.mkdir(dirname, path.dirname(dirname));
122
- fs.mkdirSync(dirpath);
123
- }
124
- }
125
- };
126
-
127
- chmodPath (path, mode) {
128
- let files = [];
129
- if (fs.existsSync(path)) {
130
- files = fs.readdirSync(path);
131
- files.forEach((file, index) => {
132
- const curPath = path + '/' + file;
133
- if (fs.statSync(curPath).isDirectory()) {
134
- this.chmodPath(curPath, mode);
135
- } else {
136
- fs.chmodSync(curPath, mode);
137
- }
138
- });
139
- fs.chmodSync(path, mode);
140
- }
141
- };
142
- }
143
-
1
+ 'use strict';
2
+
3
+ const assert = require('assert');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const lowdb = require('lowdb');
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
+
144
99
  module.exports = LowdbStorage;
@@ -0,0 +1,59 @@
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
+
15
+ const storageDir = utilsCommon.getStorageDir();
16
+ if (!fs.existsSync(storageDir)) {
17
+ utilsCommon.mkdir(storageDir);
18
+ utilsCommon.chmodPath(storageDir, '777');
19
+ }
20
+
21
+ this.db = this.initDB(name, opt);
22
+ }
23
+
24
+ /**
25
+ * 初始化db
26
+ */
27
+ initDB (name, opt = {}) {
28
+ let options = Object.assign({
29
+ timeout: 5000,
30
+ }, opt);
31
+
32
+ // 存储类型:db文件、内存(:memory:)
33
+ let isFileDB = false;
34
+ if (path.extname(name) == '.db') {
35
+ name = this.getFilePath(name);
36
+ isFileDB = true;
37
+ }
38
+
39
+ const db = new Database(name, options);
40
+
41
+ // 如果是文件类型,判断文件是否创建成功
42
+ if (isFileDB) {
43
+ assert(fs.existsSync(name), `error: storage ${name} not exists`);
44
+ }
45
+
46
+ return db;
47
+ }
48
+
49
+ /**
50
+ * 获取文件绝对路径
51
+ */
52
+ getFilePath (name) {
53
+ const storageDir = utilsCommon.getStorageDir();
54
+ const dbFile = path.join(storageDir, name);
55
+ return dbFile;
56
+ }
57
+ }
58
+
59
+ module.exports = SqliteStorage;
package/package.json CHANGED
@@ -1,45 +1,45 @@
1
- {
2
- "name": "ee-core",
3
- "version": "1.2.7",
4
- "description": "ee core",
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-core": "./bin/tools.js"
13
- },
14
- "dependencies": {
15
- "agentkeepalive": "^4.2.0",
16
- "co": "^4.6.0",
17
- "debug": "^4.3.3",
18
- "depd": "^2.0.0",
19
- "egg-errors": "^2.3.0",
20
- "egg-logger": "^2.7.1",
21
- "electron-is": "^3.0.0",
22
- "electron-updater": "^4.6.1",
23
- "extend2": "^1.0.1",
24
- "fs-extra": "^10.0.0",
25
- "get-port": "^5.1.1",
26
- "globby": "^10.0.0",
27
- "humanize-ms": "^1.2.1",
28
- "is-type-of": "^1.2.1",
29
- "koa": "^2.13.4",
30
- "koa-bodyparser": "^4.3.0",
31
- "koa-convert": "^2.0.0",
32
- "koa-static": "^5.0.0",
33
- "koa2-cors": "^2.0.6",
34
- "lodash": "^4.17.21",
35
- "lowdb": "^1.0.0",
36
- "path-to-regexp": "^6.2.0",
37
- "socket.io": "^4.4.1",
38
- "socket.io-client": "^4.4.1",
39
- "uglify-js": "^3.14.5",
40
- "unzip-crx-3": "^0.2.0",
41
- "urllib": "^2.38.0",
42
- "utility": "^1.17.0"
43
- },
44
- "devDependencies": {}
45
- }
1
+ {
2
+ "name": "ee-core",
3
+ "version": "1.2.8-beta.4",
4
+ "description": "ee core",
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-core": "./bin/tools.js"
13
+ },
14
+ "dependencies": {
15
+ "agentkeepalive": "^4.2.0",
16
+ "better-sqlite3": "^7.6.0",
17
+ "co": "^4.6.0",
18
+ "debug": "^4.3.3",
19
+ "depd": "^2.0.0",
20
+ "egg-errors": "^2.3.0",
21
+ "egg-logger": "^2.7.1",
22
+ "electron-is": "^3.0.0",
23
+ "electron-updater": "^4.6.1",
24
+ "extend2": "^1.0.1",
25
+ "fs-extra": "^10.0.0",
26
+ "get-port": "^5.1.1",
27
+ "globby": "^10.0.0",
28
+ "humanize-ms": "^1.2.1",
29
+ "is-type-of": "^1.2.1",
30
+ "koa": "^2.13.4",
31
+ "koa-body": "^5.0.0",
32
+ "koa-convert": "^2.0.0",
33
+ "koa-static": "^5.0.0",
34
+ "koa2-cors": "^2.0.6",
35
+ "lodash": "^4.17.21",
36
+ "lowdb": "^1.0.0",
37
+ "path-to-regexp": "^6.2.0",
38
+ "socket.io": "^4.4.1",
39
+ "socket.io-client": "^4.4.1",
40
+ "uglify-js": "^3.14.5",
41
+ "urllib": "^2.38.0",
42
+ "utility": "^1.17.0"
43
+ },
44
+ "devDependencies": {}
45
+ }