jjb-cmd 2.5.8 → 2.6.0
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/package.json +1 -1
- package/src/ai-pull.js +1 -715
- package/src/auth.js +1 -71
- package/src/code-optimization.js +1 -46
- package/src/config.js +1 -122
- package/src/crypto-utils.js +1 -183
- package/src/password-input.js +1 -79
- package/src/publish.js +1 -307
- package/src/push.js +1 -417
- package/src/rm-rf.js +1 -49
- package/src/utils.js +1 -228
- package/SECURITY.md +0 -71
- package/build.js +0 -20
- package/obf.config.json +0 -3
package/src/push.js
CHANGED
|
@@ -1,417 +1 @@
|
|
|
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
|
-
};
|
|
1
|
+
const a7_0x10b04b=a7_0x3525;(function(_0x3369e8,_0x233974){const _0x34bb2f=a7_0x3525,_0x4e3d29=_0x3369e8();while(!![]){try{const _0x44b420=-parseInt(_0x34bb2f(0x157))/0x1+parseInt(_0x34bb2f(0x120))/0x2*(parseInt(_0x34bb2f(0x140))/0x3)+-parseInt(_0x34bb2f(0x12e))/0x4*(parseInt(_0x34bb2f(0xf5))/0x5)+parseInt(_0x34bb2f(0x113))/0x6*(parseInt(_0x34bb2f(0x148))/0x7)+-parseInt(_0x34bb2f(0x11e))/0x8+parseInt(_0x34bb2f(0x159))/0x9*(-parseInt(_0x34bb2f(0xed))/0xa)+parseInt(_0x34bb2f(0x152))/0xb;if(_0x44b420===_0x233974)break;else _0x4e3d29['push'](_0x4e3d29['shift']());}catch(_0x52f298){_0x4e3d29['push'](_0x4e3d29['shift']());}}}(a7_0x4d38,0x7cf8a));function a7_0x4d38(){const _0x1af951=['4hbGHzI','response','请求失败\x20(','代码提交成功','username','未找到\x20jjb.config.json\x20文件','map','配置文件中缺少必要字段:\x20','BUILD_OUTPUT_DIR','正在克隆\x20Git\x20仓库...','Git\x20仓库克隆完成','scripts','代码提交跳过:\x20没有需要提交的变更','yarn','404gAeyeT','javaGit','已选择环境:\x20','已生成\x20index.html\x20文件','.html\x20文件','node_modules','trim','正在复制构建产物到目标目录...','正在处理构建产物...','已选择打包命令:\x20','正在提交代码变更...','some','正在同步远程仓库...','解析\x20jjb.config.json\x20失败:\x20','javaGitName','git\x20add\x20.','正在推送代码到远程仓库...','index.html','1091319nWeVKc','appIdentifier','临时工作目录已清理:\x20','git\x20commit\x20-m\x20\x22','./utils','已生成\x20','prompt','uncaughtException','212485ccBkaW','package.json\x20读取成功','keys','list','分支切换完成','git\x20pull','未找到\x20environment\x20配置,将使用默认分支','git\x20checkout\x20','项目构建失败:\x20','正在添加文件变更...','18034027PGxfiz','操作失败:\x20','正在执行构建命令:\x20','读取认证信息失败:\x20','then','336828tSkAsP','index','811494LrDSWI','jjb.config.json\x20读取成功','length','axios','now','认证信息加载成功','toString','npm\x20run\x20','检测到未安装项目依赖','environment\x20配置为空,将使用默认分支','构建产物复制完成','TEMPLATES_PATH','utf8','未知错误','tmpdir','object','yarn\x20run\x20','未检测到认证信息,请先执行登录操作','110bnHjGx','git\x20push','readFileSync','force','path','npm','未找到\x20package.json\x20文件','请选择要执行的打包命令:','20185zDNgJn','yarn.lock','临时工作目录已创建','正在加载认证信息...','npm\x20install','授权失败\x20(','git\x20clone\x20','正在清理临时工作目录...','授权失败:\x20','default','项目依赖检查通过','正在准备临时工作目录...','正在请求服务器授权...','__esModule','exit','./crypto-utils','CONFIG_FILE_NAME','SYNC_DELAY','未找到打包相关的命令,请检查\x20package.json\x20中的\x20scripts\x20配置','input','inquirer','项目构建完成','正在创建模板目录...','项目依赖安装完成','):\x20','environment','password','join','正在切换到目标分支:\x20','commitMessage','150koLzxw','package.json','includes','request','message','构建产物目录不存在,请检查构建输出配置','./config','javaGitBranch','exports','status','清理临时目录失败:\x20','7020840NycAWA','正在安装项目依赖\x20('];a7_0x4d38=function(){return _0x1af951;};return a7_0x4d38();}const os=require('os'),path=require(a7_0x10b04b(0xf1)),fs=require('fs'),inquirer=require(a7_0x10b04b(0x109)),{CopyFolder,DeleteDirAllFile}=require(a7_0x10b04b(0x144)),{GIT_TEMP_JAVA,getApiHost}=require(a7_0x10b04b(0x119)),axios=require(a7_0x10b04b(0x15c)),{CONSTANTS,logInfo,logSuccess,logWarning,logError,executeCommand,deleteFolderRecursive,fileExists,readFile,writeFile,createDir,isViteProject,validateConfig}=require(a7_0x10b04b(0x144)),{loadAuth}=require(a7_0x10b04b(0x104));function a7_0x3525(_0x3dcc4f,_0x4f78c7){_0x3dcc4f=_0x3dcc4f-0xe3;const _0x4d3816=a7_0x4d38();let _0x3525dc=_0x4d3816[_0x3dcc4f];return _0x3525dc;}module[a7_0x10b04b(0x11b)]=async arguments=>{const _0x277fdc=a7_0x10b04b;let _0x53173e=null;const _0x2972d7=path[_0x277fdc(0x110)](__dirname,'../.auth');!fileExists(_0x2972d7)&&(logError(_0x277fdc(0xec)),process[_0x277fdc(0x103)](0x1));let _0x249d64,_0xe6c596;try{logInfo(_0x277fdc(0xf8));const _0x2d71a4=loadAuth(_0x2972d7);_0x249d64=_0x2d71a4[_0x277fdc(0x124)],_0xe6c596=_0x2d71a4[_0x277fdc(0x10f)],logSuccess(_0x277fdc(0x15e));}catch(_0x30d6a3){logError(_0x277fdc(0x155)+_0x30d6a3[_0x277fdc(0x117)]),process[_0x277fdc(0x103)](0x1);}const _0x2fd323=arguments[0x1]?arguments[0x1]['split']('-'):[],_0x4a938a=path['resolve']('./'),_0x2d672a=path[_0x277fdc(0x110)](_0x4a938a,_0x277fdc(0x114)),_0x460dc1=path[_0x277fdc(0x110)](_0x4a938a,CONSTANTS[_0x277fdc(0x105)]),_0x55f19c=path['join'](_0x4a938a,CONSTANTS[_0x277fdc(0x128)]),_0x4d1c12=os['tmpdir'](),_0x59c33d=fileExists(path['join'](_0x4a938a,_0x277fdc(0xf6)))?_0x277fdc(0x12d):_0x277fdc(0xf2),_0x13ffa4=_0x59c33d==='yarn'?_0x277fdc(0x12d):_0x277fdc(0xf9),_0x4f7efa=_0x711e42=>_0x59c33d==='yarn'?_0x277fdc(0xeb)+_0x711e42:_0x277fdc(0x160)+_0x711e42;logInfo('正在检查项目配置文件...');!fileExists(_0x2d672a)&&(logError(_0x277fdc(0xf3)),process['exit'](0x1));let _0x5390d4;try{_0x5390d4=JSON['parse'](fs[_0x277fdc(0xef)](_0x2d672a,_0x277fdc(0xe7))),logSuccess(_0x277fdc(0x149));}catch(_0x1b30c9){logError('解析\x20package.json\x20失败:\x20'+_0x1b30c9[_0x277fdc(0x117)]),process[_0x277fdc(0x103)](0x1);}const _0x343c4e=_0x5390d4[_0x277fdc(0x12b)]||{},_0x4df598=['build'],_0x33d0f9=Object[_0x277fdc(0x14a)](_0x343c4e)['filter'](_0x1070ef=>{const _0x3e9eb5=_0x277fdc;return _0x4df598[_0x3e9eb5(0x139)](_0x201596=>_0x1070ef['toLowerCase']()['includes'](_0x201596));});_0x33d0f9[_0x277fdc(0x15b)]===0x0&&(logError(_0x277fdc(0x107)),process[_0x277fdc(0x103)](0x1));const {selectedScript:_0x23fc1f}=await inquirer[_0x277fdc(0x146)]([{'type':'list','name':'selectedScript','message':_0x277fdc(0xf4),'choices':_0x33d0f9[_0x277fdc(0x126)](_0x34cc7e=>({'name':_0x34cc7e+'\x20('+_0x343c4e[_0x34cc7e]+')','value':_0x34cc7e}))}]);logInfo(_0x277fdc(0x137)+_0x23fc1f),logInfo('正在检查项目配置文件...');!fileExists(_0x460dc1)&&(logError(_0x277fdc(0x125)),process[_0x277fdc(0x103)](0x1));let _0x582cf4;try{_0x582cf4=require(_0x460dc1),_0x582cf4=_0x582cf4[_0x277fdc(0x102)]?_0x582cf4[_0x277fdc(0xfe)]:_0x582cf4,logSuccess(_0x277fdc(0x15a));}catch(_0x253e29){logError(_0x277fdc(0x13b)+_0x253e29[_0x277fdc(0x117)]),process[_0x277fdc(0x103)](0x1);}const _0x87d45d=[_0x277fdc(0x12f),_0x277fdc(0x13c),_0x277fdc(0x141)],_0x1c5484=validateConfig(_0x582cf4,_0x87d45d);!_0x1c5484['isValid']&&(logError(_0x277fdc(0x127)+_0x1c5484['missingFields'][_0x277fdc(0x110)](',\x20')),process[_0x277fdc(0x103)](0x1));let _0x342687=null;if(_0x582cf4[_0x277fdc(0x10e)]&&typeof _0x582cf4[_0x277fdc(0x10e)]===_0x277fdc(0xea)){const _0x3e9b49=Object[_0x277fdc(0x14a)](_0x582cf4[_0x277fdc(0x10e)]);if(_0x3e9b49[_0x277fdc(0x15b)]>0x0){const {envType:_0x36d54b}=await inquirer['prompt']([{'type':_0x277fdc(0x14b),'name':'envType','message':'请选择环境:','choices':_0x3e9b49[_0x277fdc(0x126)](_0x237426=>({'name':_0x237426,'value':_0x237426}))}]);_0x342687=_0x36d54b,logInfo(_0x277fdc(0x130)+_0x342687);}else logWarning(_0x277fdc(0xe4));}else logWarning(_0x277fdc(0x14e));logInfo(_0x277fdc(0x101)),axios['post'](getApiHost()+'/api/auth',{'username':_0x249d64,'password':_0xe6c596})[_0x277fdc(0x156)](async _0x5383e3=>{const _0x29549d=_0x277fdc;if(_0x5383e3['data']['status']){logSuccess('服务器授权成功');const _0x381efc=GIT_TEMP_JAVA+'-'+Date[_0x29549d(0x15d)]()+'-'+Math['random']()[_0x29549d(0x15f)](0x24)['substr'](0x2,0x9);_0x53173e=_0x381efc;const _0x3578d3=path[_0x29549d(0x110)](_0x4d1c12,_0x381efc);logInfo(_0x29549d(0x100));fileExists(_0x3578d3)&&deleteFolderRecursive(_0x3578d3);createDir(_0x3578d3),logSuccess(_0x29549d(0xf7));const _0x35f882=path[_0x29549d(0x110)](_0x3578d3,_0x582cf4['javaGitName']);logInfo(_0x29549d(0x129)),fileExists(_0x35f882)?_0x2fd323[_0x29549d(0x115)](_0x29549d(0xf0))?(logInfo('检测到已存在的仓库,正在强制清理...'),DeleteDirAllFile(_0x35f882,()=>{const _0x316260=_0x29549d;executeCommand(_0x316260(0xfb)+_0x582cf4[_0x316260(0x12f)],_0x3578d3),logSuccess(_0x316260(0x12a));})):(executeCommand('git\x20clone\x20'+_0x582cf4[_0x29549d(0x12f)],_0x3578d3),logSuccess(_0x29549d(0x12a))):(executeCommand(_0x29549d(0xfb)+_0x582cf4['javaGit'],_0x3578d3),logSuccess(_0x29549d(0x12a))),_0x59c3ee(_0x3578d3,_0x582cf4,_0x381efc,_0x23fc1f,_0x342687);}else logError(_0x29549d(0xfd)+(_0x5383e3['data']['message']||_0x29549d(0xe8))),process['exit'](0x1);})['catch'](_0x4a0369=>{const _0x591b39=_0x277fdc;if(_0x4a0369&&_0x4a0369[_0x591b39(0x121)]){const _0x19400f=_0x4a0369[_0x591b39(0x121)][_0x591b39(0x11c)];_0x19400f===0x191||_0x19400f===0x193?logError(_0x591b39(0xfa)+_0x19400f+'):\x20认证信息无效或无权限'):logError(_0x591b39(0x122)+_0x19400f+_0x591b39(0x10d)+(_0x4a0369[_0x591b39(0x121)]['data']?.[_0x591b39(0x117)]||_0x4a0369[_0x591b39(0x117)]));}else _0x4a0369&&_0x4a0369[_0x591b39(0x116)]?logError('网络连接失败:\x20无法连接到服务器'):logError(_0x591b39(0x153)+(_0x4a0369[_0x591b39(0x117)]||_0x591b39(0xe8)));process[_0x591b39(0x103)](0x1);}),process['on'](_0x277fdc(0x103),()=>{const _0x365ccc=_0x277fdc;if(_0x53173e){const _0x37b180=path[_0x365ccc(0x110)](os[_0x365ccc(0xe9)](),_0x53173e);if(fileExists(_0x37b180))try{deleteFolderRecursive(_0x37b180);}catch(_0x5975c0){}}}),process['on'](_0x277fdc(0x147),_0x9300ae=>{const _0xa0265d=_0x277fdc;if(_0x53173e){const _0x22bd54=path['join'](os[_0xa0265d(0xe9)](),_0x53173e);if(fileExists(_0x22bd54))try{deleteFolderRecursive(_0x22bd54);}catch(_0x1fc74b){}}throw _0x9300ae;});function _0x59c3ee(_0x5ef4bf,_0xec6722,_0xe0e5d6,_0x12d018,_0xc5235d){const _0x35e15f=_0x277fdc,_0x580776=path[_0x35e15f(0x110)](_0x5ef4bf,_0xec6722['javaGitName']);logInfo('正在同步\x20Git\x20仓库最新代码...'),executeCommand(_0x35e15f(0x14d),_0x580776),logSuccess('代码同步完成');!fileExists(path[_0x35e15f(0x110)](_0x4a938a,_0x35e15f(0x133)))?(logWarning(_0x35e15f(0xe3)),logInfo(_0x35e15f(0x11f)+_0x59c33d+'),请稍候...'),executeCommand(_0x13ffa4,_0x4a938a),logSuccess(_0x35e15f(0x10c))):logInfo(_0x35e15f(0xff));try{logInfo(_0x35e15f(0x154)+_0x4f7efa(_0x12d018)),executeCommand(_0x4f7efa(_0x12d018),_0x4a938a,{'maxBuffer':CONSTANTS['MAX_BUFFER_SIZE']}),logSuccess(_0x35e15f(0x10a));}catch(_0x43e7bc){logError(_0x35e15f(0x150)+_0x43e7bc[_0x35e15f(0x117)]);const _0x2b31a3=path[_0x35e15f(0x110)](os[_0x35e15f(0xe9)](),_0xe0e5d6);if(fileExists(_0x2b31a3))try{deleteFolderRecursive(_0x2b31a3),logInfo(_0x35e15f(0x142)+_0xe0e5d6);}catch(_0x4c9980){logWarning(_0x35e15f(0x11d)+_0x4c9980['message']);}process[_0x35e15f(0x103)](0x1);}if(fileExists(_0x55f19c)){logInfo(_0x35e15f(0x136));const _0x133a0a=_0xec6722[_0x35e15f(0x141)],_0x1695cd=readFile(path[_0x35e15f(0x110)](_0x55f19c,_0x35e15f(0x13f)));_0x2fd323['includes'](_0x35e15f(0x158))?(writeFile(path['join'](_0x55f19c,_0x35e15f(0x13f)),_0x1695cd),logInfo(_0x35e15f(0x131))):(writeFile(path[_0x35e15f(0x110)](_0x55f19c,_0x133a0a+'.html'),_0x1695cd),logInfo(_0x35e15f(0x145)+_0x133a0a+_0x35e15f(0x132)));const _0x31fd30=path[_0x35e15f(0x110)](_0x580776,CONSTANTS[_0x35e15f(0xe6)]);logInfo(_0x35e15f(0x10b)),createDir(_0x31fd30);const _0xb0ca0a=_0xc5235d&&_0xec6722['environment']&&_0xec6722['environment'][_0xc5235d]&&_0xec6722[_0x35e15f(0x10e)][_0xc5235d][_0x35e15f(0x11a)]?_0xec6722['environment'][_0xc5235d][_0x35e15f(0x11a)]:CONSTANTS['DEFAULT_BRANCH'];logInfo(_0x35e15f(0x111)+_0xb0ca0a),executeCommand(_0x35e15f(0x14f)+_0xb0ca0a,_0x580776),logSuccess(_0x35e15f(0x14c));const _0x2768e6=path['join'](_0x31fd30,_0xec6722[_0x35e15f(0x141)]);logInfo('正在清理目标目录...'),DeleteDirAllFile(_0x2768e6,()=>{const _0x284d2c=_0x35e15f;createDir(_0x2768e6),logInfo(_0x284d2c(0x135)),writeFile(path[_0x284d2c(0x110)](_0x31fd30,_0x133a0a+'.html'),_0x1695cd),CopyFolder(path[_0x284d2c(0x110)](_0x55f19c,_0xec6722['appIdentifier']),_0x2768e6,async()=>{const _0x2a6185=_0x284d2c;logSuccess(_0x2a6185(0xe5)),setTimeout(async()=>{const _0x235e4d=_0x2a6185;logInfo(_0x235e4d(0x13a)),executeCommand(_0x235e4d(0x14d),_0x580776),logInfo(_0x235e4d(0x151)),executeCommand(_0x235e4d(0x13d),_0x580776);const {commitMessage:_0x2e2988}=await inquirer['prompt']([{'type':_0x235e4d(0x108),'name':_0x235e4d(0x112),'message':'请输入提交信息:','default':'no\x20message'}]),_0x34a36d=_0x2e2988[_0x235e4d(0x134)]()||'no\x20message';try{logInfo(_0x235e4d(0x138)),executeCommand(_0x235e4d(0x143)+_0x34a36d+'\x22\x20--no-verify',_0x580776),logSuccess(_0x235e4d(0x123));}catch(_0xea4fb5){logWarning(_0x235e4d(0x12c));}logInfo(_0x235e4d(0x13e)),executeCommand(_0x235e4d(0xee),_0x580776),logSuccess('代码推送完成'),setTimeout(()=>{const _0x1d9b94=_0x235e4d;logInfo(_0x1d9b94(0xfc));const _0x4865d6=path[_0x1d9b94(0x110)](os[_0x1d9b94(0xe9)](),_0xe0e5d6);if(fileExists(_0x4865d6))try{deleteFolderRecursive(_0x4865d6),logSuccess(_0x1d9b94(0x142)+_0xe0e5d6);}catch(_0x60feb){logWarning('清理临时目录失败:\x20'+_0x60feb[_0x1d9b94(0x117)]);}},CONSTANTS['SYNC_DELAY']*0x2);},CONSTANTS[_0x2a6185(0x106)]);});});}else{logError(_0x35e15f(0x118));const _0x3f984e=path[_0x35e15f(0x110)](os[_0x35e15f(0xe9)](),_0xe0e5d6);if(fileExists(_0x3f984e))try{deleteFolderRecursive(_0x3f984e),logInfo(_0x35e15f(0x142)+_0xe0e5d6);}catch(_0x48346a){logWarning(_0x35e15f(0x11d)+_0x48346a[_0x35e15f(0x117)]);}process[_0x35e15f(0x103)](0x1);}}};
|
package/src/rm-rf.js
CHANGED
|
@@ -1,49 +1 @@
|
|
|
1
|
-
const
|
|
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
|
-
|
|
1
|
+
function a8_0x1c56(_0x4f6147,_0x2a4c1c){_0x4f6147=_0x4f6147-0x68;const _0x319bac=a8_0x319b();let _0x1c56f1=_0x319bac[_0x4f6147];return _0x1c56f1;}function a8_0x319b(){const _0x1d7261=['146391hwugya','1673520eWCIHT','exit','exports','resolve','./utils','54gQUNEz','操作已取消','confirm','1076724SMeXCo','13238505yrQifn','删除操作失败:\x20','message','prompt','inquirer','开始执行删除操作...','32785znhDTB','是否确认删除?删除后不可恢复!','3598689YdNluj','2148662vllnLD','所有文件已成功删除','496xObJht'];a8_0x319b=function(){return _0x1d7261;};return a8_0x319b();}const a8_0x4a152f=a8_0x1c56;(function(_0x35ca3a,_0x14545f){const _0x6dd45b=a8_0x1c56,_0x2be6a0=_0x35ca3a();while(!![]){try{const _0xc9494f=-parseInt(_0x6dd45b(0x7b))/0x1+-parseInt(_0x6dd45b(0x77))/0x2+parseInt(_0x6dd45b(0x76))/0x3+-parseInt(_0x6dd45b(0x6d))/0x4+parseInt(_0x6dd45b(0x74))/0x5*(-parseInt(_0x6dd45b(0x6a))/0x6)+parseInt(_0x6dd45b(0x7a))/0x7*(parseInt(_0x6dd45b(0x79))/0x8)+parseInt(_0x6dd45b(0x6e))/0x9;if(_0xc9494f===_0x14545f)break;else _0x2be6a0['push'](_0x2be6a0['shift']());}catch(_0x5d9fa4){_0x2be6a0['push'](_0x2be6a0['shift']());}}}(a8_0x319b,0xd98bd));const path=require('path'),inquirer=require(a8_0x4a152f(0x72)),{logInfo,logSuccess,logError,logWarning,deleteFolderRecursive}=require(a8_0x4a152f(0x69));module[a8_0x4a152f(0x7d)]=async function(){const _0x3ddfde=a8_0x4a152f,_0x49e86d=path[_0x3ddfde(0x68)]('./');logWarning('危险操作:此命令将删除当前目录下的所有文件和文件夹'),logWarning('删除后不可恢复,请谨慎操作');const {confirm:_0x105a0b}=await inquirer[_0x3ddfde(0x71)]([{'type':_0x3ddfde(0x6c),'name':'confirm','message':_0x3ddfde(0x75),'default':![]}]);_0x105a0b?(logInfo('正在扫描目录结构...'),setTimeout(()=>{const _0x367037=_0x3ddfde;try{logInfo(_0x367037(0x73)),deleteFolderRecursive(_0x49e86d),logSuccess(_0x367037(0x78)),process[_0x367037(0x7c)](0x0);}catch(_0x8407b7){logError(_0x367037(0x6f)+_0x8407b7[_0x367037(0x70)]),process[_0x367037(0x7c)](0x1);}},0x3e8)):(logInfo(_0x3ddfde(0x6b)),process[_0x3ddfde(0x7c)](0x0));};
|