ee-bin 4.1.11 → 5.0.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.
Files changed (72) hide show
  1. package/dist/cjs/config/bin_default.js +149 -0
  2. package/dist/cjs/config/bin_default.js.map +1 -0
  3. package/dist/cjs/index.js +98 -0
  4. package/dist/cjs/index.js.map +1 -0
  5. package/dist/cjs/lib/extend.js +48 -0
  6. package/dist/cjs/lib/extend.js.map +1 -0
  7. package/dist/cjs/lib/helpers.js +92 -0
  8. package/dist/cjs/lib/helpers.js.map +1 -0
  9. package/dist/cjs/lib/utils.js +108 -0
  10. package/dist/cjs/lib/utils.js.map +1 -0
  11. package/dist/cjs/tools/encrypt.js +121 -0
  12. package/dist/cjs/tools/encrypt.js.map +1 -0
  13. package/dist/cjs/tools/iconGen.js +140 -0
  14. package/dist/cjs/tools/iconGen.js.map +1 -0
  15. package/dist/cjs/tools/incrUpdater.js +187 -0
  16. package/dist/cjs/tools/incrUpdater.js.map +1 -0
  17. package/dist/cjs/tools/move.js +56 -0
  18. package/dist/cjs/tools/move.js.map +1 -0
  19. package/dist/cjs/tools/serve.js +286 -0
  20. package/dist/cjs/tools/serve.js.map +1 -0
  21. package/dist/esm/config/bin_default.d.ts +148 -0
  22. package/dist/esm/config/bin_default.d.ts.map +1 -0
  23. package/dist/esm/config/bin_default.js +149 -0
  24. package/dist/esm/config/bin_default.js.map +1 -0
  25. package/dist/esm/index.d.ts +3 -0
  26. package/dist/esm/index.d.ts.map +1 -0
  27. package/dist/esm/index.js +98 -0
  28. package/dist/esm/index.js.map +1 -0
  29. package/dist/esm/lib/extend.d.ts +3 -0
  30. package/dist/esm/lib/extend.d.ts.map +1 -0
  31. package/dist/esm/lib/extend.js +48 -0
  32. package/dist/esm/lib/extend.js.map +1 -0
  33. package/dist/esm/lib/helpers.d.ts +23 -0
  34. package/dist/esm/lib/helpers.d.ts.map +1 -0
  35. package/dist/esm/lib/helpers.js +92 -0
  36. package/dist/esm/lib/helpers.js.map +1 -0
  37. package/dist/esm/lib/utils.d.ts +11 -0
  38. package/dist/esm/lib/utils.d.ts.map +1 -0
  39. package/dist/esm/lib/utils.js +108 -0
  40. package/dist/esm/lib/utils.js.map +1 -0
  41. package/dist/esm/tools/encrypt.d.ts +11 -0
  42. package/dist/esm/tools/encrypt.d.ts.map +1 -0
  43. package/dist/esm/tools/encrypt.js +121 -0
  44. package/dist/esm/tools/encrypt.js.map +1 -0
  45. package/dist/esm/tools/iconGen.d.ts +2 -0
  46. package/dist/esm/tools/iconGen.d.ts.map +1 -0
  47. package/dist/esm/tools/iconGen.js +140 -0
  48. package/dist/esm/tools/iconGen.js.map +1 -0
  49. package/dist/esm/tools/incrUpdater.d.ts +32 -0
  50. package/dist/esm/tools/incrUpdater.d.ts.map +1 -0
  51. package/dist/esm/tools/incrUpdater.js +187 -0
  52. package/dist/esm/tools/incrUpdater.js.map +1 -0
  53. package/dist/esm/tools/move.d.ts +7 -0
  54. package/dist/esm/tools/move.d.ts.map +1 -0
  55. package/dist/esm/tools/move.js +56 -0
  56. package/dist/esm/tools/move.js.map +1 -0
  57. package/dist/esm/tools/serve.d.ts +42 -0
  58. package/dist/esm/tools/serve.d.ts.map +1 -0
  59. package/dist/esm/tools/serve.js +286 -0
  60. package/dist/esm/tools/serve.js.map +1 -0
  61. package/package.json +67 -32
  62. package/config/bin_default.js +0 -182
  63. package/index.js +0 -121
  64. package/lib/extend.js +0 -78
  65. package/lib/pargv.js +0 -263
  66. package/lib/utils.js +0 -255
  67. package/readme.md +0 -1
  68. package/tools/encrypt.js +0 -179
  69. package/tools/iconGen.js +0 -183
  70. package/tools/incrUpdater.js +0 -196
  71. package/tools/move.js +0 -69
  72. package/tools/serve.js +0 -346
package/tools/encrypt.js DELETED
@@ -1,179 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const fs = require('fs');
5
- const fsPro = require('fs-extra');
6
- const is = require('is-type-of');
7
- const bytenode = require('bytenode');
8
- const JavaScriptObfuscator = require('javascript-obfuscator');
9
- const globby = require('globby');
10
- const chalk = require('chalk');
11
- const { loadConfig } = require('../lib/utils');
12
- const { extend } = require('../lib/extend');
13
-
14
- const EncryptTypes = ['bytecode', 'confusion', 'strict'];
15
-
16
- class Encrypt {
17
- constructor(options = {}) {
18
- // cli args
19
- const { config, out, target } = options;
20
- this.basePath = process.cwd();
21
- this.target = target;
22
-
23
- const conf = loadConfig(config).encrypt;
24
- this.config = conf[target];
25
- const outputFolder = out || this.config.encryptDir;
26
- this.encryptDir = path.join(this.basePath, outputFolder);
27
- this.filesExt = this.config.fileExt;
28
- this.type = this.config.type;
29
- this.bOpt = this.config.bytecodeOptions;
30
- this.cOpt = this.config.confusionOptions;
31
- this.cleanFiles = this.config.cleanFiles;
32
- this.patterns = this.config.files || null;
33
- this.specFiles = this.config.specificFiles;
34
-
35
- this.codefiles = this._initCodeFiles();
36
- }
37
-
38
- /**
39
- * 初始化需要加密的文件列表
40
- */
41
- _initCodeFiles() {
42
- if (!this.patterns) return;
43
-
44
- const files = globby.sync(this.patterns, { cwd: this.basePath });
45
- return files;
46
- }
47
-
48
- /**
49
- * 加密代码
50
- */
51
- encrypt() {
52
- if (EncryptTypes.indexOf(this.type) == -1) return;
53
- if (this.target == 'frontend' && (this.type == 'bytecode' || this.type == 'strict')) return;
54
-
55
- console.log(chalk.blue('[ee-bin] [encrypt] ') + `start ciphering ${this.target}`);
56
- for (const file of this.codefiles) {
57
- const fullpath = path.join(this.encryptDir, file);
58
- if (!fs.statSync(fullpath).isFile()) continue;
59
-
60
- // 特殊文件处理
61
- if (this.specFiles.includes(file)) {
62
- this.generate(fullpath, 'confusion');
63
- continue;
64
- }
65
-
66
- this.generate(fullpath);
67
- }
68
- console.log(chalk.blue('[ee-bin] [encrypt] ') + 'end ciphering');
69
- };
70
-
71
- /**
72
- * 递归
73
- */
74
- loop(dirPath) {
75
- let files = [];
76
- if (fs.existsSync(dirPath)) {
77
- files = fs.readdirSync(dirPath);
78
- files.forEach((file, index) => {
79
- let curPath = dirPath + '/' + file;
80
- if (fs.statSync(curPath).isDirectory()) {
81
- this.loop(curPath);
82
- } else {
83
- const extname = path.extname(curPath);
84
- if (this.filesExt.indexOf(extname) !== -1) {
85
- this.generate(curPath);
86
- }
87
- }
88
- });
89
- }
90
- }
91
-
92
- /**
93
- * 生成文件
94
- */
95
- generate(curPath, type) {
96
- let encryptType = type ? type : this.type;
97
-
98
- let tips = chalk.blue('[ee-bin] [encrypt] ') + 'file: ' + chalk.green(`${curPath}`) + ' ' + chalk.cyan(`(${encryptType})`);
99
- console.log(tips);
100
- if (encryptType == 'strict') {
101
- this.generateJSConfuseFile(curPath);
102
- this.generateBytecodeFile(curPath);
103
- } else if (encryptType == 'bytecode') {
104
- this.generateBytecodeFile(curPath);
105
- } else if (encryptType == 'confusion') {
106
- this.generateJSConfuseFile(curPath);
107
- } else {
108
- // none
109
- }
110
- }
111
-
112
- /**
113
- * 使用 javascript-obfuscator 生成压缩/混淆文件
114
- */
115
- generateJSConfuseFile(file) {
116
- let opt = Object.assign({
117
- compact: true,
118
- stringArray: true,
119
- stringArrayThreshold: 1,
120
- }, this.cOpt);
121
-
122
- let code = fs.readFileSync(file, "utf8");
123
- let result = JavaScriptObfuscator.obfuscate(code, opt);
124
- fs.writeFileSync(file, result.getObfuscatedCode(), "utf8");
125
- }
126
-
127
- /**
128
- * 生成字节码文件
129
- */
130
- generateBytecodeFile(curPath) {
131
- if (path.extname(curPath) !== '.js') {
132
- return
133
- }
134
- //let jscFile = curPath.replace(/.js/g, '.jsc');
135
- let jscFile = curPath + 'c';
136
- let opt = Object.assign({
137
- filename: curPath,
138
- output: jscFile,
139
- electron: true
140
- }, this.bOpt);
141
-
142
- bytenode.compileFile(opt);
143
- fsPro.removeSync(curPath);
144
- }
145
- }
146
-
147
- function encrypt(options = {}) {
148
- const electronOpt = extend(true, {
149
- target: 'electron',
150
- }, options);
151
- const electronEpt = new Encrypt(electronOpt);
152
- electronEpt.encrypt();
153
-
154
- const frontendOpt = extend(true, {
155
- target: 'frontend',
156
- }, options);
157
- const frontendEpt = new Encrypt(frontendOpt);
158
- frontendEpt.encrypt();
159
- }
160
-
161
- function cleanEncrypt(options = {}) {
162
- // [todo] 删除前端和主进程代码
163
- return;
164
- let files = options.dir !== undefined ? options.dir : ['./public/electron'];
165
- files = is.string(files) ? [files] : files;
166
-
167
- files.forEach((file) => {
168
- const tmpFile = path.join(process.cwd(), file);
169
- if (fs.existsSync(tmpFile)) {
170
- fsPro.removeSync(tmpFile);
171
- console.log(chalk.blue('[ee-bin] [encrypt] ') + 'clean up tmp files: ' + chalk.magenta(`${tmpFile}`));
172
- }
173
- })
174
- }
175
-
176
- module.exports = {
177
- encrypt,
178
- cleanEncrypt,
179
- };
package/tools/iconGen.js DELETED
@@ -1,183 +0,0 @@
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
- };
@@ -1,196 +0,0 @@
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
- }
package/tools/move.js DELETED
@@ -1,69 +0,0 @@
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
- }