ee-core 2.2.3 → 2.3.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/bin/tools.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  const replaceDist = require('../tools/replaceDist');
4
4
  const encrypt = require('../tools/encrypt');
5
+ const iconGen = require('../tools/iconGen');
5
6
 
6
7
  // argv
7
8
  const args = process.argv;
@@ -20,3 +21,7 @@ if (cmd == 'encrypt') {
20
21
  if (cmd == 'clean') {
21
22
  encrypt.clean();
22
23
  }
24
+
25
+ if (cmd == 'icon') {
26
+ iconGen.run();
27
+ }
package/ee/eeApp.js CHANGED
@@ -128,7 +128,7 @@ class EeApp extends BaseApp {
128
128
  const mainServer = this.config.mainServer;
129
129
  if (Conf.isFileProtocol(mainServer)) {
130
130
  url = path.join(this.config.homeDir, mainServer.indexPath);
131
- this.loadMainUrl('spa', url);
131
+ this.loadMainUrl('spa', url, 'file');
132
132
  } else {
133
133
  this.loadLocalWeb('spa');
134
134
  }
@@ -138,7 +138,6 @@ class EeApp extends BaseApp {
138
138
  * 加载本地前端资源
139
139
  */
140
140
  loadLocalWeb(mode, staticDir, hostInfo) {
141
- const self = this;
142
141
  if (!staticDir) {
143
142
  staticDir = path.join(this.config.homeDir, 'public', 'dist')
144
143
  }
@@ -168,27 +167,36 @@ class EeApp extends BaseApp {
168
167
  Log.coreLogger.info('[ee-core] [lib/eeApp] createServer error: ', err);
169
168
  return
170
169
  }
171
- self.loadMainUrl(mode, url);
170
+ this.loadMainUrl(mode, url);
172
171
  });
173
172
  } else {
174
173
  koaApp.listen(mainServer.port, () => {
175
- self.loadMainUrl(mode, url);
174
+ this.loadMainUrl(mode, url);
176
175
  });
177
176
  }
178
177
  }
179
178
 
180
179
  /**
181
- * 主页面
180
+ * 主服务
181
+ * @params load <string> value: "url" 、 "file"
182
182
  */
183
- loadMainUrl(type, url) {
183
+ loadMainUrl(type, url, load = 'url') {
184
184
  const mainServer = this.config.mainServer;
185
185
  Log.coreLogger.info('[ee-core] Env: %s, Type: %s', this.config.env, type);
186
186
  Log.coreLogger.info('[ee-core] App running at: %s', url);
187
- this.mainWindow.loadURL(url, mainServer.options)
188
- .then()
189
- .catch((err)=>{
190
- Log.coreLogger.error(`[ee-core] Please check the ${url} are running OR modify config file !`);
191
- });
187
+ if (load == 'file') {
188
+ this.mainWindow.loadFile(url, mainServer.options)
189
+ .then()
190
+ .catch((err)=>{
191
+ Log.coreLogger.error(`[ee-core] Please check the ${url} !`);
192
+ });
193
+ } else {
194
+ this.mainWindow.loadURL(url, mainServer.options)
195
+ .then()
196
+ .catch((err)=>{
197
+ Log.coreLogger.error(`[ee-core] Please check the ${url} !`);
198
+ });
199
+ }
192
200
  }
193
201
 
194
202
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ee-core",
3
- "version": "2.2.3",
3
+ "version": "2.3.0-beta.1",
4
4
  "description": "ee core",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -20,6 +20,7 @@
20
20
  "egg-logger": "^2.7.1",
21
21
  "fs-extra": "^10.0.0",
22
22
  "globby": "^10.0.0",
23
+ "icon-gen": "^3.0.1",
23
24
  "is-type-of": "^1.2.1",
24
25
  "javascript-obfuscator": "^4.0.2",
25
26
  "koa": "^2.13.4",
@@ -34,6 +35,5 @@
34
35
  "socket.io": "^4.6.1",
35
36
  "socket.io-client": "^4.6.1",
36
37
  "urllib": "^2.38.0"
37
- },
38
- "devDependencies": {}
38
+ }
39
39
  }
@@ -0,0 +1,162 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const icongen = require("icon-gen");
4
+
5
+ // ---> 处理参数
6
+ const args = process.argv.splice(3);
7
+ let params = {
8
+ input: "/public/images/logo.png",
9
+ output: "/build/icons/",
10
+ size: "16,32,64,256,512",
11
+ clear: false,
12
+ imagesDir: "/public/images/",
13
+ };
14
+ try {
15
+ const len = args.length;
16
+ for (let i = 0; i < len; i++) {
17
+ const arg = args[i];
18
+ if (arg.match(/^-i/) || arg.match(/^-input/)) {
19
+ params["input"] = args[i + 1];
20
+ i++;
21
+ continue;
22
+ }
23
+ if (arg.match(/^-o/) || arg.match(/^-output/)) {
24
+ params["output"] = args[i + 1];
25
+ i++;
26
+ continue;
27
+ }
28
+ if (arg.match(/^-s/) || arg.match(/^-size/)) {
29
+ params["size"] = args[i + 1];
30
+ i++;
31
+ continue;
32
+ }
33
+ if (arg.match(/^-c/) || arg.match(/^-clear/)) {
34
+ params["clear"] = true;
35
+ continue;
36
+ }
37
+ if (arg.match(/^-img/) || arg.match(/^-images/)) {
38
+ params["imagesDir"] = args[i + 1];
39
+ i++;
40
+ continue;
41
+ }
42
+ }
43
+ } catch (e) {
44
+ console.error("[ee-core] [tools/iconGen] args: ", args);
45
+ console.error("[ee-core] [tools/iconGen] ERROR: ", e);
46
+ throw new Error("参数错误!!");
47
+ }
48
+
49
+ // ---> 组装参数
50
+ console.log("[ee-core] [tools/iconGen] icon 当前路径: ", process.cwd());
51
+ const input = path.join(process.cwd(), params.input);
52
+ const output = path.join(process.cwd(), params.output);
53
+ const imagesDir = path.join(process.cwd(), params.imagesDir);
54
+ const sizeList = params.size.split(",").map((item) => parseInt(item));
55
+ const iconOptions = {
56
+ report: false,
57
+ ico: {
58
+ name: "icon",
59
+ sizes: [256],
60
+ },
61
+ favicon: {
62
+ name: "logo-",
63
+ pngSizes: sizeList,
64
+ },
65
+ };
66
+
67
+ // 删除生成的文件(.ico .png)
68
+ const deleteGenFile = (dirPath) => {
69
+ if (fs.existsSync(dirPath)) {
70
+ // 读取文件夹下的文件目录
71
+ const files = fs.readdirSync(dirPath);
72
+ files.forEach((file) => {
73
+ const curPath = path.join(dirPath, file);
74
+ // 判断是不是文件夹,如果是,继续递归
75
+ if (fs.lstatSync(curPath).isDirectory()) {
76
+ deleteGenFile(curPath);
77
+ } else {
78
+ // 删除文件
79
+ if ([".ico", ".png"].includes(path.extname(curPath))) {
80
+ fs.unlinkSync(curPath);
81
+ }
82
+ }
83
+ });
84
+ }
85
+ };
86
+
87
+ // 为生成的资源重命名 (logo-32.png -> 32x32.png)
88
+ function renameForEE(filesPath) {
89
+ console.log("[ee-core] [tools/iconGen] iconGen 开始重新命名logo图片资源");
90
+ try {
91
+ const len = filesPath.length;
92
+ for (let i = 0; i < len; i++) {
93
+ const filePath = filesPath[i];
94
+ const extname = path.extname(filePath);
95
+ if ([".png"].includes(extname)) {
96
+ const filename = path.basename(filePath, extname);
97
+ const basename = filename.split("-")[1];
98
+ const dirname = path.dirname(filePath);
99
+ // 处理 tray 图标 --> 复制到 public/images 目录下
100
+ if ("16" === basename) {
101
+ const newName = "tray-logo" + extname;
102
+ fs.copyFileSync(filePath, path.join(imagesDir, newName));
103
+ console.log(`${filename}${extname} --> ${params.imagesDir}/${newName} 复制成功!`);
104
+ fs.unlinkSync(filePath);
105
+ continue;
106
+ }
107
+ // 处理 win 窗口图标 --> 复制到 public/images 目录下
108
+ if ("32" === basename) {
109
+ const newName = filename + extname;
110
+ fs.copyFileSync(filePath, path.join(imagesDir, newName));
111
+ console.log(`${filename}${extname} --> ${params.imagesDir}/${newName} 复制成功!`);
112
+ }
113
+ // 重命名 --> 32x32.png
114
+ const newName = basename + "x" + basename + extname;
115
+ const newPath = path.join(dirname, newName);
116
+ fs.renameSync(filePath, newPath);
117
+ console.log(`${filename}${extname} --> ${newName} 重命名成功!`);
118
+ }
119
+ }
120
+ console.log("[ee-core] [tools/iconGen] iconGen 资源处理完成!");
121
+ } catch (e) {
122
+ console.error("[ee-core] [tools/iconGen] ERROR: ", e);
123
+ throw new Error("重命名logo图片资源失败!!");
124
+ }
125
+ }
126
+
127
+ // ---> 生成图标
128
+ const generateIcons = () => {
129
+ console.log("[ee-core] [tools/iconGen] iconGen 开始处理生成logo图片");
130
+ if (!fs.existsSync(input)) {
131
+ console.error("[ee-core] [tools/iconGen] input: ", input);
132
+ throw new Error("输入的图片不存在或路径错误");
133
+ }
134
+ if (!fs.existsSync(output)) {
135
+ fs.mkdirSync(output, { recursive: true });
136
+ } else {
137
+ // 清空目录
138
+ params.clear && deleteGenFile(output);
139
+ }
140
+ if (!fs.existsSync(imagesDir)) {
141
+ fs.mkdirSync(imagesDir, { recursive: true });
142
+ }
143
+ icongen(input, output, iconOptions)
144
+ .then((results) => {
145
+ console.log("[ee-core] [tools/iconGen] iconGen 已生成下方图片资源");
146
+ console.log(results);
147
+ renameForEE(results);
148
+ })
149
+ .catch((err) => {
150
+ console.error(err);
151
+ throw new Error("[ee-core] [tools/iconGen] iconGen 生成失败!");
152
+ });
153
+ };
154
+
155
+ // ---> 执行
156
+ const run = () => {
157
+ generateIcons();
158
+ };
159
+
160
+ module.exports = {
161
+ run,
162
+ };