ee-core 1.4.1-beta.2 → 1.5.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/core/lib/loader/mixin/controller.js +1 -1
- package/lib/baseApp.js +0 -2
- package/lib/constant.js +0 -19
- package/lib/eeApp.js +1 -1
- package/lib/storage/sqliteStorage.js +86 -17
- package/package.json +1 -1
|
@@ -47,7 +47,7 @@ module.exports = {
|
|
|
47
47
|
const controllerBase = opt.directory;
|
|
48
48
|
|
|
49
49
|
this.loadToApp(controllerBase, 'controller', opt);
|
|
50
|
-
this.options.logger.info('[ee:loader] Controller loaded: %s', controllerBase);
|
|
50
|
+
this.options.logger.info('[ee-core:loader] Controller loaded: %s', controllerBase);
|
|
51
51
|
this.timing.end('Load Controller');
|
|
52
52
|
},
|
|
53
53
|
|
package/lib/baseApp.js
CHANGED
package/lib/constant.js
CHANGED
|
@@ -1,26 +1,7 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
autoLaunch: {
|
|
3
|
-
LOGIN_SETTING_OPTIONS: {
|
|
4
|
-
// For Windows
|
|
5
|
-
args: [
|
|
6
|
-
'--opened-at-login=1'
|
|
7
|
-
]
|
|
8
|
-
}
|
|
9
|
-
},
|
|
10
2
|
storageKey: {
|
|
11
3
|
cache: 'cache',
|
|
12
4
|
},
|
|
13
|
-
ipcChannels: {
|
|
14
|
-
appMessage: 'app.message',
|
|
15
|
-
appUpdater: 'app.updater'
|
|
16
|
-
},
|
|
17
|
-
appUpdaterStatus: {
|
|
18
|
-
error: -1,
|
|
19
|
-
available: 1,
|
|
20
|
-
noAvailable: 2,
|
|
21
|
-
downloading: 3,
|
|
22
|
-
downloaded: 4,
|
|
23
|
-
},
|
|
24
5
|
socketIo: {
|
|
25
6
|
channel: {
|
|
26
7
|
partySoftware: 'c1',
|
package/lib/eeApp.js
CHANGED
|
@@ -194,7 +194,6 @@ class EeApp extends BaseApp {
|
|
|
194
194
|
return;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
const protocol = 'http://';
|
|
198
197
|
const developmentModeConfig = this.config.developmentMode;
|
|
199
198
|
const selectMode = developmentModeConfig.default;
|
|
200
199
|
const modeInfo = developmentModeConfig.mode[selectMode];
|
|
@@ -210,6 +209,7 @@ class EeApp extends BaseApp {
|
|
|
210
209
|
}
|
|
211
210
|
|
|
212
211
|
// 单页应用
|
|
212
|
+
const protocol = modeInfo.protocol || 'http://';
|
|
213
213
|
url = protocol + modeInfo.hostname + ':' + modeInfo.port;
|
|
214
214
|
if (this.config.env !== 'prod') {
|
|
215
215
|
this.loadMainUrl('spa', url);
|
|
@@ -11,47 +11,116 @@ class SqliteStorage {
|
|
|
11
11
|
assert(name, `db name ${name} Cannot be empty`);
|
|
12
12
|
|
|
13
13
|
this.name = name;
|
|
14
|
+
this.mode = this.getMode(name);
|
|
14
15
|
|
|
15
|
-
const storageDir =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const storageDir = this._createStorageDir();
|
|
17
|
+
this.storageDir = storageDir;
|
|
18
|
+
|
|
19
|
+
const fileName = this._formatFileName(name);
|
|
20
|
+
this.fileName = fileName;
|
|
20
21
|
|
|
21
|
-
this.db = this.
|
|
22
|
+
this.db = this._initDB(opt);
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* 初始化db
|
|
26
27
|
*/
|
|
27
|
-
|
|
28
|
+
_initDB (opt = {}) {
|
|
28
29
|
let options = Object.assign({
|
|
29
30
|
timeout: 5000,
|
|
30
31
|
}, opt);
|
|
31
32
|
|
|
32
33
|
// 存储类型:db文件、内存(:memory:)
|
|
33
|
-
let
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
isFileDB = true;
|
|
34
|
+
let dbPath = this.name;
|
|
35
|
+
if (this.mode != 'memory') {
|
|
36
|
+
dbPath = this.getFilePath();
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
const db = new Database(
|
|
39
|
+
const db = new Database(dbPath, options);
|
|
40
40
|
|
|
41
41
|
// 如果是文件类型,判断文件是否创建成功
|
|
42
|
-
if (
|
|
43
|
-
assert(fs.existsSync(
|
|
42
|
+
if (this.mode != 'memory') {
|
|
43
|
+
assert(fs.existsSync(dbPath), `error: storage ${dbPath} not exists`);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
return db;
|
|
47
47
|
}
|
|
48
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
|
+
|
|
49
118
|
/**
|
|
50
119
|
* 获取文件绝对路径
|
|
51
120
|
*/
|
|
52
|
-
getFilePath (
|
|
53
|
-
const
|
|
54
|
-
|
|
121
|
+
getFilePath () {
|
|
122
|
+
const dbFile = path.join(this.storageDir, this.fileName);
|
|
123
|
+
|
|
55
124
|
return dbFile;
|
|
56
125
|
}
|
|
57
126
|
}
|