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.
- package/LICENSE +21 -21
- package/README.md +2 -2
- package/bin/tools.js +22 -22
- package/config/config.default.js +250 -247
- package/core/index.js +12 -12
- package/core/lib/ee.js +209 -209
- package/core/lib/loader/context_loader.js +105 -105
- package/core/lib/loader/ee_loader.js +451 -451
- package/core/lib/loader/file_loader.js +262 -262
- package/core/lib/loader/mixin/config.js +138 -138
- package/core/lib/loader/mixin/controller.js +123 -123
- package/core/lib/loader/mixin/service.js +29 -29
- package/core/lib/utils/base_context_class.js +34 -34
- package/core/lib/utils/index.js +100 -100
- 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 +45 -45
- package/lib/application.js +80 -80
- package/lib/baseApp.js +118 -118
- package/lib/constant.js +28 -28
- package/lib/eeApp.js +326 -326
- package/lib/helper.js +51 -51
- package/lib/httpclient.js +136 -136
- package/lib/logger.js +46 -46
- package/lib/socket/httpServer.js +102 -104
- package/lib/socket/io.js +23 -23
- package/lib/socket/ipcServer.js +128 -128
- package/lib/socket/socketClient.js +50 -50
- package/lib/socket/socketServer.js +76 -76
- package/lib/socket/start.js +22 -22
- package/lib/storage/index.js +33 -21
- package/lib/storage/lowdbStorage.js +98 -143
- package/lib/storage/sqliteStorage.js +59 -0
- package/package.json +45 -45
- package/resource/loading.html +21 -21
- package/resource/view_example.html +21 -21
- package/tools/codeCompress.js +204 -204
- package/tools/replaceDist.js +76 -76
- package/utils/common.js +91 -30
- package/utils/index.js +207 -207
- package/utils/wrap.js +37 -37
- package/lib/storage/appStorage.js +0 -14
package/utils/common.js
CHANGED
|
@@ -1,30 +1,91 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
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
|
+
}
|
package/utils/index.js
CHANGED
|
@@ -1,207 +1,207 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const constant = require('../lib/constant');
|
|
6
|
-
const convert = require('koa-convert');
|
|
7
|
-
const is = require('is-type-of');
|
|
8
|
-
const co = require('co');
|
|
9
|
-
const utility = require('utility');
|
|
10
|
-
const eis = require('electron-is');
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 创建文件夹
|
|
14
|
-
*/
|
|
15
|
-
exports.mkdir = function(dirpath, dirname) {
|
|
16
|
-
// 判断是否是第一次调用
|
|
17
|
-
if (typeof dirname === 'undefined') {
|
|
18
|
-
if (fs.existsSync(dirpath)) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
this.mkdir(dirpath, path.dirname(dirpath));
|
|
22
|
-
} else {
|
|
23
|
-
// 判断第二个参数是否正常,避免调用时传入错误参数
|
|
24
|
-
if (dirname !== path.dirname(dirpath)) {
|
|
25
|
-
this.mkdir(dirpath);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
if (fs.existsSync(dirname)) {
|
|
29
|
-
fs.mkdirSync(dirpath);
|
|
30
|
-
} else {
|
|
31
|
-
this.mkdir(dirname, path.dirname(dirname));
|
|
32
|
-
fs.mkdirSync(dirpath);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* 修改文件权限
|
|
39
|
-
*/
|
|
40
|
-
exports.chmodPath = function(path, mode) {
|
|
41
|
-
let files = [];
|
|
42
|
-
if (fs.existsSync(path)) {
|
|
43
|
-
files = fs.readdirSync(path);
|
|
44
|
-
files.forEach((file, index) => {
|
|
45
|
-
const curPath = path + '/' + file;
|
|
46
|
-
if (fs.statSync(curPath).isDirectory()) {
|
|
47
|
-
this.chmodPath(curPath, mode); // 递归删除文件夹
|
|
48
|
-
} else {
|
|
49
|
-
fs.chmodSync(curPath, mode);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
fs.chmodSync(path, mode);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* 获取项目根目录package.json
|
|
59
|
-
*/
|
|
60
|
-
exports.getPackage = function() {
|
|
61
|
-
const cdb = this.getCoreDB();
|
|
62
|
-
const config = cdb.getItem('config');
|
|
63
|
-
const json = utility.readJSONSync(path.join(config.homeDir, 'package.json'));
|
|
64
|
-
|
|
65
|
-
return json;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* 获取 coredb
|
|
70
|
-
*/
|
|
71
|
-
exports.getCoreDB = function() {
|
|
72
|
-
const coreDB = require('../lib/storage/index').JsonDB.connection('system');
|
|
73
|
-
return coreDB;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* 获取 ee配置
|
|
78
|
-
*/
|
|
79
|
-
exports.getEeConfig = function() {
|
|
80
|
-
const cdb = this.getCoreDB();
|
|
81
|
-
const config = cdb.getItem('config');
|
|
82
|
-
|
|
83
|
-
return config;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* 获取 egg配置
|
|
88
|
-
*/
|
|
89
|
-
exports.getEggConfig = function() {
|
|
90
|
-
const cdb = this.getCoreDB();
|
|
91
|
-
const config = cdb.getItem('config');
|
|
92
|
-
|
|
93
|
-
return config.egg;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* 获取 数据库存储路径
|
|
98
|
-
*/
|
|
99
|
-
exports.getStorageDir = function() {
|
|
100
|
-
const cdb = this.getCoreDB();
|
|
101
|
-
const dirPath = cdb.getStorageDir();
|
|
102
|
-
|
|
103
|
-
return dirPath;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* 获取 应用程序数据目录 (开发环境时,为项目根目录)
|
|
108
|
-
*/
|
|
109
|
-
exports.getAppUserDataDir = function() {
|
|
110
|
-
const cdb = this.getCoreDB();
|
|
111
|
-
const config = cdb.getItem('config');
|
|
112
|
-
const env = config.env;
|
|
113
|
-
const dir = env === 'local' || env === 'unittest' ? config.homeDir : config.appUserDataDir;
|
|
114
|
-
return dir;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* 获取 日志目录
|
|
119
|
-
*/
|
|
120
|
-
exports.getLogDir = function() {
|
|
121
|
-
const logPath = path.join(this.getAppUserDataDir(), 'logs');
|
|
122
|
-
return logPath;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* 获取 socketio port
|
|
127
|
-
*/
|
|
128
|
-
exports.getSocketPort = function() {
|
|
129
|
-
const cdb = this.getCoreDB();
|
|
130
|
-
const port = cdb.getItem('config').socketServer.port;
|
|
131
|
-
return parseInt(port);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* 获取 socket channel
|
|
136
|
-
*/
|
|
137
|
-
exports.getSocketChannel = function() {
|
|
138
|
-
return constant.socketIo.channel;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* 获取 额外资源目录
|
|
143
|
-
*/
|
|
144
|
-
exports.getExtraResourcesDir = function() {
|
|
145
|
-
const cdb = this.getCoreDB();
|
|
146
|
-
const config = cdb.getItem('config');
|
|
147
|
-
const execDir = config.execDir;
|
|
148
|
-
|
|
149
|
-
// 资源路径不同
|
|
150
|
-
let dir = '';
|
|
151
|
-
if (config.isPackaged) {
|
|
152
|
-
// 打包后 execDir为 应用程序 exe\dmg\dep软件所在目录;打包前该值是项目根目录
|
|
153
|
-
// windows和MacOs不一样
|
|
154
|
-
dir = path.join(execDir, "resources", "extraResources");
|
|
155
|
-
if (eis.macOS()) {
|
|
156
|
-
dir = path.join(execDir, "..", "Resources", "extraResources");
|
|
157
|
-
}
|
|
158
|
-
} else {
|
|
159
|
-
// 打包前
|
|
160
|
-
dir = path.join(execDir, "build", "extraResources");
|
|
161
|
-
}
|
|
162
|
-
return dir;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* 执行一个函数
|
|
167
|
-
*/
|
|
168
|
-
exports.callFn = async function (fn, args, ctx) {
|
|
169
|
-
args = args || [];
|
|
170
|
-
if (!is.function(fn)) return;
|
|
171
|
-
if (is.generatorFunction(fn)) fn = co.wrap(fn);
|
|
172
|
-
return ctx ? fn.call(ctx, ...args) : fn(...args);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
exports.middleware = function (fn) {
|
|
176
|
-
return is.generatorFunction(fn) ? convert(fn) : fn;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* 版本号比较
|
|
181
|
-
*/
|
|
182
|
-
exports.compareVersion = function (v1, v2) {
|
|
183
|
-
v1 = v1.split('.')
|
|
184
|
-
v2 = v2.split('.')
|
|
185
|
-
const len = Math.max(v1.length, v2.length)
|
|
186
|
-
|
|
187
|
-
while (v1.length < len) {
|
|
188
|
-
v1.push('0')
|
|
189
|
-
}
|
|
190
|
-
while (v2.length < len) {
|
|
191
|
-
v2.push('0')
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
for (let i = 0; i < len; i++) {
|
|
195
|
-
const num1 = parseInt(v1[i])
|
|
196
|
-
const num2 = parseInt(v2[i])
|
|
197
|
-
|
|
198
|
-
if (num1 > num2) {
|
|
199
|
-
return 1
|
|
200
|
-
} else if (num1 < num2) {
|
|
201
|
-
return -1
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return 0
|
|
206
|
-
}
|
|
207
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const constant = require('../lib/constant');
|
|
6
|
+
const convert = require('koa-convert');
|
|
7
|
+
const is = require('is-type-of');
|
|
8
|
+
const co = require('co');
|
|
9
|
+
const utility = require('utility');
|
|
10
|
+
const eis = require('electron-is');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 创建文件夹
|
|
14
|
+
*/
|
|
15
|
+
exports.mkdir = function(dirpath, dirname) {
|
|
16
|
+
// 判断是否是第一次调用
|
|
17
|
+
if (typeof dirname === 'undefined') {
|
|
18
|
+
if (fs.existsSync(dirpath)) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
this.mkdir(dirpath, path.dirname(dirpath));
|
|
22
|
+
} else {
|
|
23
|
+
// 判断第二个参数是否正常,避免调用时传入错误参数
|
|
24
|
+
if (dirname !== path.dirname(dirpath)) {
|
|
25
|
+
this.mkdir(dirpath);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (fs.existsSync(dirname)) {
|
|
29
|
+
fs.mkdirSync(dirpath);
|
|
30
|
+
} else {
|
|
31
|
+
this.mkdir(dirname, path.dirname(dirname));
|
|
32
|
+
fs.mkdirSync(dirpath);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 修改文件权限
|
|
39
|
+
*/
|
|
40
|
+
exports.chmodPath = function(path, mode) {
|
|
41
|
+
let files = [];
|
|
42
|
+
if (fs.existsSync(path)) {
|
|
43
|
+
files = fs.readdirSync(path);
|
|
44
|
+
files.forEach((file, index) => {
|
|
45
|
+
const curPath = path + '/' + file;
|
|
46
|
+
if (fs.statSync(curPath).isDirectory()) {
|
|
47
|
+
this.chmodPath(curPath, mode); // 递归删除文件夹
|
|
48
|
+
} else {
|
|
49
|
+
fs.chmodSync(curPath, mode);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
fs.chmodSync(path, mode);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 获取项目根目录package.json
|
|
59
|
+
*/
|
|
60
|
+
exports.getPackage = function() {
|
|
61
|
+
const cdb = this.getCoreDB();
|
|
62
|
+
const config = cdb.getItem('config');
|
|
63
|
+
const json = utility.readJSONSync(path.join(config.homeDir, 'package.json'));
|
|
64
|
+
|
|
65
|
+
return json;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 获取 coredb
|
|
70
|
+
*/
|
|
71
|
+
exports.getCoreDB = function() {
|
|
72
|
+
const coreDB = require('../lib/storage/index').JsonDB.connection('system');
|
|
73
|
+
return coreDB;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 获取 ee配置
|
|
78
|
+
*/
|
|
79
|
+
exports.getEeConfig = function() {
|
|
80
|
+
const cdb = this.getCoreDB();
|
|
81
|
+
const config = cdb.getItem('config');
|
|
82
|
+
|
|
83
|
+
return config;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 获取 egg配置
|
|
88
|
+
*/
|
|
89
|
+
exports.getEggConfig = function() {
|
|
90
|
+
const cdb = this.getCoreDB();
|
|
91
|
+
const config = cdb.getItem('config');
|
|
92
|
+
|
|
93
|
+
return config.egg;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 获取 数据库存储路径
|
|
98
|
+
*/
|
|
99
|
+
exports.getStorageDir = function() {
|
|
100
|
+
const cdb = this.getCoreDB();
|
|
101
|
+
const dirPath = cdb.getStorageDir();
|
|
102
|
+
|
|
103
|
+
return dirPath;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 获取 应用程序数据目录 (开发环境时,为项目根目录)
|
|
108
|
+
*/
|
|
109
|
+
exports.getAppUserDataDir = function() {
|
|
110
|
+
const cdb = this.getCoreDB();
|
|
111
|
+
const config = cdb.getItem('config');
|
|
112
|
+
const env = config.env;
|
|
113
|
+
const dir = env === 'local' || env === 'unittest' ? config.homeDir : config.appUserDataDir;
|
|
114
|
+
return dir;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 获取 日志目录
|
|
119
|
+
*/
|
|
120
|
+
exports.getLogDir = function() {
|
|
121
|
+
const logPath = path.join(this.getAppUserDataDir(), 'logs');
|
|
122
|
+
return logPath;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* 获取 socketio port
|
|
127
|
+
*/
|
|
128
|
+
exports.getSocketPort = function() {
|
|
129
|
+
const cdb = this.getCoreDB();
|
|
130
|
+
const port = cdb.getItem('config').socketServer.port;
|
|
131
|
+
return parseInt(port);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* 获取 socket channel
|
|
136
|
+
*/
|
|
137
|
+
exports.getSocketChannel = function() {
|
|
138
|
+
return constant.socketIo.channel;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 获取 额外资源目录
|
|
143
|
+
*/
|
|
144
|
+
exports.getExtraResourcesDir = function() {
|
|
145
|
+
const cdb = this.getCoreDB();
|
|
146
|
+
const config = cdb.getItem('config');
|
|
147
|
+
const execDir = config.execDir;
|
|
148
|
+
|
|
149
|
+
// 资源路径不同
|
|
150
|
+
let dir = '';
|
|
151
|
+
if (config.isPackaged) {
|
|
152
|
+
// 打包后 execDir为 应用程序 exe\dmg\dep软件所在目录;打包前该值是项目根目录
|
|
153
|
+
// windows和MacOs不一样
|
|
154
|
+
dir = path.join(execDir, "resources", "extraResources");
|
|
155
|
+
if (eis.macOS()) {
|
|
156
|
+
dir = path.join(execDir, "..", "Resources", "extraResources");
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
// 打包前
|
|
160
|
+
dir = path.join(execDir, "build", "extraResources");
|
|
161
|
+
}
|
|
162
|
+
return dir;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* 执行一个函数
|
|
167
|
+
*/
|
|
168
|
+
exports.callFn = async function (fn, args, ctx) {
|
|
169
|
+
args = args || [];
|
|
170
|
+
if (!is.function(fn)) return;
|
|
171
|
+
if (is.generatorFunction(fn)) fn = co.wrap(fn);
|
|
172
|
+
return ctx ? fn.call(ctx, ...args) : fn(...args);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
exports.middleware = function (fn) {
|
|
176
|
+
return is.generatorFunction(fn) ? convert(fn) : fn;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* 版本号比较
|
|
181
|
+
*/
|
|
182
|
+
exports.compareVersion = function (v1, v2) {
|
|
183
|
+
v1 = v1.split('.')
|
|
184
|
+
v2 = v2.split('.')
|
|
185
|
+
const len = Math.max(v1.length, v2.length)
|
|
186
|
+
|
|
187
|
+
while (v1.length < len) {
|
|
188
|
+
v1.push('0')
|
|
189
|
+
}
|
|
190
|
+
while (v2.length < len) {
|
|
191
|
+
v2.push('0')
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
for (let i = 0; i < len; i++) {
|
|
195
|
+
const num1 = parseInt(v1[i])
|
|
196
|
+
const num2 = parseInt(v2[i])
|
|
197
|
+
|
|
198
|
+
if (num1 > num2) {
|
|
199
|
+
return 1
|
|
200
|
+
} else if (num1 < num2) {
|
|
201
|
+
return -1
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return 0
|
|
206
|
+
}
|
|
207
|
+
|
package/utils/wrap.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const assert = require('assert');
|
|
4
|
-
const is = require('is-type-of');
|
|
5
|
-
|
|
6
|
-
exports.getProperties = (filepath, { caseStyle }) => {
|
|
7
|
-
// if caseStyle is function, return the result of function
|
|
8
|
-
if (is.function(caseStyle)) {
|
|
9
|
-
const result = caseStyle(filepath);
|
|
10
|
-
assert(is.array(result), `caseStyle expect an array, but got ${result}`);
|
|
11
|
-
return result;
|
|
12
|
-
}
|
|
13
|
-
// use default camelize
|
|
14
|
-
return this.defaultCamelize(filepath, caseStyle);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
exports.defaultCamelize = (filepath, caseStyle) => {
|
|
18
|
-
const properties = filepath.substring(0, filepath.lastIndexOf('.')).split('/');
|
|
19
|
-
return properties.map(property => {
|
|
20
|
-
if (!/^[a-z][a-z0-9_-]*$/i.test(property)) {
|
|
21
|
-
throw new Error(`${property} is not match 'a-z0-9_-' in ${filepath}`);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
property = property.replace(/[_-][a-z]/ig, s => s.substring(1).toUpperCase());
|
|
25
|
-
let first = property[0];
|
|
26
|
-
switch (caseStyle) {
|
|
27
|
-
case 'lower':
|
|
28
|
-
first = first.toLowerCase();
|
|
29
|
-
break;
|
|
30
|
-
case 'upper':
|
|
31
|
-
first = first.toUpperCase();
|
|
32
|
-
break;
|
|
33
|
-
case 'camel':
|
|
34
|
-
default:
|
|
35
|
-
}
|
|
36
|
-
return first + property.substring(1);
|
|
37
|
-
});
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const assert = require('assert');
|
|
4
|
+
const is = require('is-type-of');
|
|
5
|
+
|
|
6
|
+
exports.getProperties = (filepath, { caseStyle }) => {
|
|
7
|
+
// if caseStyle is function, return the result of function
|
|
8
|
+
if (is.function(caseStyle)) {
|
|
9
|
+
const result = caseStyle(filepath);
|
|
10
|
+
assert(is.array(result), `caseStyle expect an array, but got ${result}`);
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
// use default camelize
|
|
14
|
+
return this.defaultCamelize(filepath, caseStyle);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.defaultCamelize = (filepath, caseStyle) => {
|
|
18
|
+
const properties = filepath.substring(0, filepath.lastIndexOf('.')).split('/');
|
|
19
|
+
return properties.map(property => {
|
|
20
|
+
if (!/^[a-z][a-z0-9_-]*$/i.test(property)) {
|
|
21
|
+
throw new Error(`${property} is not match 'a-z0-9_-' in ${filepath}`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
property = property.replace(/[_-][a-z]/ig, s => s.substring(1).toUpperCase());
|
|
25
|
+
let first = property[0];
|
|
26
|
+
switch (caseStyle) {
|
|
27
|
+
case 'lower':
|
|
28
|
+
first = first.toLowerCase();
|
|
29
|
+
break;
|
|
30
|
+
case 'upper':
|
|
31
|
+
first = first.toUpperCase();
|
|
32
|
+
break;
|
|
33
|
+
case 'camel':
|
|
34
|
+
default:
|
|
35
|
+
}
|
|
36
|
+
return first + property.substring(1);
|
|
37
|
+
});
|
|
38
38
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
class AppStorage {
|
|
4
|
-
constructor() {
|
|
5
|
-
const Storage = require('./storage');
|
|
6
|
-
const sObj = Storage.getInstance('appData');
|
|
7
|
-
|
|
8
|
-
for (const attr of sObj) {
|
|
9
|
-
Object.assign(UserStorage.prototype, attr);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
module.exports = AppStorage;
|