jjb-cmd 2.5.2 → 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/push.js CHANGED
@@ -1 +1,417 @@
1
- const a6_0x553c7d=a6_0x403c;function a6_0x403c(_0x50af48,_0x5bf631){const _0x1a3f99=a6_0x1a3f();return a6_0x403c=function(_0x403c0f,_0x493a7f){_0x403c0f=_0x403c0f-0x12b;let _0xe0dcf0=_0x1a3f99[_0x403c0f];return _0xe0dcf0;},a6_0x403c(_0x50af48,_0x5bf631);}(function(_0x3cb185,_0x335ea3){const _0x230384=a6_0x403c,_0x1ccef0=_0x3cb185();while(!![]){try{const _0xcd18ee=parseInt(_0x230384(0x171))/0x1+-parseInt(_0x230384(0x167))/0x2+-parseInt(_0x230384(0x146))/0x3*(parseInt(_0x230384(0x13a))/0x4)+-parseInt(_0x230384(0x13c))/0x5*(parseInt(_0x230384(0x130))/0x6)+parseInt(_0x230384(0x158))/0x7*(parseInt(_0x230384(0x154))/0x8)+-parseInt(_0x230384(0x13e))/0x9+parseInt(_0x230384(0x14a))/0xa;if(_0xcd18ee===_0x335ea3)break;else _0x1ccef0['push'](_0x1ccef0['shift']());}catch(_0x4848bd){_0x1ccef0['push'](_0x1ccef0['shift']());}}}(a6_0x1a3f,0xb3dbc));const os=require('os'),path=require(a6_0x553c7d(0x141)),{CopyFolder,DeleteDirAllFile}=require('./utils'),{GIT_TEMP_JAVA,getApiHost}=require('./config'),axios=require(a6_0x553c7d(0x16c)),{CONSTANTS,logInfo,logSuccess,logWarning,logError,executeCommand,deleteFolderRecursive,fileExists,readFile,writeFile,createDir,isViteProject,validateConfig,validateEnvironment}=require(a6_0x553c7d(0x132)),{loadAuth}=require(a6_0x553c7d(0x15c));module[a6_0x553c7d(0x13b)]=arguments=>{const _0x3f3f89=a6_0x553c7d;arguments[_0x3f3f89(0x138)]<0x2&&(logError(_0x3f3f89(0x139)),process[_0x3f3f89(0x165)](0x1));let _0x3fb7a6=null;const _0x156cde=path[_0x3f3f89(0x144)](__dirname,_0x3f3f89(0x152));!fileExists(_0x156cde)&&(logError(_0x3f3f89(0x162)),process['exit'](0x1));let _0x5b2dda,_0x3d2695;try{const _0x3a803f=loadAuth(_0x156cde);_0x5b2dda=_0x3a803f[_0x3f3f89(0x14f)],_0x3d2695=_0x3a803f[_0x3f3f89(0x145)];}catch(_0xe6d7f2){logError(_0x3f3f89(0x16d)+_0xe6d7f2[_0x3f3f89(0x163)]),process['exit'](0x1);}const _0x474606=arguments[0x1],_0x527981=arguments[0x2]||_0x3f3f89(0x131),_0x44a917=arguments[0x3]?arguments[0x3][_0x3f3f89(0x137)]('-'):[],_0x37572d=path[_0x3f3f89(0x136)]('./'),_0x4a5d9a=path[_0x3f3f89(0x144)](_0x37572d,CONSTANTS[_0x3f3f89(0x13d)]),_0x217702=path[_0x3f3f89(0x144)](_0x37572d,CONSTANTS[_0x3f3f89(0x161)]),_0x284113=os[_0x3f3f89(0x160)]();logInfo(_0x3f3f89(0x153)),axios[_0x3f3f89(0x13f)](getApiHost()+_0x3f3f89(0x16a),{'username':_0x5b2dda,'password':_0x3d2695})[_0x3f3f89(0x15b)](async _0x25099c=>{const _0x300d00=_0x3f3f89;if(_0x25099c[_0x300d00(0x12c)][_0x300d00(0x15f)]){logSuccess(_0x300d00(0x142));if(!fileExists(_0x4a5d9a))logError('当前应用中不存在\x22jjb.config.json\x22文件!'),process[_0x300d00(0x165)](0x1);else{let _0x290896;_0x290896=require(_0x4a5d9a),_0x290896=_0x290896[_0x300d00(0x12d)]?_0x290896['default']:_0x290896;const _0x3e2067=[_0x300d00(0x14c),_0x300d00(0x14b),'appIdentifier'],_0x11838a=validateConfig(_0x290896,_0x3e2067);!_0x11838a[_0x300d00(0x12e)]&&(logError(_0x300d00(0x169)+_0x11838a['missingFields']['join'](',\x20')),process[_0x300d00(0x165)](0x1));!validateEnvironment(_0x290896,_0x474606)&&(logError(_0x300d00(0x164)+_0x474606+']!'),process[_0x300d00(0x165)](0x1));const _0x553301=GIT_TEMP_JAVA+'-'+Date[_0x300d00(0x15e)]()+'-'+Math[_0x300d00(0x12b)]()['toString'](0x24)[_0x300d00(0x143)](0x2,0x9);_0x3fb7a6=_0x553301;const _0x3f3cce=path['join'](_0x284113,_0x553301);fileExists(_0x3f3cce)&&deleteFolderRecursive(_0x3f3cce);createDir(_0x3f3cce);const _0x336431=path[_0x300d00(0x144)](_0x3f3cce,_0x290896[_0x300d00(0x14b)]);fileExists(_0x336431)?_0x44a917[_0x300d00(0x16f)](_0x300d00(0x14e))?DeleteDirAllFile(_0x336431,()=>{const _0x4f847e=_0x300d00;executeCommand(_0x4f847e(0x174)+_0x290896[_0x4f847e(0x14c)],_0x3f3cce);}):executeCommand(_0x300d00(0x174)+_0x290896[_0x300d00(0x14c)],_0x3f3cce):executeCommand(_0x300d00(0x174)+_0x290896[_0x300d00(0x14c)],_0x3f3cce),_0x5bddae(_0x3f3cce,_0x290896,_0x553301);}}else logError(_0x300d00(0x149)),process[_0x300d00(0x165)](0x1);})[_0x3f3f89(0x16e)](_0x484b03=>{const _0x23ea7=_0x3f3f89;logError(_0x23ea7(0x168)+_0x484b03['message']),process[_0x23ea7(0x165)](0x1);}),process['on'](_0x3f3f89(0x165),()=>{const _0x59dfb3=_0x3f3f89;if(_0x3fb7a6){const _0x529d61=path[_0x59dfb3(0x144)](os[_0x59dfb3(0x160)](),_0x3fb7a6);if(fileExists(_0x529d61))try{deleteFolderRecursive(_0x529d61);}catch(_0x3aec3c){}}}),process['on'](_0x3f3f89(0x150),_0x41a4a7=>{const _0x4c74ff=_0x3f3f89;if(_0x3fb7a6){const _0x5544b0=path[_0x4c74ff(0x144)](os['tmpdir'](),_0x3fb7a6);if(fileExists(_0x5544b0))try{deleteFolderRecursive(_0x5544b0);}catch(_0x19e804){}}throw _0x41a4a7;});function _0x5bddae(_0x5cfdc7,_0x16351a,_0x222e3c){const _0x660fd1=_0x3f3f89,_0x1dd292=_0x16351a[_0x660fd1(0x172)][_0x474606],_0x422e90=path[_0x660fd1(0x144)](_0x5cfdc7,_0x16351a[_0x660fd1(0x14b)]);!_0x1dd292[_0x660fd1(0x155)]&&logWarning(_0x660fd1(0x166)+_0x474606+_0x660fd1(0x147));executeCommand(_0x660fd1(0x15a),_0x422e90);!fileExists(path[_0x660fd1(0x144)](_0x37572d,'node_modules'))&&(logWarning(_0x660fd1(0x16b)),executeCommand('yarn',_0x37572d),logSuccess(_0x660fd1(0x140)));const _0x492888=isViteProject(_0x37572d);_0x492888?(logInfo(_0x660fd1(0x156)),executeCommand(_0x660fd1(0x15d),_0x37572d,{'maxBuffer':CONSTANTS[_0x660fd1(0x12f)]})):(logInfo('项目为Webpack项目,即将进行应用打包\x20[Env#'+_0x474606+']\x20请稍等!'),executeCommand('yarn\x20build:'+_0x474606,_0x37572d,{'maxBuffer':CONSTANTS[_0x660fd1(0x12f)]}));logSuccess(_0x660fd1(0x170));if(fileExists(_0x217702)){const _0x2671b2=_0x16351a[_0x660fd1(0x157)],_0xd2d467=readFile(path['join'](_0x217702,_0x660fd1(0x151)));_0x44a917[_0x660fd1(0x16f)](_0x660fd1(0x135))?writeFile(path[_0x660fd1(0x144)](_0x217702,_0x660fd1(0x151)),_0xd2d467):writeFile(path['join'](_0x217702,_0x2671b2+_0x660fd1(0x134)),_0xd2d467);const _0x54f2c6=path[_0x660fd1(0x144)](_0x422e90,CONSTANTS['TEMPLATES_PATH']);createDir(_0x54f2c6);const _0x294011=_0x1dd292[_0x660fd1(0x155)]?_0x1dd292[_0x660fd1(0x155)]:CONSTANTS['DEFAULT_BRANCH'];executeCommand(_0x660fd1(0x133)+_0x294011,_0x422e90);const _0x3cfe6c=path[_0x660fd1(0x144)](_0x54f2c6,_0x16351a[_0x660fd1(0x157)]);DeleteDirAllFile(_0x3cfe6c,()=>{const _0x4b5187=_0x660fd1;createDir(_0x3cfe6c),writeFile(path[_0x4b5187(0x144)](_0x54f2c6,_0x2671b2+_0x4b5187(0x134)),_0xd2d467),CopyFolder(path[_0x4b5187(0x144)](_0x217702,_0x16351a[_0x4b5187(0x157)]),_0x3cfe6c,()=>{setTimeout(()=>{const _0xd199bc=a6_0x403c;executeCommand(_0xd199bc(0x15a),_0x422e90),executeCommand(_0xd199bc(0x148),_0x422e90);try{executeCommand('git\x20commit\x20-m\x20'+_0x527981+'\x20--no-verify',_0x422e90);}catch(_0x2b31a5){logWarning('Git\x20commit\x20失败,可能没有变更需要提交:\x20'+_0x2b31a5[_0xd199bc(0x163)]);}executeCommand(_0xd199bc(0x14d),_0x422e90),setTimeout(()=>{const _0x375133=_0xd199bc,_0x264f4b=path[_0x375133(0x144)](os[_0x375133(0x160)](),_0x222e3c);if(fileExists(_0x264f4b))try{deleteFolderRecursive(_0x264f4b),logInfo('临时文件夹已清理:\x20'+_0x222e3c);}catch(_0x44493f){logWarning('清理临时文件夹失败:\x20'+_0x44493f[_0x375133(0x163)]);}},CONSTANTS['SYNC_DELAY']*0x2);},CONSTANTS['SYNC_DELAY']);});});}else{logError(_0x660fd1(0x159));const _0x494af2=path[_0x660fd1(0x144)](os[_0x660fd1(0x160)](),_0x222e3c);if(fileExists(_0x494af2))try{deleteFolderRecursive(_0x494af2),logInfo(_0x660fd1(0x173)+_0x222e3c);}catch(_0x1ea446){logWarning('清理临时文件夹失败:\x20'+_0x1ea446[_0x660fd1(0x163)]);}process[_0x660fd1(0x165)](0x1);}}};function a6_0x1a3f(){const _0x26df1b=['git\x20checkout\x20','.html','index','resolve','split','length','命令参数传递错误!','4sdfWHA','exports','2840xtpcHV','CONFIG_FILE_NAME','1993221dqtTft','post','应用依赖安装完成!','path','Auth:\x20授权成功!','substr','join','password','922371RGbFiD',']\x20未配置\x22javaGitBranch\x22,将使用默认分支\x22master\x22!','git\x20add\x20.','授权失败!','2025280MIUVmu','javaGitName','javaGit','git\x20push','force','username','uncaughtException','index.html','../.auth','Auth:\x20正在获取授权!','1424krcwTp','javaGitBranch','项目为Vite项目,即将执行yarn\x20run\x20build命令','appIdentifier','11886vIRqEy','未知错误,未找到\x22dist\x22目录!','git\x20pull','then','./crypto-utils','yarn\x20run\x20build','now','status','tmpdir','BUILD_OUTPUT_DIR','请先登录!','message','未找到环境配置\x20[','exit','当前打包\x20[Env#','287830XhVSIz','未知错误!','\x22jjb.config.json\x22中缺少必要字段:\x20','/api/auth','当前应用未安装依赖!即将执行依赖安装命令,请稍等!','axios','读取认证信息失败!','catch','includes','应用打包完成!','1176273kFSSFU','environment','临时文件夹已清理:\x20','git\x20clone\x20','random','data','__esModule','isValid','MAX_BUFFER_SIZE','2868OGofum','\x22no\x20message\x22','./utils'];a6_0x1a3f=function(){return _0x26df1b;};return a6_0x1a3f();}
1
+ const os = require('os');
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+ const inquirer = require('inquirer');
5
+ const {
6
+ CopyFolder,
7
+ DeleteDirAllFile
8
+ } = require('./utils');
9
+ const {
10
+ GIT_TEMP_JAVA,
11
+ getApiHost
12
+ } = require('./config');
13
+ const axios = require('axios');
14
+ const {
15
+ CONSTANTS,
16
+ logInfo,
17
+ logSuccess,
18
+ logWarning,
19
+ logError,
20
+ executeCommand,
21
+ deleteFolderRecursive,
22
+ fileExists,
23
+ readFile,
24
+ writeFile,
25
+ createDir,
26
+ isViteProject,
27
+ validateConfig
28
+ } = require('./utils');
29
+ const { loadAuth } = require('./crypto-utils');
30
+
31
+ module.exports = async arguments => {
32
+
33
+ // 存储当前任务的临时文件夹名称,用于进程退出时清理
34
+ let currentTempDir = null;
35
+
36
+ const authPath = path.join(__dirname, '../.auth');
37
+
38
+ if (!fileExists(authPath)) {
39
+ logError('未检测到认证信息,请先执行登录操作');
40
+ process.exit(1);
41
+ }
42
+
43
+ // 安全读取认证信息
44
+ let username, password;
45
+ try {
46
+ logInfo('正在加载认证信息...');
47
+ const authData = loadAuth(authPath);
48
+ username = authData.username;
49
+ password = authData.password;
50
+ logSuccess('认证信息加载成功');
51
+ } catch (error) {
52
+ logError(`读取认证信息失败: ${error.message}`);
53
+ process.exit(1);
54
+ }
55
+
56
+ /**
57
+ * 更多参数
58
+ * @type {*|*[]}
59
+ */
60
+ const parameter = arguments[ 1 ]
61
+ ? arguments[ 1 ].split('-')
62
+ : [];
63
+
64
+ /**
65
+ * 当前根路径
66
+ * @type {Promise<void> | Promise<string>}
67
+ */
68
+ const root_path = path.resolve('./');
69
+
70
+ /**
71
+ * package.json 路径
72
+ * @type {string}
73
+ */
74
+ const package_json_path = path.join(root_path, 'package.json');
75
+
76
+ /**
77
+ * jjb配置文件路径
78
+ * @type {string}
79
+ */
80
+ const config_json_path = path.join(root_path, CONSTANTS.CONFIG_FILE_NAME);
81
+
82
+ /**
83
+ * 打包输出目录
84
+ * @type {string}
85
+ */
86
+ const build_output_dir = path.join(root_path, CONSTANTS.BUILD_OUTPUT_DIR);
87
+
88
+ /**
89
+ * 临时目录
90
+ */
91
+ const tmpdir = os.tmpdir();
92
+
93
+ // 读取 package.json 并筛选打包命令
94
+ logInfo('正在检查项目配置文件...');
95
+ if (!fileExists(package_json_path)) {
96
+ logError('未找到 package.json 文件');
97
+ process.exit(1);
98
+ }
99
+
100
+ let packageJson;
101
+ try {
102
+ packageJson = JSON.parse(fs.readFileSync(package_json_path, 'utf8'));
103
+ logSuccess('package.json 读取成功');
104
+ } catch (error) {
105
+ logError(`解析 package.json 失败: ${error.message}`);
106
+ process.exit(1);
107
+ }
108
+
109
+ const scripts = packageJson.scripts || {};
110
+
111
+ // 筛选打包相关的命令(只判断键名,包含 build、compile、打包等关键字)
112
+ const buildKeywords = ['build'];
113
+ const buildScripts = Object.keys(scripts).filter(key => {
114
+ return buildKeywords.some(keyword =>
115
+ key.toLowerCase().includes(keyword)
116
+ );
117
+ });
118
+
119
+ if (buildScripts.length === 0) {
120
+ logError('未找到打包相关的命令,请检查 package.json 中的 scripts 配置');
121
+ process.exit(1);
122
+ }
123
+
124
+ // 使用 inquirer 让用户选择打包命令
125
+ const { selectedScript } = await inquirer.prompt([
126
+ {
127
+ type: 'list',
128
+ name: 'selectedScript',
129
+ message: '请选择要执行的打包命令:',
130
+ choices: buildScripts.map(script => ({
131
+ name: `${script} (${scripts[script]})`,
132
+ value: script
133
+ }))
134
+ }
135
+ ]);
136
+
137
+ logInfo(`已选择打包命令: ${selectedScript}`);
138
+
139
+ // 读取 jjb.config.json 以获取 environment 配置
140
+ logInfo('正在检查项目配置文件...');
141
+ if (!fileExists(config_json_path)) {
142
+ logError('未找到 jjb.config.json 文件');
143
+ process.exit(1);
144
+ }
145
+
146
+ // 支持 ESM 和 CJS 模块导入
147
+ let jjbConfig;
148
+ try {
149
+ // 如果 ESM 导入失败,回退到 require
150
+ jjbConfig = require(config_json_path);
151
+ jjbConfig = jjbConfig.__esModule ? jjbConfig.default : jjbConfig;
152
+ logSuccess('jjb.config.json 读取成功');
153
+ } catch (error) {
154
+ logError(`解析 jjb.config.json 失败: ${error.message}`);
155
+ process.exit(1);
156
+ }
157
+
158
+ // 验证必要的配置字段
159
+ const requiredFields = ['javaGit', 'javaGitName', 'appIdentifier'];
160
+ const configValidation = validateConfig(jjbConfig, requiredFields);
161
+
162
+ if (!configValidation.isValid) {
163
+ logError(`配置文件中缺少必要字段: ${configValidation.missingFields.join(', ')}`);
164
+ process.exit(1);
165
+ }
166
+
167
+ // 选择 environment
168
+ let selectedEnvType = null;
169
+ if (jjbConfig.environment && typeof jjbConfig.environment === 'object') {
170
+ const envKeys = Object.keys(jjbConfig.environment);
171
+ if (envKeys.length > 0) {
172
+ const { envType } = await inquirer.prompt([
173
+ {
174
+ type: 'list',
175
+ name: 'envType',
176
+ message: '请选择环境:',
177
+ choices: envKeys.map(key => ({
178
+ name: key,
179
+ value: key
180
+ }))
181
+ }
182
+ ]);
183
+ selectedEnvType = envType;
184
+ logInfo(`已选择环境: ${selectedEnvType}`);
185
+ } else {
186
+ logWarning('environment 配置为空,将使用默认分支');
187
+ }
188
+ } else {
189
+ logWarning('未找到 environment 配置,将使用默认分支');
190
+ }
191
+
192
+ logInfo('正在请求服务器授权...');
193
+ axios.post(`${getApiHost()}/api/auth`, {
194
+ username,
195
+ password
196
+ }).then(async res => {
197
+ if (res.data.status) {
198
+ logSuccess('服务器授权成功');
199
+
200
+ // 为每个打包任务创建唯一的临时文件夹
201
+ const uniqueTempDir = `${GIT_TEMP_JAVA}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
202
+ currentTempDir = uniqueTempDir; // 存储当前临时文件夹名称
203
+ const tempGit = path.join(tmpdir, uniqueTempDir);
204
+
205
+ logInfo('正在准备临时工作目录...');
206
+ if (fileExists(tempGit)) {
207
+ deleteFolderRecursive(tempGit);
208
+ }
209
+
210
+ createDir(tempGit);
211
+ logSuccess('临时工作目录已创建');
212
+
213
+ const projectDir = path.join(tempGit, jjbConfig.javaGitName);
214
+
215
+ logInfo('正在克隆 Git 仓库...');
216
+ if (fileExists(projectDir)) {
217
+ if (parameter.includes('force')) {
218
+ logInfo('检测到已存在的仓库,正在强制清理...');
219
+ DeleteDirAllFile(projectDir, () => {
220
+ executeCommand(`git clone ${jjbConfig.javaGit}`, tempGit);
221
+ logSuccess('Git 仓库克隆完成');
222
+ });
223
+ } else {
224
+ executeCommand(`git clone ${jjbConfig.javaGit}`, tempGit);
225
+ logSuccess('Git 仓库克隆完成');
226
+ }
227
+ } else {
228
+ executeCommand(`git clone ${jjbConfig.javaGit}`, tempGit);
229
+ logSuccess('Git 仓库克隆完成');
230
+ }
231
+
232
+ project_sync(tempGit, jjbConfig, uniqueTempDir, selectedScript, selectedEnvType);
233
+ } else {
234
+ logError(`授权失败: ${res.data.message || '未知错误'}`);
235
+ process.exit(1);
236
+ }
237
+ }).catch(e => {
238
+ if (e && e.response) {
239
+ const status = e.response.status;
240
+ if (status === 401 || status === 403) {
241
+ logError(`授权失败 (${status}): 认证信息无效或无权限`);
242
+ } else {
243
+ logError(`请求失败 (${status}): ${e.response.data?.message || e.message}`);
244
+ }
245
+ } else if (e && e.request) {
246
+ logError(`网络连接失败: 无法连接到服务器`);
247
+ } else {
248
+ logError(`操作失败: ${e.message || '未知错误'}`);
249
+ }
250
+ process.exit(1);
251
+ });
252
+
253
+ // 进程退出时清理临时文件夹
254
+ process.on('exit', () => {
255
+ if (currentTempDir) {
256
+ const tempDirToClean = path.join(os.tmpdir(), currentTempDir);
257
+ if (fileExists(tempDirToClean)) {
258
+ try {
259
+ deleteFolderRecursive(tempDirToClean);
260
+ } catch (e) {
261
+ // 静默处理清理失败的情况
262
+ }
263
+ }
264
+ }
265
+ });
266
+
267
+ // 处理未捕获的异常
268
+ process.on('uncaughtException', (error) => {
269
+ if (currentTempDir) {
270
+ const tempDirToClean = path.join(os.tmpdir(), currentTempDir);
271
+ if (fileExists(tempDirToClean)) {
272
+ try {
273
+ deleteFolderRecursive(tempDirToClean);
274
+ } catch (e) {
275
+ // 静默处理清理失败的情况
276
+ }
277
+ }
278
+ }
279
+ throw error;
280
+ });
281
+
282
+ /**
283
+ * 应用git同步
284
+ */
285
+ function project_sync(tempGit, jjbConfig, uniqueTempDir, buildScript, envType) {
286
+ const projectDir = path.join(tempGit, jjbConfig.javaGitName);
287
+
288
+ logInfo('正在同步 Git 仓库最新代码...');
289
+ executeCommand(`git pull`, projectDir);
290
+ logSuccess('代码同步完成');
291
+
292
+ if (!fileExists(path.join(root_path, 'node_modules'))) {
293
+ logWarning('检测到未安装项目依赖');
294
+ logInfo('正在安装项目依赖,请稍候...');
295
+ executeCommand(`yarn`, root_path);
296
+ logSuccess('项目依赖安装完成');
297
+ } else {
298
+ logInfo('项目依赖检查通过');
299
+ }
300
+
301
+ try {
302
+ logInfo(`正在执行构建命令: yarn run ${buildScript}`);
303
+ executeCommand(`yarn run ${buildScript}`, root_path, { maxBuffer: CONSTANTS.MAX_BUFFER_SIZE });
304
+ logSuccess('项目构建完成');
305
+ } catch (e) {
306
+ logError(`项目构建失败: ${e.message}`);
307
+ // 清理临时文件夹
308
+ const tempDirToClean = path.join(os.tmpdir(), uniqueTempDir);
309
+ if (fileExists(tempDirToClean)) {
310
+ try {
311
+ deleteFolderRecursive(tempDirToClean);
312
+ logInfo(`临时工作目录已清理: ${uniqueTempDir}`);
313
+ } catch (err) {
314
+ logWarning(`清理临时目录失败: ${err.message}`);
315
+ }
316
+ }
317
+ process.exit(1);
318
+ }
319
+
320
+ if (fileExists(build_output_dir)) {
321
+ logInfo('正在处理构建产物...');
322
+ const appIdentifier = jjbConfig.appIdentifier;
323
+ const indexContent = readFile(path.join(build_output_dir, 'index.html'));
324
+
325
+ if (parameter.includes('index')) {
326
+ writeFile(path.join(build_output_dir, 'index.html'), indexContent);
327
+ logInfo('已生成 index.html 文件');
328
+ } else {
329
+ writeFile(path.join(build_output_dir, `${appIdentifier}.html`), indexContent);
330
+ logInfo(`已生成 ${appIdentifier}.html 文件`);
331
+ }
332
+
333
+ const tempJavaPath = path.join(projectDir, CONSTANTS.TEMPLATES_PATH);
334
+
335
+ logInfo('正在创建模板目录...');
336
+ createDir(tempJavaPath);
337
+
338
+ // 从选择的 environment 中获取分支,如果没有则使用默认分支
339
+ const javaGitBranch = (envType && jjbConfig.environment && jjbConfig.environment[envType] && jjbConfig.environment[envType].javaGitBranch)
340
+ ? jjbConfig.environment[envType].javaGitBranch
341
+ : CONSTANTS.DEFAULT_BRANCH;
342
+
343
+ logInfo(`正在切换到目标分支: ${javaGitBranch}`);
344
+ executeCommand(`git checkout ${javaGitBranch}`, projectDir);
345
+ logSuccess('分支切换完成');
346
+
347
+ const projectJavaPath = path.join(tempJavaPath, jjbConfig.appIdentifier);
348
+
349
+ logInfo('正在清理目标目录...');
350
+ DeleteDirAllFile(projectJavaPath, () => {
351
+ createDir(projectJavaPath);
352
+ logInfo('正在复制构建产物到目标目录...');
353
+ writeFile(path.join(tempJavaPath, `${appIdentifier}.html`), indexContent);
354
+
355
+ CopyFolder(path.join(build_output_dir, jjbConfig.appIdentifier), projectJavaPath, async () => {
356
+ logSuccess('构建产物复制完成');
357
+ setTimeout(async () => {
358
+ logInfo('正在同步远程仓库...');
359
+ executeCommand(`git pull`, projectDir);
360
+ logInfo('正在添加文件变更...');
361
+ executeCommand(`git add .`, projectDir);
362
+
363
+ // 提示用户输入提交信息
364
+ const { commitMessage: inputMessage } = await inquirer.prompt([
365
+ {
366
+ type: 'input',
367
+ name: 'commitMessage',
368
+ message: '请输入提交信息:',
369
+ default: 'no message'
370
+ }
371
+ ]);
372
+ const commitMessage = inputMessage.trim() || 'no message';
373
+
374
+ try {
375
+ logInfo('正在提交代码变更...');
376
+ executeCommand(`git commit -m "${commitMessage}" --no-verify`, projectDir);
377
+ logSuccess('代码提交成功');
378
+ } catch (e) {
379
+ logWarning(`代码提交跳过: 没有需要提交的变更`);
380
+ }
381
+
382
+ logInfo('正在推送代码到远程仓库...');
383
+ executeCommand(`git push`, projectDir);
384
+ logSuccess('代码推送完成');
385
+
386
+ // 清理临时文件夹
387
+ setTimeout(() => {
388
+ logInfo('正在清理临时工作目录...');
389
+ const tempDirToClean = path.join(os.tmpdir(), uniqueTempDir);
390
+ if (fileExists(tempDirToClean)) {
391
+ try {
392
+ deleteFolderRecursive(tempDirToClean);
393
+ logSuccess(`临时工作目录已清理: ${uniqueTempDir}`);
394
+ } catch (e) {
395
+ logWarning(`清理临时目录失败: ${e.message}`);
396
+ }
397
+ }
398
+ }, CONSTANTS.SYNC_DELAY * 2); // 延迟清理,确保git操作完成
399
+ }, CONSTANTS.SYNC_DELAY);
400
+ });
401
+ });
402
+ } else {
403
+ logError('构建产物目录不存在,请检查构建输出配置');
404
+ // 清理临时文件夹
405
+ const tempDirToClean = path.join(os.tmpdir(), uniqueTempDir);
406
+ if (fileExists(tempDirToClean)) {
407
+ try {
408
+ deleteFolderRecursive(tempDirToClean);
409
+ logInfo(`临时工作目录已清理: ${uniqueTempDir}`);
410
+ } catch (e) {
411
+ logWarning(`清理临时目录失败: ${e.message}`);
412
+ }
413
+ }
414
+ process.exit(1);
415
+ }
416
+ }
417
+ };
package/src/rm-rf.js CHANGED
@@ -1 +1,49 @@
1
- const a7_0x4153c2=a7_0x4bbc;function a7_0x26e2(){const _0x9a75b6=['是否确认删除?删除后不可恢复![y/n]:','6294bSNFQk','3LuqxwO','删除过程中发生错误:','删除完成。','./utils','52692lYJksA','1598373OdDPQk','exports','8199dVxbho','290AyhRpP','resolve','toLowerCase','869ZONSGo','38trRouf','1569140IuZDuS','trim','1374FMougp','664naOsax','⚠️\x20\x20删除后不可恢复,请谨慎操作!','readline','453404CXvAYG','exit','message','开始删除操作...','正在计算项目数,请稍等...','createInterface','stdin'];a7_0x26e2=function(){return _0x9a75b6;};return a7_0x26e2();}(function(_0x18182a,_0x2b5248){const _0x9532bb=a7_0x4bbc,_0x59eca7=_0x18182a();while(!![]){try{const _0x4950c0=parseInt(_0x9532bb(0x100))/0x1*(-parseInt(_0x9532bb(0xe7))/0x2)+parseInt(_0x9532bb(0xf4))/0x3*(-parseInt(_0x9532bb(0xeb))/0x4)+parseInt(_0x9532bb(0xfc))/0x5*(-parseInt(_0x9532bb(0xf3))/0x6)+-parseInt(_0x9532bb(0xf9))/0x7+parseInt(_0x9532bb(0xe8))/0x8*(parseInt(_0x9532bb(0xfb))/0x9)+parseInt(_0x9532bb(0xe5))/0xa+-parseInt(_0x9532bb(0xff))/0xb*(-parseInt(_0x9532bb(0xf8))/0xc);if(_0x4950c0===_0x2b5248)break;else _0x59eca7['push'](_0x59eca7['shift']());}catch(_0xd8437e){_0x59eca7['push'](_0x59eca7['shift']());}}}(a7_0x26e2,0x24cfa));const path=require('path'),readline=require(a7_0x4153c2(0xea)),{logInfo,logSuccess,logError,logWarning,deleteFolderRecursive}=require(a7_0x4153c2(0xf7)),io=readline[a7_0x4153c2(0xf0)]({'input':process[a7_0x4153c2(0xf1)],'output':process['stdout']});function a7_0x4bbc(_0x5bf39b,_0x3cb0ae){const _0x26e210=a7_0x26e2();return a7_0x4bbc=function(_0x4bbc07,_0x4519bd){_0x4bbc07=_0x4bbc07-0xe5;let _0x56d5b9=_0x26e210[_0x4bbc07];return _0x56d5b9;},a7_0x4bbc(_0x5bf39b,_0x3cb0ae);}module[a7_0x4153c2(0xfa)]=function(){const _0x4a7a48=a7_0x4153c2,_0x5c9c43=path[_0x4a7a48(0xfd)]('./');logWarning('⚠️\x20\x20危险操作:此命令将删除当前目录下的所有文件和文件夹!'),logWarning(_0x4a7a48(0xe9)),io['question'](_0x4a7a48(0xf2),function(_0x1e8154){const _0x34169c=_0x4a7a48,_0x4ab44b=_0x1e8154[_0x34169c(0xe6)]()[_0x34169c(0xfe)]();if(_0x4ab44b==='y'||_0x4ab44b==='yes')logInfo(_0x34169c(0xef)),setTimeout(()=>{const _0x24e6ac=_0x34169c;try{logInfo(_0x24e6ac(0xee)),deleteFolderRecursive(_0x5c9c43),logSuccess(_0x24e6ac(0xf6)),process[_0x24e6ac(0xec)](0x0);}catch(_0x18312d){logError(_0x24e6ac(0xf5)+_0x18312d[_0x24e6ac(0xed)]),process[_0x24e6ac(0xec)](0x1);}},0x3e8);else _0x4ab44b==='n'||_0x4ab44b==='no'?(logInfo('取消删除。'),process['exit'](0x0)):(logError('无效操作,请输入\x20y\x20或\x20n。'),process['exit'](0x1));});};
1
+ const path = require('path');
2
+ const inquirer = require('inquirer');
3
+ const {
4
+ logInfo,
5
+ logSuccess,
6
+ logError,
7
+ logWarning,
8
+ deleteFolderRecursive
9
+ } = require('./utils');
10
+
11
+ /**
12
+ * 递归删除目录模块
13
+ * 危险操作:删除当前目录下的所有文件和文件夹
14
+ */
15
+ module.exports = async function () {
16
+ const rootPath = path.resolve('./');
17
+
18
+ logWarning('危险操作:此命令将删除当前目录下的所有文件和文件夹');
19
+ logWarning('删除后不可恢复,请谨慎操作');
20
+
21
+ const { confirm } = await inquirer.prompt([
22
+ {
23
+ type: 'confirm',
24
+ name: 'confirm',
25
+ message: '是否确认删除?删除后不可恢复!',
26
+ default: false
27
+ }
28
+ ]);
29
+
30
+ if (confirm) {
31
+ logInfo('正在扫描目录结构...');
32
+
33
+ setTimeout(() => {
34
+ try {
35
+ logInfo('开始执行删除操作...');
36
+ deleteFolderRecursive(rootPath);
37
+ logSuccess('所有文件已成功删除');
38
+ process.exit(0);
39
+ } catch (error) {
40
+ logError(`删除操作失败: ${error.message}`);
41
+ process.exit(1);
42
+ }
43
+ }, 1000);
44
+ } else {
45
+ logInfo('操作已取消');
46
+ process.exit(0);
47
+ }
48
+ };
49
+