jjb-cmd 2.5.3 → 2.5.4

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/src/utils.js CHANGED
@@ -1 +1,228 @@
1
- const a8_0x5d5f15=a8_0x4429;(function(_0x46cc26,_0x20c2c2){const _0x4869f3=a8_0x4429,_0xacbaee=_0x46cc26();while(!![]){try{const _0x2cb3de=-parseInt(_0x4869f3(0x133))/0x1*(-parseInt(_0x4869f3(0x122))/0x2)+-parseInt(_0x4869f3(0x126))/0x3+parseInt(_0x4869f3(0x139))/0x4*(-parseInt(_0x4869f3(0x127))/0x5)+parseInt(_0x4869f3(0x10e))/0x6*(-parseInt(_0x4869f3(0x10b))/0x7)+parseInt(_0x4869f3(0x11d))/0x8+parseInt(_0x4869f3(0x121))/0x9*(parseInt(_0x4869f3(0x135))/0xa)+-parseInt(_0x4869f3(0x10c))/0xb*(-parseInt(_0x4869f3(0x12e))/0xc);if(_0x2cb3de===_0x20c2c2)break;else _0xacbaee['push'](_0xacbaee['shift']());}catch(_0x3e5c07){_0xacbaee['push'](_0xacbaee['shift']());}}}(a8_0x5026,0xb0404));const fs=require('fs'),path=require(a8_0x5d5f15(0x111)),child_process=require('child_process'),chalk=require(a8_0x5d5f15(0x11c)),CONSTANTS={'MAX_BUFFER_SIZE':0x3b9aca00,'SYNC_DELAY':0x3e8,'DEFAULT_BRANCH':a8_0x5d5f15(0x11b),'CONFIG_FILE_NAME':a8_0x5d5f15(0x112),'BUILD_OUTPUT_DIR':a8_0x5d5f15(0x120),'TEMPLATES_PATH':a8_0x5d5f15(0x10d)};function a8_0x5026(){const _0x342991=['join','readdir','yellow','execSync','filter','master','chalk','7778912QslLym','createWriteStream','lstatSync','dist','37431DFnubB','1204646TztbZi','existsSync','log','dirname','54810yPuYhX','5632885okuURi','error','writeFileSync','文件复制失败:\x20','environment','vite.config.ts','mkdir','3036dszPKF','unlinkSync','vite.config.mjs','rmdirSync','[工作目录:\x20','1ZYmqxa','pipe','790ljbsbV','创建目录失败:\x20','执行命令:\x20','exports','4JSxjYE','createReadStream','readdirSync','statSync','green','utf8','6579580lUviIU','39281JXTTeW','start/src/main/resources/templates','6cXCAUo','message','isDirectory','path','jjb.config.js','forEach','vite.config.js','length'];a8_0x5026=function(){return _0x342991;};return a8_0x5026();}function logInfo(_0x3f3bc1,_0x238df8=''){const _0x2a7457=a8_0x5d5f15,_0x3ef952=chalk['blue']('ℹ'),_0x17dca8=_0x238df8?_0x3ef952+'\x20'+_0x3f3bc1+'\x20'+_0x238df8:_0x3ef952+'\x20'+_0x3f3bc1;console[_0x2a7457(0x124)](_0x17dca8);}function logSuccess(_0x23ef68){const _0x4dad1c=a8_0x5d5f15;console[_0x4dad1c(0x124)](chalk[_0x4dad1c(0x109)]('✓\x20'+_0x23ef68));}function logWarning(_0x24a7f8){const _0xc91599=a8_0x5d5f15;console[_0xc91599(0x124)](chalk[_0xc91599(0x118)]('⚠\x20'+_0x24a7f8));}function logError(_0x1bb3f2){const _0x26d1bf=a8_0x5d5f15;console[_0x26d1bf(0x124)](chalk['red']('✗\x20'+_0x1bb3f2));}function executeCommand(_0x592801,_0x496e49,_0x2b502b={}){const _0x302e27=a8_0x5d5f15;return logInfo(_0x302e27(0x137)+_0x592801,_0x496e49?_0x302e27(0x132)+_0x496e49+']':''),child_process[_0x302e27(0x119)](_0x592801,{'cwd':_0x496e49,..._0x2b502b});}function deleteFolderRecursive(_0x440e96){const _0x4b1351=a8_0x5d5f15;fs[_0x4b1351(0x123)](_0x440e96)&&(fs[_0x4b1351(0x13b)](_0x440e96)[_0x4b1351(0x113)](_0x386144=>{const _0x4d876b=_0x4b1351,_0xe640c9=path[_0x4d876b(0x116)](_0x440e96,_0x386144);fs[_0x4d876b(0x11f)](_0xe640c9)[_0x4d876b(0x110)]()?deleteFolderRecursive(_0xe640c9):fs[_0x4d876b(0x12f)](_0xe640c9);}),fs[_0x4b1351(0x131)](_0x440e96));}function a8_0x4429(_0x46e3eb,_0x434574){const _0x5026c0=a8_0x5026();return a8_0x4429=function(_0x442941,_0x1967a9){_0x442941=_0x442941-0x108;let _0x324e5b=_0x5026c0[_0x442941];return _0x324e5b;},a8_0x4429(_0x46e3eb,_0x434574);}function fileExists(_0x4af3ee){const _0x38e33d=a8_0x5d5f15;return fs[_0x38e33d(0x123)](_0x4af3ee);}function readFile(_0x43a414,_0x4d5fbf=a8_0x5d5f15(0x10a)){return fs['readFileSync'](_0x43a414,_0x4d5fbf);}function writeFile(_0x44e262,_0x37077e,_0x125ab2=a8_0x5d5f15(0x10a)){const _0xa401cd=a8_0x5d5f15;fs[_0xa401cd(0x129)](_0x44e262,_0x37077e,_0x125ab2);}function createDir(_0x157a1c){const _0x4c6d5=a8_0x5d5f15;!fs[_0x4c6d5(0x123)](_0x157a1c)&&fs['mkdirSync'](_0x157a1c,{'recursive':!![]});}function isViteProject(_0x3bb374){const _0x1fa21f=a8_0x5d5f15;return fileExists(path[_0x1fa21f(0x116)](_0x3bb374,_0x1fa21f(0x114)))||fileExists(path[_0x1fa21f(0x116)](_0x3bb374,_0x1fa21f(0x12c)))||fileExists(path[_0x1fa21f(0x116)](_0x3bb374,_0x1fa21f(0x130)));}function validateConfig(_0x319c5c,_0x479d76){const _0x9e4945=a8_0x5d5f15,_0x29fc52=_0x479d76[_0x9e4945(0x11a)](_0x1057ff=>!_0x319c5c[_0x1057ff]);return{'isValid':_0x29fc52[_0x9e4945(0x115)]===0x0,'missingFields':_0x29fc52};}function validateEnvironment(_0x74590,_0x5511ff){const _0x37c251=a8_0x5d5f15;return _0x74590[_0x37c251(0x12b)]&&_0x74590[_0x37c251(0x12b)][_0x5511ff];}function DeleteDirAllFile(_0x56522a,_0x435828){const _0x39448b=a8_0x5d5f15;let _0x335ca0=[];fs[_0x39448b(0x123)](_0x56522a)?(_0x335ca0=fs[_0x39448b(0x13b)](_0x56522a),_0x335ca0[_0x39448b(0x113)](function(_0x489db1,_0x3c959a){const _0xf6d3=_0x39448b;let _0x2fbb3c=path['join'](_0x56522a,_0x489db1);fs[_0xf6d3(0x108)](_0x2fbb3c)[_0xf6d3(0x110)]()?DeleteDirAllFile(_0x2fbb3c):fs[_0xf6d3(0x12f)](_0x2fbb3c);}),fs['rmdirSync'](_0x56522a),_0x435828&&_0x435828()):_0x435828&&_0x435828();}function CopyFile(_0x2cd9f8,_0x26def6,_0x2569f5){const _0x18ecd5=a8_0x5d5f15,_0x41a589=path[_0x18ecd5(0x125)](_0x26def6);!fs[_0x18ecd5(0x123)](_0x41a589)&&fs['mkdirSync'](_0x41a589,{'recursive':!![]});const _0x4e05ff=fs['createReadStream'](_0x2cd9f8),_0x2aaf22=fs[_0x18ecd5(0x11e)](_0x26def6);_0x4e05ff[_0x18ecd5(0x134)](_0x2aaf22),_0x2aaf22['on']('close',function(){_0x2569f5&&_0x2569f5();}),_0x2aaf22['on'](_0x18ecd5(0x128),function(_0x439ae4){const _0x4dc80d=_0x18ecd5;logError(_0x4dc80d(0x12a)+_0x439ae4[_0x4dc80d(0x10f)]),_0x2569f5&&_0x2569f5();});}function CopyFolder(_0x224049,_0xd0c07c,_0x4b033f){const _0x481bfe=a8_0x5d5f15;!fs[_0x481bfe(0x123)](_0xd0c07c)&&fs['mkdirSync'](_0xd0c07c,{'recursive':!![]}),fs[_0x481bfe(0x117)](_0x224049,function(_0x120640,_0x4f552e){const _0x284d23=_0x481bfe;let _0x3e350c=0x0;const _0x526a29=function(){++_0x3e350c===_0x4f552e['length']&&_0x4b033f&&_0x4b033f();};if(_0x120640){_0x526a29();return;}_0x4f552e[_0x284d23(0x113)](function(_0x40f000){const _0x28081a=_0x284d23,_0x2511d3=path[_0x28081a(0x116)](_0x224049,_0x40f000),_0x2e4ee9=path[_0x28081a(0x116)](_0xd0c07c,_0x40f000);fs['stat'](_0x2511d3,function(_0x1bacff,_0x40058f){const _0x20bd8e=_0x28081a;if(_0x40058f[_0x20bd8e(0x110)]())fs[_0x20bd8e(0x12d)](_0x2e4ee9,{'recursive':!![]},function(_0x1a585a){const _0x59c213=_0x20bd8e;if(_0x1a585a){logError(_0x59c213(0x136)+_0x1a585a[_0x59c213(0x10f)]);return;}CopyFolder(_0x2511d3,_0x2e4ee9,_0x526a29);});else{const _0x7337da=fs[_0x20bd8e(0x13a)](_0x2511d3),_0x225be5=fs[_0x20bd8e(0x11e)](_0x2e4ee9);_0x7337da[_0x20bd8e(0x134)](_0x225be5),_0x225be5['on']('close',_0x526a29),_0x225be5['on'](_0x20bd8e(0x128),_0x526a29);}});}),_0x4f552e['length']===0x0&&_0x4b033f&&_0x4b033f();});}module[a8_0x5d5f15(0x138)]={'CONSTANTS':CONSTANTS,'logInfo':logInfo,'logSuccess':logSuccess,'logWarning':logWarning,'logError':logError,'executeCommand':executeCommand,'deleteFolderRecursive':deleteFolderRecursive,'fileExists':fileExists,'readFile':readFile,'writeFile':writeFile,'createDir':createDir,'isViteProject':isViteProject,'validateConfig':validateConfig,'validateEnvironment':validateEnvironment,'DeleteDirAllFile':DeleteDirAllFile,'CopyFile':CopyFile,'CopyFolder':CopyFolder};
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const child_process = require('child_process');
4
+ const chalk = require('chalk');
5
+
6
+ // 常量定义
7
+ const CONSTANTS = {
8
+ MAX_BUFFER_SIZE: 1000000000, // 1GB
9
+ SYNC_DELAY: 1000, // 1秒
10
+ DEFAULT_BRANCH: 'master',
11
+ CONFIG_FILE_NAME: 'jjb.config.js',
12
+ BUILD_OUTPUT_DIR: 'dist',
13
+ TEMPLATES_PATH: 'start/src/main/resources/templates'
14
+ };
15
+
16
+
17
+ // 日志函数
18
+ function logInfo(message, path = '') {
19
+ const prefix = chalk.blue('ℹ');
20
+ const output = path ? `${prefix} ${message} ${path}` : `${prefix} ${message}`;
21
+ console.log(output);
22
+ }
23
+
24
+ function logSuccess(message) {
25
+ console.log(chalk.green(`✓ ${message}`));
26
+ }
27
+
28
+ function logWarning(message) {
29
+ console.log(chalk.yellow(`⚠ ${message}`));
30
+ }
31
+
32
+ function logError(message) {
33
+ console.log(chalk.red(`✗ ${message}`));
34
+ }
35
+
36
+ // 统一的命令执行函数
37
+ function executeCommand(command, cwd, options = {}) {
38
+ logInfo(`执行命令: ${command}`, cwd ? `[工作目录: ${cwd}]` : '');
39
+ return child_process.execSync(command, { cwd, ...options });
40
+ }
41
+
42
+ // 文件处理函数
43
+ function deleteFolderRecursive(folderPath) {
44
+ if (fs.existsSync(folderPath)) {
45
+ fs.readdirSync(folderPath).forEach((file) => {
46
+ const curPath = path.join(folderPath, file);
47
+ if (fs.lstatSync(curPath).isDirectory()) {
48
+ // 递归删除子文件夹
49
+ deleteFolderRecursive(curPath);
50
+ } else {
51
+ // 删除文件
52
+ fs.unlinkSync(curPath);
53
+ }
54
+ });
55
+ // 删除空文件夹
56
+ fs.rmdirSync(folderPath);
57
+ }
58
+ }
59
+
60
+ // 检查文件是否存在
61
+ function fileExists(filePath) {
62
+ return fs.existsSync(filePath);
63
+ }
64
+
65
+ // 读取文件内容
66
+ function readFile(filePath, encoding = 'utf8') {
67
+ return fs.readFileSync(filePath, encoding);
68
+ }
69
+
70
+ // 写入文件内容
71
+ function writeFile(filePath, content, encoding = 'utf8') {
72
+ fs.writeFileSync(filePath, content, encoding);
73
+ }
74
+
75
+ // 创建目录
76
+ function createDir(dirPath) {
77
+ if (!fs.existsSync(dirPath)) {
78
+ fs.mkdirSync(dirPath, { recursive: true });
79
+ }
80
+ }
81
+
82
+ // 检查是否为 Vite 项目
83
+ function isViteProject(rootPath) {
84
+ return fileExists(path.join(rootPath, 'vite.config.js')) ||
85
+ fileExists(path.join(rootPath, 'vite.config.ts')) ||
86
+ fileExists(path.join(rootPath, 'vite.config.mjs'));
87
+ }
88
+
89
+ // 验证配置对象
90
+ function validateConfig(config, requiredFields) {
91
+ const missingFields = requiredFields.filter(field => !config[field]);
92
+ return {
93
+ isValid: missingFields.length === 0,
94
+ missingFields
95
+ };
96
+ }
97
+
98
+ // 验证环境配置
99
+ function validateEnvironment(config, environment) {
100
+ return config.environment && config.environment[environment];
101
+ }
102
+
103
+ /**
104
+ * @description 清空当前目录
105
+ * @param filePath
106
+ * @param callback
107
+ * @constructor
108
+ */
109
+ function DeleteDirAllFile(filePath, callback) {
110
+ let files = [];
111
+ if (fs.existsSync(filePath)) {
112
+ files = fs.readdirSync(filePath);
113
+ files.forEach(function (file, index) {
114
+ let curPath = path.join(filePath, file);
115
+ if (fs.statSync(curPath).isDirectory()) {
116
+ DeleteDirAllFile(curPath);
117
+ } else {
118
+ fs.unlinkSync(curPath);
119
+ }
120
+ });
121
+ fs.rmdirSync(filePath);
122
+ callback && callback();
123
+ } else {
124
+ callback && callback();
125
+ }
126
+ }
127
+
128
+ /**
129
+ * @description 复制单个文件
130
+ * @param srcFile
131
+ * @param tarFile
132
+ * @param cb
133
+ */
134
+ function CopyFile(srcFile, tarFile, cb) {
135
+ // 确保目标目录存在
136
+ const tarDir = path.dirname(tarFile);
137
+ if (!fs.existsSync(tarDir)) {
138
+ fs.mkdirSync(tarDir, { recursive: true });
139
+ }
140
+
141
+ const rs = fs.createReadStream(srcFile);
142
+ const ws = fs.createWriteStream(tarFile);
143
+
144
+ rs.pipe(ws);
145
+
146
+ ws.on('close', function() {
147
+ cb && cb();
148
+ });
149
+
150
+ ws.on('error', function(err) {
151
+ logError(`文件复制失败: ${err.message}`);
152
+ cb && cb();
153
+ });
154
+ }
155
+
156
+ /**
157
+ * @description 复制文件夹及子目录文件
158
+ * @param srcDir
159
+ * @param tarDir
160
+ * @param cb
161
+ */
162
+ function CopyFolder(srcDir, tarDir, cb) {
163
+ // 确保目标目录存在
164
+ if (!fs.existsSync(tarDir)) {
165
+ fs.mkdirSync(tarDir, { recursive: true });
166
+ }
167
+
168
+ fs.readdir(srcDir, function (err, files) {
169
+
170
+ let count = 0;
171
+ const checkEnd = function () {
172
+ ++count === files.length && cb && cb();
173
+ };
174
+
175
+ if (err) {
176
+ checkEnd();
177
+ return;
178
+ }
179
+
180
+ files.forEach(function (file) {
181
+ const srcPath = path.join(srcDir, file);
182
+ const tarPath = path.join(tarDir, file);
183
+
184
+ fs.stat(srcPath, function (err, stats) {
185
+ if (stats.isDirectory()) {
186
+ fs.mkdir(tarPath, { recursive: true }, function (err) {
187
+ if (err) {
188
+ logError(`创建目录失败: ${err.message}`);
189
+ return;
190
+ }
191
+
192
+ CopyFolder(srcPath, tarPath, checkEnd);
193
+ });
194
+ } else {
195
+ // 复制文件
196
+ const rs = fs.createReadStream(srcPath);
197
+ const ws = fs.createWriteStream(tarPath);
198
+ rs.pipe(ws);
199
+ ws.on('close', checkEnd);
200
+ ws.on('error', checkEnd);
201
+ }
202
+ });
203
+ });
204
+ //为空时直接回调
205
+ files.length === 0 && cb && cb();
206
+ });
207
+ }
208
+
209
+
210
+ module.exports = {
211
+ CONSTANTS,
212
+ logInfo,
213
+ logSuccess,
214
+ logWarning,
215
+ logError,
216
+ executeCommand,
217
+ deleteFolderRecursive,
218
+ fileExists,
219
+ readFile,
220
+ writeFile,
221
+ createDir,
222
+ isViteProject,
223
+ validateConfig,
224
+ validateEnvironment,
225
+ DeleteDirAllFile,
226
+ CopyFile,
227
+ CopyFolder
228
+ };