ee-core 1.4.0 → 1.4.1-beta.2

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
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  const replaceDist = require('../tools/replaceDist');
4
4
  const encrypt = require('../tools/encrypt');
@@ -107,7 +107,7 @@ module.exports = {
107
107
  this._setConfigMeta(envConfig, '<process.env.EE_APP_CONFIG>');
108
108
  return envConfig;
109
109
  } catch (err) {
110
- this.options.logger.warn('[egg-loader] process.env.EE_APP_CONFIG is not invalid JSON: %s', envConfigStr);
110
+ this.options.logger.warn('[ee-loader] process.env.EE_APP_CONFIG is not invalid JSON: %s', envConfigStr);
111
111
  }
112
112
  },
113
113
 
@@ -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('[egg:loader] Controller loaded: %s', controllerBase);
50
+ this.options.logger.info('[ee:loader] Controller loaded: %s', controllerBase);
51
51
  this.timing.end('Load Controller');
52
52
  },
53
53
 
@@ -32,7 +32,7 @@ module.exports = {
32
32
  if (obj.__esModule) return 'default' in obj ? obj.default : obj;
33
33
  return obj;
34
34
  } catch (err) {
35
- err.message = `[egg-core] load file: ${filepath}, error: ${err.message}`;
35
+ err.message = `[ee-core] load file: ${filepath}, error: ${err.message}`;
36
36
  throw err;
37
37
  }
38
38
  },
@@ -65,8 +65,6 @@ module.exports = {
65
65
  let fileName;
66
66
  /* istanbul ignore else */
67
67
  if (callSite) {
68
- // egg-mock will create a proxy
69
- // https://github.com/eggjs/egg-mock/blob/master/lib/app.js#L174
70
68
  fileName = callSite.getFileName();
71
69
  /* istanbul ignore if */
72
70
  if (fileName && fileName.endsWith('egg-mock/lib/app.js')) {
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const debug = require('debug')('egg-core#sequencify');
3
+ const debug = require('debug')('ee-core#sequencify');
4
4
 
5
5
  function sequence(tasks, names, results, missing, recursive, nest, optional, parent) {
6
6
  names.forEach(function(name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ee-core",
3
- "version": "1.4.0",
3
+ "version": "1.4.1-beta.2",
4
4
  "description": "ee core",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/tools/encrypt.js CHANGED
@@ -17,9 +17,12 @@ class Encrypt {
17
17
  this.config = this.loadConfig('encrypt.js');
18
18
  this.filesExt = this.config.fileExt || ['.js'];
19
19
  this.type = this.config.type || 'bytecode';
20
+ this.bOpt = this.config.bytecodeOptions || {};
21
+ this.cOpt = this.config.confusionOptions || {};
22
+
20
23
  const directory = this.config.directory || ['electron'];
21
- this.tmpFile = '';
22
- this.mapFile = '';
24
+ this.tmpFile = ''; // todo
25
+ this.mapFile = ''; // todo
23
26
 
24
27
  // cli
25
28
  if (Object.keys(this.config).length == 0) {
@@ -142,45 +145,17 @@ class Encrypt {
142
145
  * 使用 javascript-obfuscator 生成压缩/混淆文件
143
146
  */
144
147
  generateJSConfuseFile (file) {
145
- let defaultOpt = {
148
+ let opt = Object.assign({
146
149
  compact: true,
147
150
  stringArray: true,
148
- rotateStringArray: true,
149
- stringArrayEncoding: ['base64'],
150
151
  stringArrayThreshold: 1,
151
- disableConsoleOutput: true,
152
- }
152
+ }, this.cOpt);
153
+
153
154
  let code = fs.readFileSync(file, "utf8");
154
- let result = JavaScriptObfuscator.obfuscate(code, defaultOpt);
155
+ let result = JavaScriptObfuscator.obfuscate(code, opt);
155
156
  fs.writeFileSync(file, result.getObfuscatedCode(), "utf8");
156
157
  }
157
158
 
158
- /**
159
- * (废弃) 使用 uglify 生成压缩/混淆文件
160
- */
161
- generateConfuseFile (file) {
162
- let defaultOpt = {
163
- mangle: {
164
- toplevel: false,
165
- },
166
- compress: {
167
- drop_console: true,
168
- passes: 2
169
- },
170
- output: {
171
- beautify: false
172
- },
173
- }
174
- let options = defaultOpt;
175
- if (is.object(this.config.uglifyOpt)) {
176
- options = Object.assign(defaultOpt, this.config.uglifyOpt);
177
- }
178
-
179
- let code = fs.readFileSync(file, "utf8");
180
- let result = UglifyJS.minify(code, options);
181
- fs.writeFileSync(file, result.code, "utf8");
182
- }
183
-
184
159
  /**
185
160
  * 生成字节码文件
186
161
  */
@@ -190,11 +165,13 @@ class Encrypt {
190
165
  }
191
166
  //let jscFile = curPath.replace(/.js/g, '.jsc');
192
167
  let jscFile = curPath + 'c';
193
- bytenode.compileFile({
168
+ let opt = Object.assign({
194
169
  filename: curPath,
195
170
  output: jscFile,
196
171
  electron: true
197
- });
172
+ }, this.bOpt);
173
+
174
+ bytenode.compileFile(opt);
198
175
 
199
176
  //fs.writeFileSync(curPath, 'require("bytenode");module.exports = require("./'+path.basename(jscFile)+'");', 'utf8');
200
177
 
@@ -36,9 +36,7 @@ const fsPro = require('fs-extra');
36
36
  };
37
37
 
38
38
  const sourceDir = path.join(homeDir, distDir);
39
- const targetDir = path.join(homeDir, 'app', 'public');
40
39
  const sourceIndexFile = path.join(sourceDir, 'index.html');
41
- const targetIndexFile = path.join(homeDir, 'app', 'view', 'index.ejs');
42
40
 
43
41
  if (!fileExist(sourceIndexFile)) {
44
42
  console.error('[ee-core] [replace_dist] ERROR 前端资源不存在,请构建!!!');
@@ -55,19 +53,6 @@ const fsPro = require('fs-extra');
55
53
  fsPro.copySync(sourceDir, eeResourceDir);
56
54
  console.log('[ee-core] [replace_dist] 复制资源到:', eeResourceDir);
57
55
 
58
- // 复制到egg资源目录
59
- if (fs.existsSync(targetDir)) {
60
- console.log('[ee-core] [replace_dist] 重置egg资源:', targetDir);
61
- fs.rmdirSync(targetDir, {recursive: true});
62
-
63
- console.log('[ee-core] [replace_dist] 复制资源到egg:', sourceDir);
64
- fsPro.copySync(sourceDir, targetDir);
65
-
66
- // replace ejs
67
- fsPro.copySync(sourceIndexFile, targetIndexFile);
68
- console.log('[ee-core] [replace_dist] 替换 egg index.ejs');
69
- }
70
-
71
56
  console.log('[ee-core] [replace_dist] 结束');
72
57
  }
73
58
  }
package/utils/index.js CHANGED
@@ -43,30 +43,36 @@ exports.getCoreDB = function() {
43
43
  }
44
44
 
45
45
  /**
46
- * 获取 ee配置
46
+ * 获取 当前环境
47
47
  */
48
- exports.getEeConfig = function() {
48
+ exports.getEnv = function() {
49
49
  const cdb = this.getCoreDB();
50
- const config = cdb.getItem('config');
50
+ const env = cdb.getItem('config').env;
51
51
 
52
- return config;
52
+ return env;
53
53
  }
54
54
 
55
55
  /**
56
- * 获取 egg配置
56
+ * 获取 ee配置
57
57
  */
58
- exports.getEggConfig = function() {
58
+ exports.getEeConfig = function() {
59
59
  const cdb = this.getCoreDB();
60
60
  const config = cdb.getItem('config');
61
61
 
62
- return config.egg;
62
+ return config;
63
63
  }
64
64
 
65
65
  /**
66
66
  * 获取 数据库存储路径
67
67
  */
68
68
  exports.getStorageDir = function() {
69
- return utilsCommon.getStorageDir();
69
+ const cdb = this.getCoreDB();
70
+ const env = cdb.getItem('config').env;
71
+
72
+ const appDir = env === 'local' || env === 'unittest' ? this.getHomeDir() : this.getAppUserDataDir();
73
+ const storageDir = path.join(appDir, 'data');
74
+
75
+ return storageDir;
70
76
  }
71
77
 
72
78
  /**
@@ -89,6 +95,96 @@ exports.getLogDir = function() {
89
95
  return logPath;
90
96
  }
91
97
 
98
+ /**
99
+ * 获取 home目录
100
+ */
101
+ exports.getHomeDir = function() {
102
+ const cdb = this.getCoreDB();
103
+ const homePath = cdb.getItem('config').homeDir;
104
+ return homePath;
105
+ }
106
+
107
+ /**
108
+ * 获取 base目录
109
+ */
110
+ exports.getBaseDir = function() {
111
+ const cdb = this.getCoreDB();
112
+ const basePath = cdb.getItem('config').baseDir;
113
+ return basePath;
114
+ }
115
+
116
+ /**
117
+ * 获取 root目录
118
+ */
119
+ exports.getRootDir = function() {
120
+ const cdb = this.getCoreDB();
121
+ const rootPath = cdb.getItem('config').root;
122
+ return rootPath;
123
+ }
124
+
125
+ /**
126
+ * 获取 appUserData目录
127
+ */
128
+ exports.getAppUserDataDir = function() {
129
+ const cdb = this.getCoreDB();
130
+ const dataPath = cdb.getItem('config').appUserDataDir;
131
+ return dataPath;
132
+ }
133
+
134
+ /**
135
+ * 获取 app version
136
+ */
137
+ exports.getAppVersion = function() {
138
+ const cdb = this.getCoreDB();
139
+ const v = cdb.getItem('config').appVersion;
140
+ return v;
141
+ }
142
+
143
+ /**
144
+ * 获取 exec目录
145
+ */
146
+ exports.getExecDir = function() {
147
+ const cdb = this.getCoreDB();
148
+ const execPath = cdb.getItem('config').execDir;
149
+ return execPath;
150
+ }
151
+
152
+ /**
153
+ * 获取 插件配置
154
+ */
155
+ exports.getAddonConfig = function() {
156
+ const cdb = this.getCoreDB();
157
+ const cfg = cdb.getItem('config').addons;
158
+ return cfg;
159
+ }
160
+
161
+ /**
162
+ * 获取 mainServer配置
163
+ */
164
+ exports.getMainServerConfig = function() {
165
+ const cdb = this.getCoreDB();
166
+ const cfg = cdb.getItem('config').mainServer;
167
+ return cfg;
168
+ }
169
+
170
+ /**
171
+ * 获取 httpServer配置
172
+ */
173
+ exports.getHttpServerConfig = function() {
174
+ const cdb = this.getCoreDB();
175
+ const cfg = cdb.getItem('config').httpServer;
176
+ return cfg;
177
+ }
178
+
179
+ /**
180
+ * 获取 socketServer配置
181
+ */
182
+ exports.getSocketServerConfig = function() {
183
+ const cdb = this.getCoreDB();
184
+ const cfg = cdb.getItem('config').socketServer;
185
+ return cfg;
186
+ }
187
+
92
188
  /**
93
189
  * 获取 socketio port
94
190
  */
package/lib/helper.js DELETED
@@ -1,52 +0,0 @@
1
- 'use strict';
2
-
3
- const is = require('electron-is');
4
- const { app } = require('electron');
5
-
6
- /**
7
- * application quit
8
- *
9
- * @return {undefined}
10
- */
11
- exports.appQuit = function () {
12
- MAIN_WINDOW.destroy();
13
- app.quit();
14
- }
15
-
16
- /**
17
- * get Platform
18
- *
19
- * @return {Object}
20
- */
21
- exports.getPlatform = function () {
22
- let platform = null;
23
- let arch = null;
24
- if (is.windows()) {
25
- platform = 'windows';
26
- } else if (is.macOS()) {
27
- platform = 'macOS';
28
- } else if (is.linux()) {
29
- platform = 'linux';
30
- } else {
31
- platform = 'other';
32
- }
33
-
34
- if (is.x86()) {
35
- arch = '32';
36
- } else if (is.x64()) {
37
- arch = '64';
38
- } else if (process.arch == 'arm') {
39
- arch = 'arm32';
40
- } else if (process.arch == 'arm64') {
41
- arch = 'arm64';
42
- } else {
43
- arch = 'other';
44
- }
45
-
46
- const platfromObj = {
47
- platform: platform,
48
- arch: arch
49
- };
50
-
51
- return platfromObj;
52
- }