ee-bin 4.1.10 → 4.1.11
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 -255
- package/package.json +32 -32
- package/tools/encrypt.js +178 -178
- package/tools/iconGen.js +182 -182
- package/tools/incrUpdater.js +195 -195
- package/tools/move.js +68 -68
- package/tools/serve.js +346 -346
package/tools/incrUpdater.js
CHANGED
|
@@ -1,196 +1,196 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const fsPro = require('fs-extra');
|
|
6
|
-
const crypto = require('crypto');
|
|
7
|
-
const chalk = require('chalk');
|
|
8
|
-
const { loadConfig, getPackage, writeJsonSync } = require('../lib/utils');
|
|
9
|
-
const admZip = require('adm-zip');
|
|
10
|
-
const globby = require('globby');
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 增量升级
|
|
15
|
-
* @class
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
class IncrUpdater {
|
|
19
|
-
|
|
20
|
-
constructor() {
|
|
21
|
-
this.tmpAppDirs = [
|
|
22
|
-
'mac',
|
|
23
|
-
'mac-arm64',
|
|
24
|
-
'win-unpacked',
|
|
25
|
-
'win-ia32-unpacked',
|
|
26
|
-
'linux-unpacked'
|
|
27
|
-
];
|
|
28
|
-
this.nodeModulesString = 'node_modules';
|
|
29
|
-
this.asarUnpackedString = 'app.asar.unpacked';
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* 执行
|
|
34
|
-
*/
|
|
35
|
-
run(options = {}) {
|
|
36
|
-
console.log('[ee-bin] [updater] Start');
|
|
37
|
-
const { config, asarFile, platform } = options;
|
|
38
|
-
const binCfg = loadConfig(config);
|
|
39
|
-
const cfg = binCfg.updater;
|
|
40
|
-
|
|
41
|
-
if (!cfg) {
|
|
42
|
-
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${cfg} config does not exist`));
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
this.generateFile(cfg, asarFile, platform);
|
|
47
|
-
|
|
48
|
-
console.log('[ee-bin] [updater] End');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* 生成增量升级文件
|
|
53
|
-
*/
|
|
54
|
-
generateFile(config, asarFile, platform) {
|
|
55
|
-
const cfg = config[platform];
|
|
56
|
-
if (!cfg) {
|
|
57
|
-
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${platform} config does not exist`));
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
let latestVersionInfo = {}
|
|
62
|
-
const homeDir = process.cwd();
|
|
63
|
-
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.green(`${platform} config:`), cfg);
|
|
64
|
-
|
|
65
|
-
let asarFilePath = "";
|
|
66
|
-
if (asarFile) {
|
|
67
|
-
asarFilePath = path.normalize(path.join(homeDir, asarFile));
|
|
68
|
-
} else {
|
|
69
|
-
asarFilePath = path.normalize(path.join(homeDir, cfg.asarFile));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (!fs.existsSync(asarFilePath)) {
|
|
73
|
-
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${asarFilePath} does not exist`));
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const packageJson = getPackage();
|
|
78
|
-
const version = packageJson.version;
|
|
79
|
-
let platformForFilename = platform;
|
|
80
|
-
if (platform.indexOf("_") !== -1) {
|
|
81
|
-
const platformArr = platform.split("_");
|
|
82
|
-
platformForFilename = platformArr.join("-");
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// 生成 zip
|
|
86
|
-
let zipName = "";
|
|
87
|
-
zipName = path.basename(cfg.output.zip, '.zip') + `-${platformForFilename}-${version}.zip`;
|
|
88
|
-
const asarZipPath = path.join(homeDir, cfg.output.directory, zipName);
|
|
89
|
-
if (fs.existsSync(asarZipPath)) {
|
|
90
|
-
fsPro.removeSync(asarZipPath);
|
|
91
|
-
}
|
|
92
|
-
const zip = new admZip();
|
|
93
|
-
// 添加 asar 文件
|
|
94
|
-
zip.addLocalFile(asarFilePath);
|
|
95
|
-
// 添加 extraResources
|
|
96
|
-
if (cfg.extraResources && cfg.extraResources.length > 0) {
|
|
97
|
-
const files = globby.sync(cfg.extraResources, { cwd: homeDir });
|
|
98
|
-
for (const extraRes of files) {
|
|
99
|
-
const extraResPath = path.normalize(path.join(homeDir, extraRes));
|
|
100
|
-
if (!fs.existsSync(extraResPath)) {
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
const extraResDir = path.dirname(extraResPath);
|
|
104
|
-
const index = extraResDir.indexOf('extraResources');
|
|
105
|
-
const zipFileDir = extraResDir.substring(index);
|
|
106
|
-
// 资源路径 extraResPath: D:\www\gofile\src\ee\ee-demo\build\extraResources\hello\c.txt
|
|
107
|
-
// 文件在zip中的路径 zipFileDir: extraResources/hello
|
|
108
|
-
zip.addLocalFile(extraResPath, zipFileDir);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
// 添加 asarUnpacked
|
|
112
|
-
if (cfg.asarUnpacked && cfg.asarUnpacked.length > 0) {
|
|
113
|
-
const modules = cfg.asarUnpacked;
|
|
114
|
-
for (const moduleItem of modules) {
|
|
115
|
-
const modulePath = path.normalize(path.join(homeDir, moduleItem));
|
|
116
|
-
if (!fs.existsSync(modulePath)) {
|
|
117
|
-
throw new Error(`${modulePath} is not exists!`);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const zipDir = path.join(this.asarUnpackedString, moduleItem);
|
|
121
|
-
// console.log('modulePath', modulePath);
|
|
122
|
-
// console.log('zipDir', zipDir);
|
|
123
|
-
zip.addLocalFolder(modulePath, zipDir);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
zip.writeZip(asarZipPath, (err) => {
|
|
128
|
-
if (err) {
|
|
129
|
-
console.log(chalk.blue('[ee-bin] [updater] create zip ') + chalk.red(`Error: ${err}`));
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
// 生成 latest.json
|
|
134
|
-
const sha1 = this.generateSha1(
|
|
135
|
-
const date = this._getFormattedDate();
|
|
136
|
-
const fileStat = fs.statSync(
|
|
137
|
-
const item = {
|
|
138
|
-
version: version,
|
|
139
|
-
file: zipName,
|
|
140
|
-
size: fileStat.size,
|
|
141
|
-
sha1: sha1,
|
|
142
|
-
releaseDate: date,
|
|
143
|
-
};
|
|
144
|
-
const jsonName = path.basename(cfg.output.file, '.json') + `-${platformForFilename}.json`;
|
|
145
|
-
latestVersionInfo = item;
|
|
146
|
-
const updaterJsonFilePath = path.join(homeDir, cfg.output.directory, jsonName);
|
|
147
|
-
writeJsonSync(updaterJsonFilePath, latestVersionInfo);
|
|
148
|
-
|
|
149
|
-
// 删除缓存文件,防止生成的 zip 是旧版本
|
|
150
|
-
if (cfg.cleanCache) {
|
|
151
|
-
this.tmpAppDirs.forEach(dir => {
|
|
152
|
-
const dirPath = path.join(homeDir, cfg.output.directory, dir);
|
|
153
|
-
fsPro.removeSync(dirPath);
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
generateSha1(filepath = "") {
|
|
159
|
-
let sha1 = '';
|
|
160
|
-
if (filepath.length == 0) {
|
|
161
|
-
return sha1;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (!fs.existsSync(filepath)) {
|
|
165
|
-
return sha1;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
console.log(chalk.blue('[ee-bin] [updater] ') + `generate sha1 for filepath:${filepath}`);
|
|
169
|
-
try {
|
|
170
|
-
const buffer = fs.readFileSync(filepath);
|
|
171
|
-
const fsHash = crypto.createHash('sha1');
|
|
172
|
-
fsHash.update(buffer);
|
|
173
|
-
sha1 = fsHash.digest('hex');
|
|
174
|
-
return sha1;
|
|
175
|
-
|
|
176
|
-
} catch (error) {
|
|
177
|
-
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: generate sha1 error!`));
|
|
178
|
-
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${error}`));
|
|
179
|
-
}
|
|
180
|
-
return sha1;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
_getFormattedDate() {
|
|
184
|
-
const date = new Date(); // 获取当前日期
|
|
185
|
-
const year = date.getFullYear(); // 获取年份
|
|
186
|
-
const month = (date.getMonth() + 1).toString().padStart(2, '0'); // 获取月份,月份从0开始计数
|
|
187
|
-
const day = date.getDate().toString().padStart(2, '0'); // 获取日
|
|
188
|
-
|
|
189
|
-
return `${year}-${month}-${day}`;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
module.exports = {
|
|
194
|
-
IncrUpdater,
|
|
195
|
-
incrUpdater: new IncrUpdater()
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const fsPro = require('fs-extra');
|
|
6
|
+
const crypto = require('crypto');
|
|
7
|
+
const chalk = require('chalk');
|
|
8
|
+
const { loadConfig, getPackage, writeJsonSync } = require('../lib/utils');
|
|
9
|
+
const admZip = require('adm-zip');
|
|
10
|
+
const globby = require('globby');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 增量升级
|
|
15
|
+
* @class
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
class IncrUpdater {
|
|
19
|
+
|
|
20
|
+
constructor() {
|
|
21
|
+
this.tmpAppDirs = [
|
|
22
|
+
'mac',
|
|
23
|
+
'mac-arm64',
|
|
24
|
+
'win-unpacked',
|
|
25
|
+
'win-ia32-unpacked',
|
|
26
|
+
'linux-unpacked'
|
|
27
|
+
];
|
|
28
|
+
this.nodeModulesString = 'node_modules';
|
|
29
|
+
this.asarUnpackedString = 'app.asar.unpacked';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 执行
|
|
34
|
+
*/
|
|
35
|
+
run(options = {}) {
|
|
36
|
+
console.log('[ee-bin] [updater] Start');
|
|
37
|
+
const { config, asarFile, platform } = options;
|
|
38
|
+
const binCfg = loadConfig(config);
|
|
39
|
+
const cfg = binCfg.updater;
|
|
40
|
+
|
|
41
|
+
if (!cfg) {
|
|
42
|
+
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${cfg} config does not exist`));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.generateFile(cfg, asarFile, platform);
|
|
47
|
+
|
|
48
|
+
console.log('[ee-bin] [updater] End');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 生成增量升级文件
|
|
53
|
+
*/
|
|
54
|
+
generateFile(config, asarFile, platform) {
|
|
55
|
+
const cfg = config[platform];
|
|
56
|
+
if (!cfg) {
|
|
57
|
+
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${platform} config does not exist`));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let latestVersionInfo = {}
|
|
62
|
+
const homeDir = process.cwd();
|
|
63
|
+
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.green(`${platform} config:`), cfg);
|
|
64
|
+
|
|
65
|
+
let asarFilePath = "";
|
|
66
|
+
if (asarFile) {
|
|
67
|
+
asarFilePath = path.normalize(path.join(homeDir, asarFile));
|
|
68
|
+
} else {
|
|
69
|
+
asarFilePath = path.normalize(path.join(homeDir, cfg.asarFile));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!fs.existsSync(asarFilePath)) {
|
|
73
|
+
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${asarFilePath} does not exist`));
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const packageJson = getPackage();
|
|
78
|
+
const version = packageJson.version;
|
|
79
|
+
let platformForFilename = platform;
|
|
80
|
+
if (platform.indexOf("_") !== -1) {
|
|
81
|
+
const platformArr = platform.split("_");
|
|
82
|
+
platformForFilename = platformArr.join("-");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 生成 zip
|
|
86
|
+
let zipName = "";
|
|
87
|
+
zipName = path.basename(cfg.output.zip, '.zip') + `-${platformForFilename}-${version}.zip`;
|
|
88
|
+
const asarZipPath = path.join(homeDir, cfg.output.directory, zipName);
|
|
89
|
+
if (fs.existsSync(asarZipPath)) {
|
|
90
|
+
fsPro.removeSync(asarZipPath);
|
|
91
|
+
}
|
|
92
|
+
const zip = new admZip();
|
|
93
|
+
// 添加 asar 文件
|
|
94
|
+
zip.addLocalFile(asarFilePath);
|
|
95
|
+
// 添加 extraResources
|
|
96
|
+
if (cfg.extraResources && cfg.extraResources.length > 0) {
|
|
97
|
+
const files = globby.sync(cfg.extraResources, { cwd: homeDir });
|
|
98
|
+
for (const extraRes of files) {
|
|
99
|
+
const extraResPath = path.normalize(path.join(homeDir, extraRes));
|
|
100
|
+
if (!fs.existsSync(extraResPath)) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const extraResDir = path.dirname(extraResPath);
|
|
104
|
+
const index = extraResDir.indexOf('extraResources');
|
|
105
|
+
const zipFileDir = extraResDir.substring(index);
|
|
106
|
+
// 资源路径 extraResPath: D:\www\gofile\src\ee\ee-demo\build\extraResources\hello\c.txt
|
|
107
|
+
// 文件在zip中的路径 zipFileDir: extraResources/hello
|
|
108
|
+
zip.addLocalFile(extraResPath, zipFileDir);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// 添加 asarUnpacked
|
|
112
|
+
if (cfg.asarUnpacked && cfg.asarUnpacked.length > 0) {
|
|
113
|
+
const modules = cfg.asarUnpacked;
|
|
114
|
+
for (const moduleItem of modules) {
|
|
115
|
+
const modulePath = path.normalize(path.join(homeDir, moduleItem));
|
|
116
|
+
if (!fs.existsSync(modulePath)) {
|
|
117
|
+
throw new Error(`${modulePath} is not exists!`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const zipDir = path.join(this.asarUnpackedString, moduleItem);
|
|
121
|
+
// console.log('modulePath', modulePath);
|
|
122
|
+
// console.log('zipDir', zipDir);
|
|
123
|
+
zip.addLocalFolder(modulePath, zipDir);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
zip.writeZip(asarZipPath, (err) => {
|
|
128
|
+
if (err) {
|
|
129
|
+
console.log(chalk.blue('[ee-bin] [updater] create zip ') + chalk.red(`Error: ${err}`));
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// 生成 latest.json
|
|
134
|
+
const sha1 = this.generateSha1(asarZipPath);
|
|
135
|
+
const date = this._getFormattedDate();
|
|
136
|
+
const fileStat = fs.statSync(asarZipPath);
|
|
137
|
+
const item = {
|
|
138
|
+
version: version,
|
|
139
|
+
file: zipName,
|
|
140
|
+
size: fileStat.size,
|
|
141
|
+
sha1: sha1,
|
|
142
|
+
releaseDate: date,
|
|
143
|
+
};
|
|
144
|
+
const jsonName = path.basename(cfg.output.file, '.json') + `-${platformForFilename}.json`;
|
|
145
|
+
latestVersionInfo = item;
|
|
146
|
+
const updaterJsonFilePath = path.join(homeDir, cfg.output.directory, jsonName);
|
|
147
|
+
writeJsonSync(updaterJsonFilePath, latestVersionInfo);
|
|
148
|
+
|
|
149
|
+
// 删除缓存文件,防止生成的 zip 是旧版本
|
|
150
|
+
if (cfg.cleanCache) {
|
|
151
|
+
this.tmpAppDirs.forEach(dir => {
|
|
152
|
+
const dirPath = path.join(homeDir, cfg.output.directory, dir);
|
|
153
|
+
fsPro.removeSync(dirPath);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
generateSha1(filepath = "") {
|
|
159
|
+
let sha1 = '';
|
|
160
|
+
if (filepath.length == 0) {
|
|
161
|
+
return sha1;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (!fs.existsSync(filepath)) {
|
|
165
|
+
return sha1;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
console.log(chalk.blue('[ee-bin] [updater] ') + `generate sha1 for filepath:${filepath}`);
|
|
169
|
+
try {
|
|
170
|
+
const buffer = fs.readFileSync(filepath);
|
|
171
|
+
const fsHash = crypto.createHash('sha1');
|
|
172
|
+
fsHash.update(buffer);
|
|
173
|
+
sha1 = fsHash.digest('hex');
|
|
174
|
+
return sha1;
|
|
175
|
+
|
|
176
|
+
} catch (error) {
|
|
177
|
+
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: generate sha1 error!`));
|
|
178
|
+
console.log(chalk.blue('[ee-bin] [updater] ') + chalk.red(`Error: ${error}`));
|
|
179
|
+
}
|
|
180
|
+
return sha1;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
_getFormattedDate() {
|
|
184
|
+
const date = new Date(); // 获取当前日期
|
|
185
|
+
const year = date.getFullYear(); // 获取年份
|
|
186
|
+
const month = (date.getMonth() + 1).toString().padStart(2, '0'); // 获取月份,月份从0开始计数
|
|
187
|
+
const day = date.getDate().toString().padStart(2, '0'); // 获取日
|
|
188
|
+
|
|
189
|
+
return `${year}-${month}-${day}`;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
module.exports = {
|
|
194
|
+
IncrUpdater,
|
|
195
|
+
incrUpdater: new IncrUpdater()
|
|
196
196
|
}
|
package/tools/move.js
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
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 { loadConfig, rm } = require('../lib/utils');
|
|
8
|
-
|
|
9
|
-
const homeDir = process.cwd();
|
|
10
|
-
|
|
11
|
-
// 移动资源
|
|
12
|
-
function move(options = {}) {
|
|
13
|
-
console.log('[ee-bin] [move] Start moving resources');
|
|
14
|
-
const { config, flag } = options;
|
|
15
|
-
const binCfg = loadConfig(config);
|
|
16
|
-
const moveConfig = binCfg.move;
|
|
17
|
-
|
|
18
|
-
let flags;
|
|
19
|
-
const flagString = flag.trim();
|
|
20
|
-
if (flagString.indexOf(',') !== -1) {
|
|
21
|
-
flags = flagString.split(',');
|
|
22
|
-
} else {
|
|
23
|
-
flags = [flagString];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
for (let i = 0; i < flags.length; i++) {
|
|
27
|
-
let f = flags[i];
|
|
28
|
-
let cfg = moveConfig[f];
|
|
29
|
-
|
|
30
|
-
if (!cfg) {
|
|
31
|
-
console.log(chalk.blue('[ee-bin] [move] ') + chalk.red(`Error: ${f} config does not exist` ));
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const { src, dest, dist, target } = cfg;
|
|
36
|
-
const source = dist ? dist : src;
|
|
37
|
-
const destination = target ? target : dest;
|
|
38
|
-
|
|
39
|
-
console.log(chalk.blue('[ee-bin] [move] ') + chalk.green(`Move flag: ${f}`));
|
|
40
|
-
console.log(chalk.blue('[ee-bin] [move] ') + chalk.green('config:'), cfg);
|
|
41
|
-
|
|
42
|
-
const srcResource = path.join(homeDir, source);
|
|
43
|
-
if (!fs.existsSync(srcResource)) {
|
|
44
|
-
const errorTips = chalk.bgRed('Error') + ` ${source} resource does not exist !`;
|
|
45
|
-
console.error(errorTips);
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// clear the historical resource and copy it to the ee resource directory
|
|
50
|
-
const destResource = path.join(homeDir, destination);
|
|
51
|
-
if (fs.statSync(srcResource).isDirectory() && !fs.existsSync(destResource)) {
|
|
52
|
-
fs.mkdirSync(destResource, {recursive: true, mode: 0o777});
|
|
53
|
-
} else {
|
|
54
|
-
rm(destResource);
|
|
55
|
-
console.log('[ee-bin] [move] Clear history resources:', destResource);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
fsPro.copySync(srcResource, destResource);
|
|
59
|
-
|
|
60
|
-
// [todo] go project, special treatment of package.json, reserved only necessary
|
|
61
|
-
console.log(`[ee-bin] [move] Copy ${srcResource} to ${destResource}`);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
console.log('[ee-bin] [move] End');
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
module.exports = {
|
|
68
|
-
move
|
|
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 { loadConfig, rm } = require('../lib/utils');
|
|
8
|
+
|
|
9
|
+
const homeDir = process.cwd();
|
|
10
|
+
|
|
11
|
+
// 移动资源
|
|
12
|
+
function move(options = {}) {
|
|
13
|
+
console.log('[ee-bin] [move] Start moving resources');
|
|
14
|
+
const { config, flag } = options;
|
|
15
|
+
const binCfg = loadConfig(config);
|
|
16
|
+
const moveConfig = binCfg.move;
|
|
17
|
+
|
|
18
|
+
let flags;
|
|
19
|
+
const flagString = flag.trim();
|
|
20
|
+
if (flagString.indexOf(',') !== -1) {
|
|
21
|
+
flags = flagString.split(',');
|
|
22
|
+
} else {
|
|
23
|
+
flags = [flagString];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
for (let i = 0; i < flags.length; i++) {
|
|
27
|
+
let f = flags[i];
|
|
28
|
+
let cfg = moveConfig[f];
|
|
29
|
+
|
|
30
|
+
if (!cfg) {
|
|
31
|
+
console.log(chalk.blue('[ee-bin] [move] ') + chalk.red(`Error: ${f} config does not exist` ));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const { src, dest, dist, target } = cfg;
|
|
36
|
+
const source = dist ? dist : src;
|
|
37
|
+
const destination = target ? target : dest;
|
|
38
|
+
|
|
39
|
+
console.log(chalk.blue('[ee-bin] [move] ') + chalk.green(`Move flag: ${f}`));
|
|
40
|
+
console.log(chalk.blue('[ee-bin] [move] ') + chalk.green('config:'), cfg);
|
|
41
|
+
|
|
42
|
+
const srcResource = path.join(homeDir, source);
|
|
43
|
+
if (!fs.existsSync(srcResource)) {
|
|
44
|
+
const errorTips = chalk.bgRed('Error') + ` ${source} resource does not exist !`;
|
|
45
|
+
console.error(errorTips);
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// clear the historical resource and copy it to the ee resource directory
|
|
50
|
+
const destResource = path.join(homeDir, destination);
|
|
51
|
+
if (fs.statSync(srcResource).isDirectory() && !fs.existsSync(destResource)) {
|
|
52
|
+
fs.mkdirSync(destResource, {recursive: true, mode: 0o777});
|
|
53
|
+
} else {
|
|
54
|
+
rm(destResource);
|
|
55
|
+
console.log('[ee-bin] [move] Clear history resources:', destResource);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
fsPro.copySync(srcResource, destResource);
|
|
59
|
+
|
|
60
|
+
// [todo] go project, special treatment of package.json, reserved only necessary
|
|
61
|
+
console.log(`[ee-bin] [move] Copy ${srcResource} to ${destResource}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
console.log('[ee-bin] [move] End');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = {
|
|
68
|
+
move
|
|
69
69
|
}
|