ee-bin 1.5.0 → 1.7.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/index.js +135 -120
- package/lib/pargv.js +263 -263
- package/lib/utils.js +174 -111
- package/package.json +28 -24
- package/tools/encrypt.js +315 -315
- package/tools/iconGen.js +182 -182
- package/tools/incrUpdater.js +133 -0
- package/tools/move.js +84 -84
- package/tools/replaceDist.js +82 -82
- package/tools/serve.js +167 -163
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
|
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const crypto = require('crypto')
|
|
6
|
+
const chalk = require('chalk');
|
|
7
|
+
const Utils = require('../lib/utils');
|
|
8
|
+
const admZip = require('adm-zip')
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 增量升级
|
|
12
|
+
* @class
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
module.exports = {
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 执行
|
|
19
|
+
*/
|
|
20
|
+
run(options = {}) {
|
|
21
|
+
console.log('[ee-bin] [updater] Start');
|
|
22
|
+
const { config, asarFile } = options;
|
|
23
|
+
const binCfg = Utils.loadConfig(config);
|
|
24
|
+
const cfg = binCfg.updater;
|
|
25
|
+
|
|
26
|
+
if (!cfg) {
|
|
27
|
+
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${cfg} config does not exist`));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.green('config:'), cfg);
|
|
31
|
+
|
|
32
|
+
this.generateFile(cfg, asarFile);
|
|
33
|
+
|
|
34
|
+
console.log('[ee-bin] [updater] End');
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
generateFile(cfg, asarFile) {
|
|
38
|
+
const latestVersionInfo = {}
|
|
39
|
+
const homeDir = process.cwd();
|
|
40
|
+
|
|
41
|
+
let asarFilePath = "";
|
|
42
|
+
if (asarFile) {
|
|
43
|
+
asarFilePath = path.normalize(path.join(homeDir, asarFile));
|
|
44
|
+
} else if (Array.isArray(cfg.asarFile)) {
|
|
45
|
+
// 检查文件列表,如果存在就跳出
|
|
46
|
+
for (const filep of cfg.asarFile) {
|
|
47
|
+
asarFilePath = path.normalize(path.join(homeDir, filep));
|
|
48
|
+
if (fs.existsSync(asarFilePath)) {
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
asarFilePath = path.normalize(path.join(homeDir, cfg.asarFile));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!fs.existsSync(asarFilePath)) {
|
|
57
|
+
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${asarFilePath} does not exist`));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 生成 zip
|
|
62
|
+
const asarZipPath = path.join(homeDir, cfg.output.directory, cfg.output.zip);
|
|
63
|
+
if (fs.existsSync(asarZipPath) && cfg.cleanCache) {
|
|
64
|
+
Utils.rm(asarZipPath);
|
|
65
|
+
}
|
|
66
|
+
const zip = new admZip();
|
|
67
|
+
zip.addLocalFile(asarFilePath);
|
|
68
|
+
zip.writeZip(asarZipPath, (err) => {
|
|
69
|
+
if (err) {
|
|
70
|
+
console.log(chalk.blue('[ee-bin] [updater] create zip ') + chalk.red(`Error: ${err}`));
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const sha1 = this.generateSha1(asarFilePath);
|
|
75
|
+
const packageJson = Utils.getPackage();
|
|
76
|
+
const version = packageJson.version;
|
|
77
|
+
const date = this._getFormattedDate();
|
|
78
|
+
const fileStat = fs.statSync(asarFilePath);
|
|
79
|
+
|
|
80
|
+
for (const item of cfg.platform) {
|
|
81
|
+
latestVersionInfo[item] = {
|
|
82
|
+
version: version,
|
|
83
|
+
file: cfg.output.zip,
|
|
84
|
+
size: fileStat.size,
|
|
85
|
+
sha1: sha1,
|
|
86
|
+
releaseDate: date,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const updaterJsonFilePath = path.join(homeDir, cfg.output.directory, cfg.output.file);
|
|
91
|
+
Utils.writeJsonSync(updaterJsonFilePath, latestVersionInfo);
|
|
92
|
+
|
|
93
|
+
// 删除缓存文件,防止生成的 zip 是旧版本
|
|
94
|
+
if (cfg.cleanCache) {
|
|
95
|
+
Utils.rm(path.join(homeDir, cfg.output.directory, 'mac'));
|
|
96
|
+
Utils.rm(path.join(homeDir, cfg.output.directory, 'win-unpacked'));
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
generateSha1(filepath = "") {
|
|
101
|
+
let sha1 = '';
|
|
102
|
+
if (filepath.length == 0) {
|
|
103
|
+
return sha1;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (!fs.existsSync(filepath)) {
|
|
107
|
+
return sha1;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
console.log(chalk.blue('[ee-bin] [updater] ') + `generate sha1 for filepath:${filepath}`);
|
|
111
|
+
try {
|
|
112
|
+
const buffer = fs.readFileSync(filepath);
|
|
113
|
+
const fsHash = crypto.createHash('sha1');
|
|
114
|
+
fsHash.update(buffer);
|
|
115
|
+
sha1 = fsHash.digest('hex');
|
|
116
|
+
return sha1;
|
|
117
|
+
|
|
118
|
+
} catch (error) {
|
|
119
|
+
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: generate sha1 error!`));
|
|
120
|
+
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${error}`));
|
|
121
|
+
}
|
|
122
|
+
return sha1;
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
_getFormattedDate() {
|
|
126
|
+
const date = new Date(); // 获取当前日期
|
|
127
|
+
const year = date.getFullYear(); // 获取年份
|
|
128
|
+
const month = (date.getMonth() + 1).toString().padStart(2, '0'); // 获取月份,月份从0开始计数
|
|
129
|
+
const day = date.getDate().toString().padStart(2, '0'); // 获取日
|
|
130
|
+
|
|
131
|
+
return `${year}-${month}-${day}`;
|
|
132
|
+
}
|
|
133
|
+
}
|
package/tools/move.js
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const fsPro = require('fs-extra');
|
|
6
|
-
const chalk = require('chalk');
|
|
7
|
-
const Utils = require('../lib/utils');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 移动资源
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
module.exports = {
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 执行
|
|
17
|
-
*/
|
|
18
|
-
run(options = {}) {
|
|
19
|
-
console.log('[ee-bin] [move] Start moving resources');
|
|
20
|
-
const homeDir = process.cwd();
|
|
21
|
-
const { config, flag } = options;
|
|
22
|
-
const binCfg = Utils.loadConfig(config);
|
|
23
|
-
|
|
24
|
-
let flags;
|
|
25
|
-
const flagString = flag.trim();
|
|
26
|
-
if (flagString.indexOf(',') !== -1) {
|
|
27
|
-
flags = flagString.split(',');
|
|
28
|
-
} else {
|
|
29
|
-
flags = [flagString];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
for (let i = 0; i < flags.length; i++) {
|
|
33
|
-
let f = flags[i];
|
|
34
|
-
let cfg = binCfg.move[f];
|
|
35
|
-
|
|
36
|
-
if (!cfg) {
|
|
37
|
-
console.log(chalk.blue('[ee-bin] [move] ') + chalk.red(`Error: ${f} config does not exist` ));
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
console.log(chalk.blue('[ee-bin] [move] ') + chalk.green(`Move flag: ${f}`));
|
|
42
|
-
console.log(chalk.blue('[ee-bin] [move] ') + chalk.green('config:'), cfg);
|
|
43
|
-
|
|
44
|
-
const distResource = path.join(homeDir, cfg.dist);
|
|
45
|
-
if (!fs.existsSync(distResource)) {
|
|
46
|
-
const errorTips = chalk.bgRed('Error') + ` ${cfg.dist} resource does not exist !`;
|
|
47
|
-
console.error(errorTips);
|
|
48
|
-
return
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// clear the historical resource and copy it to the ee resource directory
|
|
52
|
-
const targetResource = path.join(homeDir, cfg.target);
|
|
53
|
-
if (fs.statSync(distResource).isDirectory() && !fs.existsSync(targetResource)) {
|
|
54
|
-
fs.mkdirSync(targetResource, {recursive: true, mode: 0o777});
|
|
55
|
-
} else {
|
|
56
|
-
this._rm(targetResource);
|
|
57
|
-
console.log('[ee-bin] [move] Clear history resources:', targetResource);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
fsPro.copySync(distResource, targetResource);
|
|
61
|
-
|
|
62
|
-
// [todo] go project, special treatment of package.json, reserved only necessary
|
|
63
|
-
console.log(`[ee-bin] [move] Copy ${distResource} to ${targetResource}`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
console.log('[ee-bin] [move] End');
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Delete a file or folder
|
|
71
|
-
*/
|
|
72
|
-
_rm(name) {
|
|
73
|
-
// check
|
|
74
|
-
if (!fs.existsSync(name)) {
|
|
75
|
-
return
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const nodeVersion = (process.versions && process.versions.node) || null;
|
|
79
|
-
if (nodeVersion && Utils.compareVersion(nodeVersion, '14.14.0') == 1) {
|
|
80
|
-
fs.rmSync(name, {recursive: true});
|
|
81
|
-
} else {
|
|
82
|
-
fs.rmdirSync(name, {recursive: true});
|
|
83
|
-
}
|
|
84
|
-
},
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const fsPro = require('fs-extra');
|
|
6
|
+
const chalk = require('chalk');
|
|
7
|
+
const Utils = require('../lib/utils');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 移动资源
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 执行
|
|
17
|
+
*/
|
|
18
|
+
run(options = {}) {
|
|
19
|
+
console.log('[ee-bin] [move] Start moving resources');
|
|
20
|
+
const homeDir = process.cwd();
|
|
21
|
+
const { config, flag } = options;
|
|
22
|
+
const binCfg = Utils.loadConfig(config);
|
|
23
|
+
|
|
24
|
+
let flags;
|
|
25
|
+
const flagString = flag.trim();
|
|
26
|
+
if (flagString.indexOf(',') !== -1) {
|
|
27
|
+
flags = flagString.split(',');
|
|
28
|
+
} else {
|
|
29
|
+
flags = [flagString];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
for (let i = 0; i < flags.length; i++) {
|
|
33
|
+
let f = flags[i];
|
|
34
|
+
let cfg = binCfg.move[f];
|
|
35
|
+
|
|
36
|
+
if (!cfg) {
|
|
37
|
+
console.log(chalk.blue('[ee-bin] [move] ') + chalk.red(`Error: ${f} config does not exist` ));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
console.log(chalk.blue('[ee-bin] [move] ') + chalk.green(`Move flag: ${f}`));
|
|
42
|
+
console.log(chalk.blue('[ee-bin] [move] ') + chalk.green('config:'), cfg);
|
|
43
|
+
|
|
44
|
+
const distResource = path.join(homeDir, cfg.dist);
|
|
45
|
+
if (!fs.existsSync(distResource)) {
|
|
46
|
+
const errorTips = chalk.bgRed('Error') + ` ${cfg.dist} resource does not exist !`;
|
|
47
|
+
console.error(errorTips);
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// clear the historical resource and copy it to the ee resource directory
|
|
52
|
+
const targetResource = path.join(homeDir, cfg.target);
|
|
53
|
+
if (fs.statSync(distResource).isDirectory() && !fs.existsSync(targetResource)) {
|
|
54
|
+
fs.mkdirSync(targetResource, {recursive: true, mode: 0o777});
|
|
55
|
+
} else {
|
|
56
|
+
this._rm(targetResource);
|
|
57
|
+
console.log('[ee-bin] [move] Clear history resources:', targetResource);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
fsPro.copySync(distResource, targetResource);
|
|
61
|
+
|
|
62
|
+
// [todo] go project, special treatment of package.json, reserved only necessary
|
|
63
|
+
console.log(`[ee-bin] [move] Copy ${distResource} to ${targetResource}`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
console.log('[ee-bin] [move] End');
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Delete a file or folder
|
|
71
|
+
*/
|
|
72
|
+
_rm(name) {
|
|
73
|
+
// check
|
|
74
|
+
if (!fs.existsSync(name)) {
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const nodeVersion = (process.versions && process.versions.node) || null;
|
|
79
|
+
if (nodeVersion && Utils.compareVersion(nodeVersion, '14.14.0') == 1) {
|
|
80
|
+
fs.rmSync(name, {recursive: true});
|
|
81
|
+
} else {
|
|
82
|
+
fs.rmdirSync(name, {recursive: true});
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
85
|
}
|