ee-bin 4.1.8 → 4.1.10
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/config/bin_default.js +181 -181
- package/index.js +120 -120
- package/lib/extend.js +77 -77
- package/lib/pargv.js +263 -263
- package/lib/utils.js +255 -224
- package/package.json +32 -32
- package/tools/encrypt.js +178 -178
- package/tools/iconGen.js +182 -182
- package/tools/incrUpdater.js +195 -176
- package/tools/move.js +68 -68
- package/tools/serve.js +346 -345
package/tools/iconGen.js
CHANGED
|
@@ -1,183 +1,183 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const icongen = require("icon-gen");
|
|
6
|
-
|
|
7
|
-
class IconGen {
|
|
8
|
-
constructor() {
|
|
9
|
-
this._init();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* _init
|
|
14
|
-
*/
|
|
15
|
-
_init() {
|
|
16
|
-
// ---> 处理参数
|
|
17
|
-
const args = process.argv.splice(3);
|
|
18
|
-
let params = {
|
|
19
|
-
input: "/public/images/logo.png",
|
|
20
|
-
output: "/build/icons/",
|
|
21
|
-
size: "16,32,64,256,512",
|
|
22
|
-
clear: false,
|
|
23
|
-
imagesDir: "/public/images/",
|
|
24
|
-
};
|
|
25
|
-
try {
|
|
26
|
-
const len = args.length;
|
|
27
|
-
for (let i = 0; i < len; i++) {
|
|
28
|
-
const arg = args[i];
|
|
29
|
-
if (arg.match(/^-i/) || arg.match(/^-input/)) {
|
|
30
|
-
params["input"] = args[i + 1];
|
|
31
|
-
i++;
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
if (arg.match(/^-o/) || arg.match(/^-output/)) {
|
|
35
|
-
params["output"] = args[i + 1];
|
|
36
|
-
i++;
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
if (arg.match(/^-s/) || arg.match(/^-size/)) {
|
|
40
|
-
params["size"] = args[i + 1];
|
|
41
|
-
i++;
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
if (arg.match(/^-c/) || arg.match(/^-clear/)) {
|
|
45
|
-
params["clear"] = true;
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
if (arg.match(/^-img/) || arg.match(/^-images/)) {
|
|
49
|
-
params["imagesDir"] = args[i + 1];
|
|
50
|
-
i++;
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
} catch (e) {
|
|
55
|
-
console.error("[ee-bin] [icon-gen] args: ", args);
|
|
56
|
-
console.error("[ee-bin] [icon-gen] ERROR: ", e);
|
|
57
|
-
throw new Error("参数错误!!");
|
|
58
|
-
}
|
|
59
|
-
this.params = params;
|
|
60
|
-
|
|
61
|
-
// ---> 组装参数
|
|
62
|
-
console.log("[ee-bin] [icon-gen] icon 当前路径: ", process.cwd());
|
|
63
|
-
this.input = path.join(process.cwd(), params.input);
|
|
64
|
-
this.output = path.join(process.cwd(), params.output);
|
|
65
|
-
this.imagesDir = path.join(process.cwd(), params.imagesDir);
|
|
66
|
-
|
|
67
|
-
const sizeList = params.size.split(",").map((item) => parseInt(item));
|
|
68
|
-
this.iconOptions = {
|
|
69
|
-
report: false,
|
|
70
|
-
ico: {
|
|
71
|
-
name: "icon",
|
|
72
|
-
sizes: [256],
|
|
73
|
-
},
|
|
74
|
-
favicon: {
|
|
75
|
-
name: "logo-",
|
|
76
|
-
pngSizes: sizeList,
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 生成图标
|
|
83
|
-
*/
|
|
84
|
-
generateIcons() {
|
|
85
|
-
console.log("[ee-bin] [icon-gen] iconGen 开始处理生成logo图片");
|
|
86
|
-
if (!fs.existsSync(this.input)) {
|
|
87
|
-
console.error("[ee-bin] [icon-gen] input: ", this.input);
|
|
88
|
-
throw new Error("输入的图片不存在或路径错误");
|
|
89
|
-
}
|
|
90
|
-
if (!fs.existsSync(this.output)) {
|
|
91
|
-
fs.mkdirSync(this.output, { recursive: true });
|
|
92
|
-
} else {
|
|
93
|
-
// 清空目录
|
|
94
|
-
this.params.clear && this.deleteGenFile(this.output);
|
|
95
|
-
}
|
|
96
|
-
if (!fs.existsSync(this.imagesDir)) {
|
|
97
|
-
fs.mkdirSync(this.imagesDir, { recursive: true });
|
|
98
|
-
}
|
|
99
|
-
icongen(this.input, this.output, this.iconOptions)
|
|
100
|
-
.then((results) => {
|
|
101
|
-
console.log("[ee-bin] [icon-gen] iconGen 已生成下方图片资源");
|
|
102
|
-
console.log(results);
|
|
103
|
-
this._renameForEE(results);
|
|
104
|
-
})
|
|
105
|
-
.catch((err) => {
|
|
106
|
-
console.error(err);
|
|
107
|
-
throw new Error("[ee-bin] [icon-gen] iconGen 生成失败!");
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* 删除生成的文件(.ico .png)
|
|
113
|
-
*/
|
|
114
|
-
deleteGenFile(dirPath) {
|
|
115
|
-
if (fs.existsSync(dirPath)) {
|
|
116
|
-
// 读取文件夹下的文件目录
|
|
117
|
-
const files = fs.readdirSync(dirPath);
|
|
118
|
-
files.forEach((file) => {
|
|
119
|
-
const curPath = path.join(dirPath, file);
|
|
120
|
-
// 判断是不是文件夹,如果是,继续递归
|
|
121
|
-
if (fs.lstatSync(curPath).isDirectory()) {
|
|
122
|
-
this.deleteGenFile(curPath);
|
|
123
|
-
} else {
|
|
124
|
-
// 删除文件
|
|
125
|
-
if ([".ico", ".png"].includes(path.extname(curPath))) {
|
|
126
|
-
fs.unlinkSync(curPath);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* 为生成的资源重命名 (logo-32.png -> 32x32.png)
|
|
135
|
-
*/
|
|
136
|
-
_renameForEE(filesPath) {
|
|
137
|
-
console.log("[ee-bin] [icon-gen] iconGen 开始重新命名logo图片资源");
|
|
138
|
-
try {
|
|
139
|
-
const len = filesPath.length;
|
|
140
|
-
for (let i = 0; i < len; i++) {
|
|
141
|
-
const filePath = filesPath[i];
|
|
142
|
-
const extname = path.extname(filePath);
|
|
143
|
-
if ([".png"].includes(extname)) {
|
|
144
|
-
const filename = path.basename(filePath, extname);
|
|
145
|
-
const basename = filename.split("-")[1];
|
|
146
|
-
const dirname = path.dirname(filePath);
|
|
147
|
-
// 处理 tray 图标 --> 复制到 public/images 目录下
|
|
148
|
-
if ("16" === basename) {
|
|
149
|
-
const newName = "tray" + extname;
|
|
150
|
-
fs.copyFileSync(filePath, path.join(this.imagesDir, newName));
|
|
151
|
-
console.log(`${filename}${extname} --> ${this.params.imagesDir}/${newName} 复制成功!`);
|
|
152
|
-
fs.unlinkSync(filePath);
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
// 处理 win 窗口图标 --> 复制到 public/images 目录下
|
|
156
|
-
if ("32" === basename) {
|
|
157
|
-
const newName = filename + extname;
|
|
158
|
-
fs.copyFileSync(filePath, path.join(this.imagesDir, newName));
|
|
159
|
-
console.log(`${filename}${extname} --> ${this.params.imagesDir}/${newName} 复制成功!`);
|
|
160
|
-
}
|
|
161
|
-
// 重命名 --> 32x32.png
|
|
162
|
-
const newName = basename + "x" + basename + extname;
|
|
163
|
-
const newPath = path.join(dirname, newName);
|
|
164
|
-
fs.renameSync(filePath, newPath);
|
|
165
|
-
console.log(`${filename}${extname} --> ${newName} 重命名成功!`);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
console.log("[ee-bin] [icon-gen] iconGen 资源处理完成!");
|
|
169
|
-
} catch (e) {
|
|
170
|
-
console.error("[ee-bin] [icon-gen] ERROR: ", e);
|
|
171
|
-
throw new Error("重命名logo图片资源失败!!");
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const run = () => {
|
|
177
|
-
const i = new IconGen();
|
|
178
|
-
i.generateIcons();
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
module.exports = {
|
|
182
|
-
run,
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const icongen = require("icon-gen");
|
|
6
|
+
|
|
7
|
+
class IconGen {
|
|
8
|
+
constructor() {
|
|
9
|
+
this._init();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* _init
|
|
14
|
+
*/
|
|
15
|
+
_init() {
|
|
16
|
+
// ---> 处理参数
|
|
17
|
+
const args = process.argv.splice(3);
|
|
18
|
+
let params = {
|
|
19
|
+
input: "/public/images/logo.png",
|
|
20
|
+
output: "/build/icons/",
|
|
21
|
+
size: "16,32,64,256,512",
|
|
22
|
+
clear: false,
|
|
23
|
+
imagesDir: "/public/images/",
|
|
24
|
+
};
|
|
25
|
+
try {
|
|
26
|
+
const len = args.length;
|
|
27
|
+
for (let i = 0; i < len; i++) {
|
|
28
|
+
const arg = args[i];
|
|
29
|
+
if (arg.match(/^-i/) || arg.match(/^-input/)) {
|
|
30
|
+
params["input"] = args[i + 1];
|
|
31
|
+
i++;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (arg.match(/^-o/) || arg.match(/^-output/)) {
|
|
35
|
+
params["output"] = args[i + 1];
|
|
36
|
+
i++;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (arg.match(/^-s/) || arg.match(/^-size/)) {
|
|
40
|
+
params["size"] = args[i + 1];
|
|
41
|
+
i++;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (arg.match(/^-c/) || arg.match(/^-clear/)) {
|
|
45
|
+
params["clear"] = true;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (arg.match(/^-img/) || arg.match(/^-images/)) {
|
|
49
|
+
params["imagesDir"] = args[i + 1];
|
|
50
|
+
i++;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
} catch (e) {
|
|
55
|
+
console.error("[ee-bin] [icon-gen] args: ", args);
|
|
56
|
+
console.error("[ee-bin] [icon-gen] ERROR: ", e);
|
|
57
|
+
throw new Error("参数错误!!");
|
|
58
|
+
}
|
|
59
|
+
this.params = params;
|
|
60
|
+
|
|
61
|
+
// ---> 组装参数
|
|
62
|
+
console.log("[ee-bin] [icon-gen] icon 当前路径: ", process.cwd());
|
|
63
|
+
this.input = path.join(process.cwd(), params.input);
|
|
64
|
+
this.output = path.join(process.cwd(), params.output);
|
|
65
|
+
this.imagesDir = path.join(process.cwd(), params.imagesDir);
|
|
66
|
+
|
|
67
|
+
const sizeList = params.size.split(",").map((item) => parseInt(item));
|
|
68
|
+
this.iconOptions = {
|
|
69
|
+
report: false,
|
|
70
|
+
ico: {
|
|
71
|
+
name: "icon",
|
|
72
|
+
sizes: [256],
|
|
73
|
+
},
|
|
74
|
+
favicon: {
|
|
75
|
+
name: "logo-",
|
|
76
|
+
pngSizes: sizeList,
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 生成图标
|
|
83
|
+
*/
|
|
84
|
+
generateIcons() {
|
|
85
|
+
console.log("[ee-bin] [icon-gen] iconGen 开始处理生成logo图片");
|
|
86
|
+
if (!fs.existsSync(this.input)) {
|
|
87
|
+
console.error("[ee-bin] [icon-gen] input: ", this.input);
|
|
88
|
+
throw new Error("输入的图片不存在或路径错误");
|
|
89
|
+
}
|
|
90
|
+
if (!fs.existsSync(this.output)) {
|
|
91
|
+
fs.mkdirSync(this.output, { recursive: true });
|
|
92
|
+
} else {
|
|
93
|
+
// 清空目录
|
|
94
|
+
this.params.clear && this.deleteGenFile(this.output);
|
|
95
|
+
}
|
|
96
|
+
if (!fs.existsSync(this.imagesDir)) {
|
|
97
|
+
fs.mkdirSync(this.imagesDir, { recursive: true });
|
|
98
|
+
}
|
|
99
|
+
icongen(this.input, this.output, this.iconOptions)
|
|
100
|
+
.then((results) => {
|
|
101
|
+
console.log("[ee-bin] [icon-gen] iconGen 已生成下方图片资源");
|
|
102
|
+
console.log(results);
|
|
103
|
+
this._renameForEE(results);
|
|
104
|
+
})
|
|
105
|
+
.catch((err) => {
|
|
106
|
+
console.error(err);
|
|
107
|
+
throw new Error("[ee-bin] [icon-gen] iconGen 生成失败!");
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 删除生成的文件(.ico .png)
|
|
113
|
+
*/
|
|
114
|
+
deleteGenFile(dirPath) {
|
|
115
|
+
if (fs.existsSync(dirPath)) {
|
|
116
|
+
// 读取文件夹下的文件目录
|
|
117
|
+
const files = fs.readdirSync(dirPath);
|
|
118
|
+
files.forEach((file) => {
|
|
119
|
+
const curPath = path.join(dirPath, file);
|
|
120
|
+
// 判断是不是文件夹,如果是,继续递归
|
|
121
|
+
if (fs.lstatSync(curPath).isDirectory()) {
|
|
122
|
+
this.deleteGenFile(curPath);
|
|
123
|
+
} else {
|
|
124
|
+
// 删除文件
|
|
125
|
+
if ([".ico", ".png"].includes(path.extname(curPath))) {
|
|
126
|
+
fs.unlinkSync(curPath);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* 为生成的资源重命名 (logo-32.png -> 32x32.png)
|
|
135
|
+
*/
|
|
136
|
+
_renameForEE(filesPath) {
|
|
137
|
+
console.log("[ee-bin] [icon-gen] iconGen 开始重新命名logo图片资源");
|
|
138
|
+
try {
|
|
139
|
+
const len = filesPath.length;
|
|
140
|
+
for (let i = 0; i < len; i++) {
|
|
141
|
+
const filePath = filesPath[i];
|
|
142
|
+
const extname = path.extname(filePath);
|
|
143
|
+
if ([".png"].includes(extname)) {
|
|
144
|
+
const filename = path.basename(filePath, extname);
|
|
145
|
+
const basename = filename.split("-")[1];
|
|
146
|
+
const dirname = path.dirname(filePath);
|
|
147
|
+
// 处理 tray 图标 --> 复制到 public/images 目录下
|
|
148
|
+
if ("16" === basename) {
|
|
149
|
+
const newName = "tray" + extname;
|
|
150
|
+
fs.copyFileSync(filePath, path.join(this.imagesDir, newName));
|
|
151
|
+
console.log(`${filename}${extname} --> ${this.params.imagesDir}/${newName} 复制成功!`);
|
|
152
|
+
fs.unlinkSync(filePath);
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
// 处理 win 窗口图标 --> 复制到 public/images 目录下
|
|
156
|
+
if ("32" === basename) {
|
|
157
|
+
const newName = filename + extname;
|
|
158
|
+
fs.copyFileSync(filePath, path.join(this.imagesDir, newName));
|
|
159
|
+
console.log(`${filename}${extname} --> ${this.params.imagesDir}/${newName} 复制成功!`);
|
|
160
|
+
}
|
|
161
|
+
// 重命名 --> 32x32.png
|
|
162
|
+
const newName = basename + "x" + basename + extname;
|
|
163
|
+
const newPath = path.join(dirname, newName);
|
|
164
|
+
fs.renameSync(filePath, newPath);
|
|
165
|
+
console.log(`${filename}${extname} --> ${newName} 重命名成功!`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
console.log("[ee-bin] [icon-gen] iconGen 资源处理完成!");
|
|
169
|
+
} catch (e) {
|
|
170
|
+
console.error("[ee-bin] [icon-gen] ERROR: ", e);
|
|
171
|
+
throw new Error("重命名logo图片资源失败!!");
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const run = () => {
|
|
177
|
+
const i = new IconGen();
|
|
178
|
+
i.generateIcons();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
module.exports = {
|
|
182
|
+
run,
|
|
183
183
|
};
|