ee-core 2.0.0-beta.1 → 2.0.0-beta.3

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.
@@ -7,7 +7,7 @@ class FileSync extends Base {
7
7
  if (fs.existsSync(this.source)) {
8
8
  // Read database
9
9
  try {
10
- const data = fs.readFileSync(this.source, {encoding: 'utf8'})
10
+ const data = fs.readFileSync(this.source, {encoding: 'utf8'}).trim()
11
11
 
12
12
  // Handle blank file
13
13
  return data ? this.deserialize(data) : this.defaultValue
@@ -19,13 +19,13 @@ class FileSync extends Base {
19
19
  }
20
20
  } else {
21
21
  // Initialize
22
- fs.writeFileSync(this.source, this.serialize(this.defaultValue))
22
+ fs.writeFileSync(this.source, this.serialize(this.defaultValue), {flag:'w+'})
23
23
  return this.defaultValue
24
24
  }
25
25
  }
26
26
 
27
27
  write(data) {
28
- return fs.writeFileSync(this.source, this.serialize(data))
28
+ return fs.writeFileSync(this.source, this.serialize(data), {flag:'w+'})
29
29
  }
30
30
  }
31
31
 
@@ -20,7 +20,6 @@ class JsondbStorage {
20
20
  const storageDir = Ps.getStorageDir();
21
21
  if (!fs.existsSync(storageDir)) {
22
22
  Helper.mkdir(storageDir);
23
- Helper.chmodPath(storageDir, '777');
24
23
  }
25
24
 
26
25
  this.db = this.table(name);
@@ -49,8 +49,8 @@ exports.getRandomString = function() {
49
49
  /**
50
50
  * 创建文件夹
51
51
  */
52
- exports.mkdir = function(filepath) {
53
- mkdirp.sync(path.dirname(filepath));
52
+ exports.mkdir = function(filepath, opt = {}) {
53
+ mkdirp.sync(filepath, opt);
54
54
  return
55
55
  }
56
56
 
@@ -1,24 +1,14 @@
1
1
  const path = require('path');
2
- const eis = require('electron-is');
3
2
  const Storage = require('../storage');
4
3
  const Constants = require('../const');
5
4
  const Ps = require('./ps');
6
- const Helper = require('./helper');
7
5
  const UtilsJson = require('./json');
8
- const Copy = require('./copyto');
9
-
10
- /**
11
- * other module
12
- */
13
- Copy(Ps)
14
- .and(Helper)
15
- .to(exports);
16
6
 
17
7
  /**
18
8
  * 获取项目根目录package.json
19
9
  */
20
10
  exports.getPackage = function() {
21
- const json = UtilsJson.readSync(path.join(this.getHomeDir(), 'package.json'));
11
+ const json = UtilsJson.readSync(path.join(Ps.getHomeDir(), 'package.json'));
22
12
 
23
13
  return json;
24
14
  };
@@ -93,28 +83,4 @@ exports.getSocketChannel = function() {
93
83
  return Constants.socketIo.channel;
94
84
  }
95
85
 
96
- /**
97
- * 获取 额外资源目录
98
- */
99
- exports.getExtraResourcesDir = function() {
100
- const execDir = this.getExecDir();
101
- const isPackaged = this.isPackaged();
102
-
103
-
104
- // 资源路径不同
105
- let dir = '';
106
- if (isPackaged) {
107
- // 打包后 execDir为 应用程序 exe\dmg\dep软件所在目录;打包前该值是项目根目录
108
- // windows和MacOs不一样
109
- dir = path.join(execDir, "resources", "extraResources");
110
- if (eis.macOS()) {
111
- dir = path.join(execDir, "..", "Resources", "extraResources");
112
- }
113
- } else {
114
- // 打包前
115
- dir = path.join(execDir, "build", "extraResources");
116
- }
117
- return dir;
118
- }
119
-
120
86
 
@@ -1,4 +1,5 @@
1
1
  const path = require('path');
2
+ const eis = require('electron-is');
2
3
 
3
4
  /**
4
5
  * 当前进程的所有env
@@ -112,12 +113,43 @@ exports.getRootDir = function () {
112
113
  }
113
114
 
114
115
  /**
115
- * 获取 base目录
116
+ * 获取base目录
116
117
  */
117
118
  exports.getBaseDir = function() {
118
119
  return process.env.EE_BASE_DIR;
119
120
  }
120
121
 
122
+ /**
123
+ * 获取electron目录
124
+ */
125
+ exports.getElectronDir = function() {
126
+ return process.env.EE_BASE_DIR;
127
+ }
128
+
129
+ /**
130
+ * 获取 额外资源目录
131
+ */
132
+ exports.getExtraResourcesDir = function() {
133
+ const execDir = this.getExecDir();
134
+ const isPackaged = this.isPackaged();
135
+
136
+
137
+ // 资源路径不同
138
+ let dir = '';
139
+ if (isPackaged) {
140
+ // 打包后 execDir为 应用程序 exe\dmg\dep软件所在目录;打包前该值是项目根目录
141
+ // windows和MacOs不一样
142
+ dir = path.join(execDir, "resources", "extraResources");
143
+ if (eis.macOS()) {
144
+ dir = path.join(execDir, "..", "Resources", "extraResources");
145
+ }
146
+ } else {
147
+ // 打包前
148
+ dir = path.join(execDir, "build", "extraResources");
149
+ }
150
+ return dir;
151
+ }
152
+
121
153
  /**
122
154
  * 获取 appUserData目录
123
155
  */
@@ -171,5 +203,19 @@ exports.getHttpPort = function () {
171
203
  * 是否打包
172
204
  */
173
205
  exports.isPackaged = function () {
174
- return process.env.EE_IS_PACKAGED;
206
+ return process.env.EE_IS_PACKAGED === 'true';
207
+ }
208
+
209
+ /**
210
+ * 是否加密
211
+ */
212
+ exports.isEncrypted = function () {
213
+ return process.env.EE_IS_ENCRYPTED === 'true';
214
+ }
215
+
216
+ /**
217
+ * 是否热重启
218
+ */
219
+ exports.isHotReload = function () {
220
+ return process.env.HOT_RELOAD === 'true';
175
221
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ee-core",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.0-beta.3",
4
4
  "description": "ee core",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/tools/encrypt.js CHANGED
@@ -7,7 +7,7 @@ const is = require('is-type-of');
7
7
  const bytenode = require('bytenode');
8
8
  const crypto = require('crypto');
9
9
  const JavaScriptObfuscator = require('javascript-obfuscator');
10
- const utilsJson = require('../module/utils/json');
10
+ const UtilsJson = require('../module/utils/json');
11
11
 
12
12
  class Encrypt {
13
13
  constructor() {
@@ -41,20 +41,20 @@ class Encrypt {
41
41
  this.dirs.push(directory[i]);
42
42
  }
43
43
  }
44
- console.log('[ee-core] [encrypt] dirs:', this.dirs);
44
+ console.log('[ee-core] [tools/encrypt] dirs:', this.dirs);
45
45
  }
46
46
 
47
47
  /**
48
48
  * 备份 electron 目录代码
49
49
  */
50
50
  backup () {
51
- console.log('[ee-core] [encrypt] backup start');
51
+ console.log('[ee-core] [tools/encrypt] backup start');
52
52
 
53
53
  for (let i = 0; i < this.dirs.length; i++) {
54
54
  // check code dir
55
55
  let codeDirPath = path.join(this.basePath, this.dirs[i]);
56
56
  if (!fs.existsSync(codeDirPath)) {
57
- console.log('[ee-core] [encrypt] ERROR: backup %s is not exist', codeDirPath);
57
+ console.log('[ee-core] [tools/encrypt] ERROR: backup %s is not exist', codeDirPath);
58
58
  return
59
59
  }
60
60
 
@@ -64,7 +64,7 @@ class Encrypt {
64
64
  this.rmBackup(targetDir);
65
65
 
66
66
  // copy
67
- console.log('[ee-core] [encrypt] backup target Dir:', targetDir);
67
+ console.log('[ee-core] [tools/encrypt] backup target Dir:', targetDir);
68
68
  if (!fs.existsSync(targetDir)) {
69
69
  this.mkdir(targetDir);
70
70
  this.chmodPath(targetDir, '777');
@@ -72,7 +72,7 @@ class Encrypt {
72
72
 
73
73
  fsPro.copySync(codeDirPath, targetDir);
74
74
  }
75
- console.log('[ee-core] [encrypt] backup end');
75
+ console.log('[ee-core] [tools/encrypt] backup end');
76
76
  return true;
77
77
  }
78
78
 
@@ -86,7 +86,7 @@ class Encrypt {
86
86
  const content = {
87
87
  nameMap: {}
88
88
  };
89
- utilsJson.writeSync(this.tmpFile, content);
89
+ UtilsJson.writeSync(this.tmpFile, content);
90
90
  }
91
91
  }
92
92
 
@@ -97,13 +97,13 @@ class Encrypt {
97
97
  * 加密代码
98
98
  */
99
99
  encrypt () {
100
- console.log('[ee-core] [encrypt] start ciphering');
100
+ console.log('[ee-core] [tools/encrypt] start ciphering');
101
101
  for (let i = 0; i < this.dirs.length; i++) {
102
102
  let codeDirPath = path.join(this.encryptCodeDir, this.dirs[i]);
103
103
  this.loop(codeDirPath);
104
104
  }
105
105
 
106
- console.log('[ee-core] [encrypt] end ciphering');
106
+ console.log('[ee-core] [tools/encrypt] end ciphering');
107
107
  };
108
108
 
109
109
  /**
@@ -183,7 +183,7 @@ class Encrypt {
183
183
  */
184
184
  rmBackup (dir) {
185
185
  if (fs.existsSync(dir)) {
186
- console.log('[ee-core] [encrypt] clean old directory:', dir);
186
+ console.log('[ee-core] [tools/encrypt] clean old directory:', dir);
187
187
  fsPro.removeSync(dir);
188
188
  }
189
189
  return;
@@ -14,7 +14,7 @@ const fsPro = require('fs-extra');
14
14
  * 执行
15
15
  */
16
16
  run () {
17
- console.log('[ee-core] [replace_dist] 开始移动资源');
17
+ console.log('[ee-core] [tools/rd] 开始移动资源');
18
18
  const homeDir = process.cwd();
19
19
 
20
20
  // argv
@@ -30,7 +30,7 @@ const fsPro = require('fs-extra');
30
30
  try {
31
31
  return fs.statSync(filePath).isFile();
32
32
  } catch (err) {
33
- console.error('[ee-core] [replace_dist] ERROR ', err);
33
+ console.error('[ee-core] [tools/rd] ERROR ', err);
34
34
  return false;
35
35
  }
36
36
  };
@@ -39,7 +39,7 @@ const fsPro = require('fs-extra');
39
39
  const sourceIndexFile = path.join(sourceDir, 'index.html');
40
40
 
41
41
  if (!fileExist(sourceIndexFile)) {
42
- console.error('[ee-core] [replace_dist] ERROR 前端资源不存在,请构建!!!');
42
+ console.error('[ee-core] [tools/rd] ERROR 前端资源不存在,请构建!!!');
43
43
  return
44
44
  }
45
45
 
@@ -48,12 +48,12 @@ const fsPro = require('fs-extra');
48
48
 
49
49
  // 清空历史资源
50
50
  fs.rmdirSync(eeResourceDir, {recursive: true});
51
- console.log('[ee-core] [replace_dist] 清空历史资源:', eeResourceDir);
51
+ console.log('[ee-core] [tools/rd] 清空历史资源:', eeResourceDir);
52
52
 
53
53
  fsPro.copySync(sourceDir, eeResourceDir);
54
- console.log('[ee-core] [replace_dist] 复制资源到:', eeResourceDir);
54
+ console.log('[ee-core] [tools/rd] 复制资源到:', eeResourceDir);
55
55
 
56
- console.log('[ee-core] [replace_dist] 结束');
56
+ console.log('[ee-core] [tools/rd] 结束');
57
57
  }
58
58
  }
59
59
 
package/utils/index.js CHANGED
@@ -3,7 +3,6 @@
3
3
  */
4
4
 
5
5
  const path = require('path');
6
- const eis = require('electron-is');
7
6
  const UtilsJson = require('../module/utils/json');
8
7
  const UtilsPs = require('../module/utils/ps');
9
8
  const UtilsHelper = require('../module/utils/helper');
@@ -105,25 +104,3 @@ exports.getSocketPort = function() {
105
104
  exports.getSocketChannel = function() {
106
105
  return Constants.socketIo.channel;
107
106
  }
108
-
109
- /**
110
- * 获取 额外资源目录
111
- */
112
- exports.getExtraResourcesDir = function() {
113
- const execDir = this.getExecDir();
114
-
115
- // 资源路径不同
116
- let dir = '';
117
- if (config.isPackaged) {
118
- // 打包后 execDir为 应用程序 exe\dmg\dep软件所在目录;打包前该值是项目根目录
119
- // windows和MacOs不一样
120
- dir = path.join(execDir, "resources", "extraResources");
121
- if (eis.macOS()) {
122
- dir = path.join(execDir, "..", "Resources", "extraResources");
123
- }
124
- } else {
125
- // 打包前
126
- dir = path.join(execDir, "build", "extraResources");
127
- }
128
- return dir;
129
- }