ee-core 1.2.9-bate.1 → 1.2.10-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/bin/tools.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  const codeCompress = require('../tools/codeCompress');
4
4
  const replaceDist = require('../tools/replaceDist');
5
+ const encrypt = require('../tools/encrypt');
5
6
 
6
7
  // argv
7
8
  const args = process.argv;
@@ -20,3 +21,7 @@ if (cmd == 'compress') {
20
21
  if (cmd == 'restore') {
21
22
  codeCompress.restore();
22
23
  }
24
+
25
+ if (cmd == 'encrypt') {
26
+ encrypt.run();
27
+ }
@@ -246,6 +246,13 @@ module.exports = appInfo => {
246
246
  enable: false
247
247
  };
248
248
 
249
+ /**
250
+ * TODO storage
251
+ */
252
+ config.storage = {
253
+ dir: path.join(appInfo.root, 'data'),
254
+ };
255
+
249
256
  /**
250
257
  * loading页(废弃)
251
258
  */
@@ -196,11 +196,7 @@ class EeLoader {
196
196
  home: this.getHomedir(),
197
197
 
198
198
  /**
199
- * The directory whether is baseDir or HOME depend on env.
200
- * it's good for test when you want to write some file to HOME,
201
- * but don't want to write to the real directory,
202
- * so use root to write file to baseDir instead of HOME when unittest.
203
- * keep root directory in baseDir when local and unittest
199
+ * The directory whether is homeDir or appUserData depend on env.
204
200
  * @member {String} AppInfo#root
205
201
  */
206
202
  root: env === 'local' || env === 'unittest' ? this.getHomedir() : this.options.appUserData,
@@ -2,6 +2,7 @@ const {app} = require('electron');
2
2
  const path = require('path');
3
3
  const EeApp = require('./eeApp');
4
4
  const debug = require('debug')('ee-core:Appliaction');
5
+ const fs = require('fs');
5
6
 
6
7
  class Appliaction extends EeApp {
7
8
  constructor() {
@@ -45,6 +46,13 @@ class Appliaction extends EeApp {
45
46
  options.execDir = path.dirname(app.getPath('exe'));
46
47
  }
47
48
 
49
+ // Use encryption, base directory is public/electron
50
+ const encryptDir = path.join(app.getAppPath(), 'public', 'electron');
51
+ let isEncrypted = fs.existsSync(encryptDir);
52
+ if (options.env == 'prod' && isEncrypted) {
53
+ options.baseDir = encryptDir;
54
+ }
55
+
48
56
  // normalize env
49
57
  env.NODE_ENV = 'production';
50
58
  env.EE_HOME = options.homeDir;
@@ -57,6 +65,8 @@ class Appliaction extends EeApp {
57
65
  env.EE_SOCKET_PORT = null;
58
66
  env.EE_HTTP_PORT = null;
59
67
  env.HOT_RELOAD = hotReload;
68
+ env.EE_EXEC_DIR = options.execDir;
69
+ env.EE_DATABASE_DIR = null;
60
70
  debug('options:%j', options)
61
71
 
62
72
  super(options);
@@ -67,8 +77,7 @@ class Appliaction extends EeApp {
67
77
 
68
78
  await this.createPorts();
69
79
 
70
- this.startSocket();
71
- //return;
80
+ await this.startSocket();
72
81
 
73
82
  await this.ready();
74
83
 
package/lib/baseApp.js CHANGED
@@ -19,6 +19,9 @@ class BaseApp extends EeAppCore {
19
19
 
20
20
  this.loader.loadConfig();
21
21
 
22
+ // todo
23
+ //this.setDatabaseDir();
24
+
22
25
  // 缓存配置
23
26
  this.getCoreDB().setItem('config', this.config);
24
27
 
@@ -108,6 +111,18 @@ class BaseApp extends EeAppCore {
108
111
  return this[HTTPCLIENT];
109
112
  }
110
113
 
114
+ /**
115
+ * todo 设置db存储目录
116
+ */
117
+ setDatabaseDir (dirPath) {
118
+ if (dirPath) {
119
+ assert(typeof dirPath === 'string', ` ${dirPath} dirPath required, and must be a string`);
120
+ process.env.EE_DATABASE_DIR = dirPath;
121
+ } else {
122
+ process.env.EE_DATABASE_DIR = this.config.database.dir;
123
+ }
124
+ }
125
+
111
126
  /**
112
127
  * core app have been loaded
113
128
  */
package/lib/eeApp.js CHANGED
@@ -47,7 +47,7 @@ class EeApp extends BaseApp {
47
47
  /**
48
48
  * 启动通信模块
49
49
  */
50
- startSocket () {
50
+ async startSocket () {
51
51
  const socket = require('./socket/start');
52
52
  socket(this);
53
53
  }
@@ -100,11 +100,6 @@ class EeApp extends BaseApp {
100
100
  const winOptions = this.config.windowsOption;
101
101
  this.electron.mainWindow = new BrowserWindow(winOptions);
102
102
  let win = this.electron.mainWindow;
103
- if (winOptions.show === false) {
104
- win.once('ready-to-show', () => {
105
- win.show();
106
- })
107
- }
108
103
 
109
104
  // 菜单显示/隐藏
110
105
  if (this.config.openAppMenu === 'dev-show'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ee-core",
3
- "version": "1.2.9-bate.1",
3
+ "version": "1.2.10-beta.1",
4
4
  "description": "ee core",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,182 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const fs = require('fs');
5
+ const fsPro = require('fs-extra');
6
+ const UglifyJS = require('uglify-js');
7
+
8
+ class Encrypt {
9
+ constructor() {
10
+
11
+ // argv
12
+ this.type = '';
13
+ for (let i = 0; i < process.argv.length; i++) {
14
+ let tmpArgv = process.argv[i];
15
+ if (tmpArgv.indexOf('--type=') !== -1) {
16
+ this.type = tmpArgv.substring(7);
17
+ }
18
+ }
19
+
20
+ const directory = [
21
+ 'electron',
22
+ ];
23
+ this.dirs = [];
24
+
25
+ this.basePath = process.cwd();
26
+ // if (this.type == 'uglify') {
27
+ // this.encryptCodeDir = path.join(this.basePath, 'public');
28
+ // }
29
+ this.encryptCodeDir = path.join(this.basePath, 'public');
30
+
31
+ // 检查存在的目录
32
+ for (let i = 0; i < directory.length; i++) {
33
+ let codeDirPath = path.join(this.basePath, directory[i]);
34
+ if (fs.existsSync(codeDirPath)) {
35
+ this.dirs.push(directory[i]);
36
+ }
37
+ }
38
+ console.log('dirs:', this.dirs);
39
+ }
40
+
41
+ /**
42
+ * 备份 electron目录代码
43
+ */
44
+ backup () {
45
+ console.log('[ee-core] [encrypt] backup start');
46
+
47
+ for (let i = 0; i < this.dirs.length; i++) {
48
+ // check code dir
49
+ let codeDirPath = path.join(this.basePath, this.dirs[i]);
50
+ if (!fs.existsSync(codeDirPath)) {
51
+ console.log('[ee-core] [encrypt] backup ERROR: %s is not exist', codeDirPath);
52
+ return
53
+ }
54
+
55
+ let targetDir = path.join(this.encryptCodeDir, this.dirs[i]);
56
+
57
+ // remove old
58
+ this.rmBackup(targetDir);
59
+
60
+ // copy
61
+ console.log('[ee-core] [encrypt] backup targetDir:', targetDir);
62
+ if (!fs.existsSync(targetDir)) {
63
+ this.mkdir(targetDir);
64
+ this.chmodPath(targetDir, '777');
65
+ }
66
+
67
+ fsPro.copySync(codeDirPath, targetDir);
68
+ }
69
+ console.log('[ee-core] [encrypt] backup success');
70
+ }
71
+
72
+ /**
73
+ * 压缩代码
74
+ */
75
+ compress () {
76
+ console.log('[ee-core] [encrypt] compress start');
77
+ for (let i = 0; i < this.dirs.length; i++) {
78
+ let codeDirPath = path.join(this.encryptCodeDir, this.dirs[i]);
79
+ this.compressLoop(codeDirPath);
80
+ }
81
+ console.log('[ee-core] [encrypt] compress success');
82
+ };
83
+
84
+ compressLoop (dirPath) {
85
+ let files = [];
86
+ if (fs.existsSync(dirPath)) {
87
+ files = fs.readdirSync(dirPath);
88
+ files.forEach((file, index) => {
89
+ let curPath = dirPath + '/' + file;
90
+ if (fs.statSync(curPath).isDirectory()) {
91
+ this.compressLoop(curPath);
92
+ } else {
93
+ if (path.extname(curPath) === '.js') {
94
+ this.miniFile(curPath);
95
+ }
96
+ }
97
+ });
98
+ }
99
+ }
100
+
101
+ miniFile (file) {
102
+ let code = fs.readFileSync(file, "utf8");
103
+ const options = {
104
+ mangle: {
105
+ toplevel: false,
106
+ },
107
+ };
108
+
109
+ let result = UglifyJS.minify(code, options);
110
+ fs.writeFileSync(file, result.code, "utf8");
111
+ }
112
+
113
+ /**
114
+ * 移除备份
115
+ */
116
+ rmBackup (dir) {
117
+ if (fs.existsSync(dir)) {
118
+ console.log('[ee-core] [encrypt] clean old directory:', dir);
119
+ fs.rmSync(dir, {recursive: true, force: true});
120
+ }
121
+ return;
122
+ }
123
+
124
+ /**
125
+ * 检查文件是否存在
126
+ */
127
+ fileExist (filePath) {
128
+ try {
129
+ return fs.statSync(filePath).isFile();
130
+ } catch (err) {
131
+ return false;
132
+ }
133
+ };
134
+
135
+ mkdir (dirpath, dirname) {
136
+ // 判断是否是第一次调用
137
+ if (typeof dirname === 'undefined') {
138
+ if (fs.existsSync(dirpath)) {
139
+ return;
140
+ }
141
+ this.mkdir(dirpath, path.dirname(dirpath));
142
+ } else {
143
+ // 判断第二个参数是否正常,避免调用时传入错误参数
144
+ if (dirname !== path.dirname(dirpath)) {
145
+ this.mkdir(dirpath);
146
+ return;
147
+ }
148
+ if (fs.existsSync(dirname)) {
149
+ fs.mkdirSync(dirpath);
150
+ } else {
151
+ this.mkdir(dirname, path.dirname(dirname));
152
+ fs.mkdirSync(dirpath);
153
+ }
154
+ }
155
+ };
156
+
157
+ chmodPath (path, mode) {
158
+ let files = [];
159
+ if (fs.existsSync(path)) {
160
+ files = fs.readdirSync(path);
161
+ files.forEach((file, index) => {
162
+ const curPath = path + '/' + file;
163
+ if (fs.statSync(curPath).isDirectory()) {
164
+ this.chmodPath(curPath, mode); // 递归删除文件夹
165
+ } else {
166
+ fs.chmodSync(curPath, mode);
167
+ }
168
+ });
169
+ fs.chmodSync(path, mode);
170
+ }
171
+ };
172
+ }
173
+
174
+ const run = () => {
175
+ const e = new Encrypt();
176
+ e.backup();
177
+ e.compress();
178
+ }
179
+
180
+ module.exports = {
181
+ run
182
+ };
package/utils/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const fs = require('fs');
4
3
  const path = require('path');
5
4
  const constant = require('../lib/constant');
6
5
  const convert = require('koa-convert');
@@ -8,51 +7,21 @@ const is = require('is-type-of');
8
7
  const co = require('co');
9
8
  const utility = require('utility');
10
9
  const eis = require('electron-is');
10
+ const utilsCommon = require('./common');
11
11
 
12
12
  /**
13
13
  * 创建文件夹
14
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
- };
15
+ exports.mkdir = function (dirpath, dirname) {
16
+ return utilsCommon.mkdir(dirpath, dirname);
17
+ }
36
18
 
37
19
  /**
38
20
  * 修改文件权限
39
21
  */
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
-
22
+ exports.chmodPath = function (path, mode) {
23
+ return utilsCommon.chmodPath(path, mode);
24
+ }
56
25
 
57
26
  /**
58
27
  * 获取项目根目录package.json
@@ -97,10 +66,7 @@ exports.getEggConfig = function() {
97
66
  * 获取 数据库存储路径
98
67
  */
99
68
  exports.getStorageDir = function() {
100
- const cdb = this.getCoreDB();
101
- const dirPath = cdb.getStorageDir();
102
-
103
- return dirPath;
69
+ return utilsCommon.getStorageDir();
104
70
  }
105
71
 
106
72
  /**
@@ -118,7 +84,8 @@ exports.getAppUserDataDir = function() {
118
84
  * 获取 日志目录
119
85
  */
120
86
  exports.getLogDir = function() {
121
- const logPath = path.join(this.getAppUserDataDir(), 'logs');
87
+ const cdb = this.getCoreDB();
88
+ const logPath = cdb.getItem('config').logger.dir;
122
89
  return logPath;
123
90
  }
124
91
 
@@ -180,28 +147,5 @@ exports.middleware = function (fn) {
180
147
  * 版本号比较
181
148
  */
182
149
  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
-
150
+ return utilsCommon.compareVersion(v1, v2);
151
+ }
Binary file
Binary file
@@ -1,22 +0,0 @@
1
- <html>
2
- <head>
3
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4
- <style type="text/css">
5
- body{
6
- margin:0px auto;
7
- }
8
- #picture1 {
9
- position: absolute;
10
- left: 50%;
11
- top: 35%;
12
- transform: translate(-50%, -50%);
13
- }
14
- </style>
15
- <title></title>
16
- </head>
17
- <body>
18
- <div id="picture1">
19
- <img src="./images/loding.gif" />
20
- </div>
21
- </body>
22
- </html>
@@ -1,22 +0,0 @@
1
- <html>
2
- <head>
3
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4
- <style type="text/css">
5
- body{
6
- margin:0px auto;
7
- }
8
- #content {
9
- position: absolute;
10
- left: 50%;
11
- top: 35%;
12
- transform: translate(-50%, -50%);
13
- }
14
- </style>
15
- <title></title>
16
- </head>
17
- <body>
18
- <div id="content">
19
- 这是一个html页面
20
- </div>
21
- </body>
22
- </html>