jjb-cmd 2.5.0 → 2.5.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.
package/bin/command.js ADDED
@@ -0,0 +1,73 @@
1
+ #! /usr/bin/env node
2
+
3
+ const commander = require('commander');
4
+ // const readline = require('readline');
5
+ const path = require('path');
6
+ const fs = require('fs');
7
+ // const child_process = require('child_process');
8
+
9
+ commander.command('v').description('-- 查看版本').action(() => {
10
+ const package_json_file = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json')).toString());
11
+ const {
12
+ version
13
+ } = package_json_file;
14
+ console.log(`当前版本 v${version}`);
15
+ });
16
+
17
+ commander.command('help').description('-- 帮助').action(() => {
18
+ console.log('jjb-cmd <command>');
19
+ console.log('');
20
+ console.log('使用:');
21
+ console.log('');
22
+ console.log('jjb-cmd help 帮助');
23
+ console.log('jjb-cmd opti 代码优化');
24
+ console.log('jjb-cmd v 查看版本');
25
+ console.log('jjb-cmd publish <version> 发布云组件\n\targ1 <version> 发布版本,可设置为latest');
26
+ console.log('jjb-cmd auth <username> <password> 登录授权\n\targ1 <username> 用户名\n\targ2 <password> 密码');
27
+ console.log('jjb-cmd push java <env> 推送微应用到服务器\n\targ1 <env> 推送环境');
28
+ });
29
+
30
+ commander.command('pushMessage [args]').description('-- 设置publish提交时是否需要提交信息').action(args => {
31
+ const package_json_file = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json')).toString());
32
+ if ([ 'yes', 'no' ].includes(args)) {
33
+ package_json_file.pushMessage = args;
34
+ fs.writeFileSync(path.join(__dirname, '../package.json'), JSON.stringify(package_json_file));
35
+ }
36
+ });
37
+
38
+ // 命令
39
+ commander.command('auth [args]').description('-- 授权').action(args => {
40
+ require('../src/auth.js')(process.argv.splice(3));
41
+ });
42
+
43
+ // 优化
44
+ commander.command('opti').description('-- 代码优化').action(args => {
45
+ require('../src/code-optimization')();
46
+ });
47
+
48
+ // 发包
49
+ commander.command('publish [args]').description('-- 发布包').action(args => {
50
+ require('../src/publish.js')(args);
51
+ });
52
+
53
+ // publish 命令
54
+ commander.command('push [args]').description('-- 发布包').action(args => {
55
+ if (args) {
56
+ if ([ 'java' ].includes(args)) {
57
+ require('../src/push.js')(process.argv.splice(3));
58
+ } else {
59
+ console.log(`无效的选项‘${args}’。`);
60
+ process.exit(0);
61
+ }
62
+ } else {
63
+ console.log(`无效的选项‘${args}’。`);
64
+ process.exit(0);
65
+ }
66
+ });
67
+
68
+ // rm-rf 命令
69
+ commander.command('rm-rf').description('-- 删除全部').action(() => {
70
+ require('../src/rm-rf.js')();
71
+ });
72
+
73
+ commander.parse(process.argv);
package/build.js ADDED
@@ -0,0 +1,20 @@
1
+ const child_process = require('child_process');
2
+ const utils = require('./src/utils');
3
+
4
+ // 执行代码混淆
5
+ child_process.execSync(`npx javascript-obfuscator src --output publish/src --config obf.config.json`);
6
+ console.log('obf Done!');
7
+
8
+ // 复制bin目录
9
+ utils.CopyFolder('./bin', './publish/bin', () => {
10
+ console.log('bin Folder Done!');
11
+
12
+ // 复制其他文件
13
+ utils.CopyFile('./package.json', './publish/package.json', () => {
14
+ utils.CopyFile('./README.md', './publish/README.md', () => {
15
+ utils.CopyFile('./LICENSE', './publish/LICENSE', () => {
16
+ console.log('ALL Done !');
17
+ });
18
+ });
19
+ });
20
+ });
@@ -0,0 +1,3 @@
1
+ {
2
+ "compact": true
3
+ }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "env": "prod",
5
5
  "httpMethod": "http",
6
6
  "pushMessage": "yes",
7
- "version": "2.5.0",
7
+ "version": "2.5.1",
8
8
  "description": "jjb-cmd命令行工具",
9
9
  "main": "index.js",
10
10
  "scripts": {
package/src/auth.js CHANGED
@@ -1 +1,47 @@
1
- function a0_0x4f02(_0x284f87,_0xb5d426){const _0x244931=a0_0x2449();return a0_0x4f02=function(_0x4f02bd,_0x37d2f2){_0x4f02bd=_0x4f02bd-0x99;let _0x117d72=_0x244931[_0x4f02bd];return _0x117d72;},a0_0x4f02(_0x284f87,_0xb5d426);}const a0_0x28f87c=a0_0x4f02;(function(_0x1ec0de,_0x2d4ea1){const _0x6c3cce=a0_0x4f02,_0x2fe226=_0x1ec0de();while(!![]){try{const _0x3dc38e=parseInt(_0x6c3cce(0xa4))/0x1+parseInt(_0x6c3cce(0xae))/0x2*(-parseInt(_0x6c3cce(0xa9))/0x3)+parseInt(_0x6c3cce(0xaf))/0x4+-parseInt(_0x6c3cce(0xad))/0x5+-parseInt(_0x6c3cce(0x9f))/0x6*(parseInt(_0x6c3cce(0xa5))/0x7)+-parseInt(_0x6c3cce(0xaa))/0x8*(parseInt(_0x6c3cce(0xb2))/0x9)+parseInt(_0x6c3cce(0x9b))/0xa*(parseInt(_0x6c3cce(0xa8))/0xb);if(_0x3dc38e===_0x2d4ea1)break;else _0x2fe226['push'](_0x2fe226['shift']());}catch(_0x2e7ff3){_0x2fe226['push'](_0x2fe226['shift']());}}}(a0_0x2449,0xd8ac9));function a0_0x2449(){const _0x3f726f=['Auth:\x20授权登录!','exit','157957kAjtrk','1681309VafWIw','/api/auth','./utils','544093rjrzfc','2526SoZXks','808PMJmSF','then','data','1008285TXLbni','2372zMdJmS','2583896yxFISp','Auth:\x20登录失败!','length','10917DerZAJ','join','catch','430kQlxJa','path','exports','./config','18eNeqZY','post','axios'];a0_0x2449=function(){return _0x3f726f;};return a0_0x2449();}const axios=require(a0_0x28f87c(0xa1)),path=require(a0_0x28f87c(0x9c)),{getApiHost}=require(a0_0x28f87c(0x9e)),{logInfo,logSuccess,logError,writeFile,fileExists,deleteFile}=require(a0_0x28f87c(0xa7));module[a0_0x28f87c(0x9d)]=_0x12d196=>{const _0x1c3859=a0_0x28f87c;(!_0x12d196||_0x12d196[_0x1c3859(0xb1)]<0x2)&&(logError('用户名和密码参数不能为空!'),process[_0x1c3859(0xa3)](0x1));const [_0x6d7056,_0x1c05bf]=_0x12d196;logInfo(_0x1c3859(0xa2));const _0xee2e09=path[_0x1c3859(0x99)](__dirname,'../.auth');axios[_0x1c3859(0xa0)](getApiHost()+_0x1c3859(0xa6),{'username':_0x6d7056,'password':_0x1c05bf})[_0x1c3859(0xab)](_0x15bc5=>{const _0xa4ba9f=_0x1c3859;_0x15bc5[_0xa4ba9f(0xac)]['status']?(logSuccess('Auth:\x20登录成功,已缓存登录状态!'),writeFile(_0xee2e09,_0x6d7056+'/'+_0x1c05bf)):(logError('Auth:\x20'+_0x15bc5[_0xa4ba9f(0xac)]['message']),fileExists(_0xee2e09)&&deleteFile(_0xee2e09),process['exit'](0x1));})[_0x1c3859(0x9a)](_0x2e97a4=>{const _0xb8cc9=_0x1c3859;logError(_0xb8cc9(0xb0)+_0x2e97a4['message']),process[_0xb8cc9(0xa3)](0x1);});};
1
+ const axios = require('axios');
2
+ const path = require('path');
3
+ const { getApiHost } = require('./config');
4
+ const {
5
+ logInfo,
6
+ logSuccess,
7
+ logError,
8
+ writeFile,
9
+ fileExists,
10
+ deleteFile
11
+ } = require('./utils');
12
+
13
+ /**
14
+ * 用户认证模块
15
+ * @param {string[]} args - 命令行参数 [username, password]
16
+ */
17
+ module.exports = args => {
18
+ // 参数验证
19
+ if (!args || args.length < 2) {
20
+ logError('用户名和密码参数不能为空!');
21
+ process.exit(1);
22
+ }
23
+
24
+ const [ username, password ] = args;
25
+ logInfo('Auth: 授权登录!');
26
+
27
+ const authPath = path.join(__dirname, '../.auth');
28
+
29
+ axios.post(`${getApiHost()}/api/auth`, {
30
+ username,
31
+ password
32
+ }).then(res => {
33
+ if (res.data.status) {
34
+ logSuccess('Auth: 登录成功,已缓存登录状态!');
35
+ writeFile(authPath, `${username}/${password}`);
36
+ } else {
37
+ logError(`Auth: ${res.data.message}`);
38
+ if (fileExists(authPath)) {
39
+ deleteFile(authPath);
40
+ }
41
+ process.exit(1);
42
+ }
43
+ }).catch(e => {
44
+ logError(`Auth: 登录失败!${e.message}`);
45
+ process.exit(1);
46
+ });
47
+ };
@@ -1 +1,49 @@
1
- function a1_0x2872(_0x4064d5,_0x411078){const _0x1e0348=a1_0x1e03();return a1_0x2872=function(_0x28720b,_0x3b24d5){_0x28720b=_0x28720b-0x154;let _0x1a2e1a=_0x1e0348[_0x28720b];return _0x1a2e1a;},a1_0x2872(_0x4064d5,_0x411078);}const a1_0x588a46=a1_0x2872;(function(_0x1cbb18,_0x95c478){const _0x18b4d0=a1_0x2872,_0x2232c2=_0x1cbb18();while(!![]){try{const _0xce31cc=parseInt(_0x18b4d0(0x169))/0x1+-parseInt(_0x18b4d0(0x15d))/0x2+-parseInt(_0x18b4d0(0x15c))/0x3+parseInt(_0x18b4d0(0x165))/0x4*(parseInt(_0x18b4d0(0x157))/0x5)+-parseInt(_0x18b4d0(0x156))/0x6+-parseInt(_0x18b4d0(0x167))/0x7+parseInt(_0x18b4d0(0x16a))/0x8;if(_0xce31cc===_0x95c478)break;else _0x2232c2['push'](_0x2232c2['shift']());}catch(_0x598b73){_0x2232c2['push'](_0x2232c2['shift']());}}}(a1_0x1e03,0xc03aa));const path=require(a1_0x588a46(0x160)),readline=require(a1_0x588a46(0x162)),{bootstrap}=require(a1_0x588a46(0x16d)),{logInfo,logSuccess,logError,logWarning}=require('./utils'),io=readline['createInterface']({'input':process[a1_0x588a46(0x164)],'output':process['stdout']});function a1_0x1e03(){const _0x1c8191=['6758880jqXywG','4430105jUgzzb','exit','toLowerCase','trim','取消优化。','3628260syCzBQ','1794198pZotTE','message','代码优化工具','path','此操作将优化当前目录下的代码,请确保已备份重要文件!','readline','代码优化过程中发生错误:','stdin','4giDOvi','无效操作,请输入\x20y\x20或\x20n。','107863XuUUFs','开始代码优化...','115061SakUHx','24277568VLAYJV','优化完成。','question','@cqsjjb/react-code-optimization','exports','resolve'];a1_0x1e03=function(){return _0x1c8191;};return a1_0x1e03();}module[a1_0x588a46(0x154)]=function(){const _0x4d9f4b=a1_0x588a46,_0x1740c6=path[_0x4d9f4b(0x155)]('./');logInfo(_0x4d9f4b(0x15f)),logWarning(_0x4d9f4b(0x161)),io[_0x4d9f4b(0x16c)]('是否确认优化代码?[y/n]:',function(_0xb4fd34){const _0x474a54=_0x4d9f4b,_0x395442=_0xb4fd34[_0x474a54(0x15a)]()[_0x474a54(0x159)]();if(_0x395442==='y'||_0x395442==='yes'){logInfo(_0x474a54(0x168));try{bootstrap(_0x1740c6,0x64,()=>{const _0x3e61a9=_0x474a54;logSuccess(_0x3e61a9(0x16b)),process[_0x3e61a9(0x158)](0x0);});}catch(_0x194a13){logError(_0x474a54(0x163)+_0x194a13[_0x474a54(0x15e)]),process[_0x474a54(0x158)](0x1);}}else _0x395442==='n'||_0x395442==='no'?(logInfo(_0x474a54(0x15b)),process[_0x474a54(0x158)](0x0)):(logError(_0x474a54(0x166)),process[_0x474a54(0x158)](0x1));});};
1
+ const path = require('path');
2
+ const readline = require('readline');
3
+ const { bootstrap } = require('@cqsjjb/react-code-optimization');
4
+ const {
5
+ logInfo,
6
+ logSuccess,
7
+ logError,
8
+ logWarning
9
+ } = require('./utils');
10
+
11
+ const io = readline.createInterface({
12
+ input: process.stdin,
13
+ output: process.stdout
14
+ });
15
+
16
+ /**
17
+ * 代码优化模块
18
+ * 使用 @cqsjjb/react-code-optimization 进行代码优化
19
+ */
20
+ module.exports = function () {
21
+ const rootPath = path.resolve('./');
22
+
23
+ logInfo('代码优化工具');
24
+ logWarning('此操作将优化当前目录下的代码,请确保已备份重要文件!');
25
+
26
+ io.question('是否确认优化代码?[y/n]:', function (answer) {
27
+ const trimmedAnswer = answer.trim().toLowerCase();
28
+
29
+ if (trimmedAnswer === 'y' || trimmedAnswer === 'yes') {
30
+ logInfo('开始代码优化...');
31
+
32
+ try {
33
+ bootstrap(rootPath, 100, () => {
34
+ logSuccess('优化完成。');
35
+ process.exit(0);
36
+ });
37
+ } catch (error) {
38
+ logError(`代码优化过程中发生错误:${error.message}`);
39
+ process.exit(1);
40
+ }
41
+ } else if (trimmedAnswer === 'n' || trimmedAnswer === 'no') {
42
+ logInfo('取消优化。');
43
+ process.exit(0);
44
+ } else {
45
+ logError('无效操作,请输入 y 或 n。');
46
+ process.exit(1);
47
+ }
48
+ });
49
+ };
package/src/config.js CHANGED
@@ -1 +1,122 @@
1
- function a2_0x1f54(_0x11ff5a,_0x3566d9){const _0xdbffc3=a2_0xdbff();return a2_0x1f54=function(_0x1f5456,_0x1886de){_0x1f5456=_0x1f5456-0x163;let _0x563b31=_0xdbffc3[_0x1f5456];return _0x563b31;},a2_0x1f54(_0x11ff5a,_0x3566d9);}function a2_0xdbff(){const _0x295a9b=['parse','jjb-assembly-java','http://120.26.210.58:8089','CLOUD_PROJECT','hLqARY89CN6fUD3yg4NL','26408460MIbOzm','GIT_TEMP_JAVA','getApiHost','GIT_HOST','gPSit8aJsLVmNzuQ5Cy4','8666fyenbt','https://jcloud.cqjjb.cn','397527GuXNVE','snBxJ2i5kYarGGcsojhY','http','httpMethod','GIT_JAVA_ENV_JSON','397368bAQPjl','3198WGxuva','test','879637fzMphJ','G4HJRsHr9D7Ssmixegw2','API_HOST','152QPHUwH','FqNrmFAgrxasMrbbjvq9','http://120.26.210.58:8088','prod','API_HOST_TEST','d4wQ7dzEjYPsgVbKnYei','join','tmpdir','env','FT3pKzxpRynFkmddJ9Bs','GIT_TEMP_DIR','path','1887285lULnEq','e9njpBd1nS_LREN8GFpR','now','readFileSync','4Xfytty','5281500fhEgVt','http://192.168.1.242:10985'];a2_0xdbff=function(){return _0x295a9b;};return a2_0xdbff();}const a2_0x4fc781=a2_0x1f54;(function(_0xeb7858,_0x28b70d){const _0x219317=a2_0x1f54,_0x458b9f=_0xeb7858();while(!![]){try{const _0x303f0a=parseInt(_0x219317(0x17b))/0x1+parseInt(_0x219317(0x164))/0x2*(-parseInt(_0x219317(0x173))/0x3)+-parseInt(_0x219317(0x165))/0x4+parseInt(_0x219317(0x18a))/0x5+parseInt(_0x219317(0x179))/0x6*(-parseInt(_0x219317(0x171))/0x7)+-parseInt(_0x219317(0x17e))/0x8*(parseInt(_0x219317(0x178))/0x9)+parseInt(_0x219317(0x16c))/0xa;if(_0x303f0a===_0x28b70d)break;else _0x458b9f['push'](_0x458b9f['shift']());}catch(_0xac74){_0x458b9f['push'](_0x458b9f['shift']());}}}(a2_0xdbff,0xc6aed));const os=require('os'),path=require(a2_0x4fc781(0x189)),fs=require('fs'),API_HOST=a2_0x4fc781(0x180),API_HOST_HTTPS=a2_0x4fc781(0x172),API_HOST_TEST=a2_0x4fc781(0x169);exports['CONFIG_FILE_HOST']='https://cdn.cqjjb.cn/jjb-cloud-config',exports[a2_0x4fc781(0x17d)]=API_HOST,exports[a2_0x4fc781(0x182)]=API_HOST_TEST,exports[a2_0x4fc781(0x16f)]=a2_0x4fc781(0x166),exports[a2_0x4fc781(0x188)]='jjb-assembly-'+Date[a2_0x4fc781(0x18c)](),exports[a2_0x4fc781(0x16d)]=a2_0x4fc781(0x168),exports[a2_0x4fc781(0x177)]={'development':'dev','production':a2_0x4fc781(0x181),'test':a2_0x4fc781(0x17a)},exports[a2_0x4fc781(0x16a)]={'common':{'token':a2_0x4fc781(0x17c),'projectId':0x117},'react-admin-component':{'token':a2_0x4fc781(0x187),'projectId':0x154},'jjb-dva-runtime':{'token':a2_0x4fc781(0x16b),'projectId':0x23b},'jjb-common-lib':{'token':a2_0x4fc781(0x18b),'projectId':0x23c},'jjb-common-decorator':{'token':a2_0x4fc781(0x170),'projectId':0x23e},'vue-unisass-component':{'token':a2_0x4fc781(0x183),'projectId':0x153},'react-component':{'token':a2_0x4fc781(0x174),'projectId':0x33f},'micro-app-ts':{'token':'7V-YUxhmh51Mdhgx4rq4','projectId':0x33e},'micro-app':{'token':a2_0x4fc781(0x17f),'projectId':0x33d},'lib':{'token':'ywPtT3xCG6b_vAxp6sTj','projectId':0x33c}},exports['TEMPLATE_FOLDER']=path['join'](os[a2_0x4fc781(0x185)](),exports[a2_0x4fc781(0x188)]),exports[a2_0x4fc781(0x16e)]=()=>{const _0x6bf093=a2_0x4fc781;try{const _0x252dd5=JSON[_0x6bf093(0x167)](fs[_0x6bf093(0x163)](path[_0x6bf093(0x184)](__dirname,'../package.json'))['toString']());return _0x252dd5[_0x6bf093(0x186)]==='test'?API_HOST_TEST:_0x252dd5[_0x6bf093(0x176)]===_0x6bf093(0x175)?API_HOST:API_HOST_HTTPS;}catch(_0x3c9a61){return API_HOST_HTTPS;}};
1
+ const os = require('os');
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+
5
+ /**
6
+ * API 主机配置
7
+ */
8
+ const API_HOST = 'http://120.26.210.58:8088';
9
+ const API_HOST_HTTPS = 'https://jcloud.cqjjb.cn';
10
+ const API_HOST_TEST = 'http://120.26.210.58:8089';
11
+
12
+ /**
13
+ * 配置文件主机地址
14
+ */
15
+ exports.CONFIG_FILE_HOST = 'https://cdn.cqjjb.cn/jjb-cloud-config';
16
+
17
+ /**
18
+ * API 主机地址
19
+ */
20
+ exports.API_HOST = API_HOST;
21
+
22
+ /**
23
+ * 测试环境 API 主机地址
24
+ */
25
+ exports.API_HOST_TEST = API_HOST_TEST;
26
+
27
+ /**
28
+ * Git 主机地址
29
+ */
30
+ exports.GIT_HOST = 'http://192.168.1.242:10985';
31
+
32
+ /**
33
+ * 临时目录名称
34
+ */
35
+ exports.GIT_TEMP_DIR = `jjb-assembly-${Date.now()}`;
36
+
37
+ /**
38
+ * Java 临时目录名称
39
+ */
40
+ exports.GIT_TEMP_JAVA = `jjb-assembly-java`;
41
+
42
+ /**
43
+ * Java 环境映射
44
+ */
45
+ exports.GIT_JAVA_ENV_JSON = {
46
+ development: 'dev',
47
+ production: 'prod',
48
+ test: 'test'
49
+ };
50
+ /**
51
+ * 云项目配置
52
+ * 包含各个项目的 token 和 projectId
53
+ */
54
+ exports.CLOUD_PROJECT = {
55
+ common: {
56
+ token: 'G4HJRsHr9D7Ssmixegw2',
57
+ projectId: 279
58
+ },
59
+ 'react-admin-component': {
60
+ token: 'FT3pKzxpRynFkmddJ9Bs',
61
+ projectId: 340
62
+ },
63
+ 'jjb-dva-runtime': {
64
+ token: 'hLqARY89CN6fUD3yg4NL',
65
+ projectId: 571
66
+ },
67
+ 'jjb-common-lib': {
68
+ token: 'e9njpBd1nS_LREN8GFpR',
69
+ projectId: 572
70
+ },
71
+ 'jjb-common-decorator': {
72
+ token: 'gPSit8aJsLVmNzuQ5Cy4',
73
+ projectId: 574
74
+ },
75
+ 'vue-unisass-component': {
76
+ token: 'd4wQ7dzEjYPsgVbKnYei',
77
+ projectId: 339
78
+ },
79
+ 'react-component': {
80
+ token: 'snBxJ2i5kYarGGcsojhY',
81
+ projectId: 831
82
+ },
83
+ 'micro-app-ts': {
84
+ token: '7V-YUxhmh51Mdhgx4rq4',
85
+ projectId: 830
86
+ },
87
+ 'micro-app': {
88
+ token: 'FqNrmFAgrxasMrbbjvq9',
89
+ projectId: 829
90
+ },
91
+ lib: {
92
+ token: 'ywPtT3xCG6b_vAxp6sTj',
93
+ projectId: 828
94
+ }
95
+ };
96
+
97
+ /**
98
+ * 模板文件夹路径
99
+ */
100
+ exports.TEMPLATE_FOLDER = path.join(os.tmpdir(), exports.GIT_TEMP_DIR);
101
+
102
+ /**
103
+ * 获取 API 主机地址
104
+ * 根据 package.json 中的配置决定使用哪个 API 主机
105
+ * @returns {string} API 主机地址
106
+ */
107
+ exports.getApiHost = () => {
108
+ try {
109
+ const packageJson = JSON.parse(
110
+ fs.readFileSync(path.join(__dirname, '../package.json')).toString()
111
+ );
112
+
113
+ if (packageJson.env === 'test') {
114
+ return API_HOST_TEST;
115
+ } else {
116
+ return packageJson.httpMethod === 'http' ? API_HOST : API_HOST_HTTPS;
117
+ }
118
+ } catch (error) {
119
+ // 如果读取 package.json 失败,默认返回 HTTPS 地址
120
+ return API_HOST_HTTPS;
121
+ }
122
+ };
package/src/publish.js CHANGED
@@ -1 +1,222 @@
1
- function a3_0x2508(_0x143e36,_0x9940f7){const _0x1e454c=a3_0x1e45();return a3_0x2508=function(_0x250833,_0x10b727){_0x250833=_0x250833-0x145;let _0xf4a601=_0x1e454c[_0x250833];return _0xf4a601;},a3_0x2508(_0x143e36,_0x9940f7);}const a3_0xe77f14=a3_0x2508;(function(_0x5de060,_0x5435d8){const _0x2838e3=a3_0x2508,_0x2cb9f4=_0x5de060();while(!![]){try{const _0x40bc19=parseInt(_0x2838e3(0x17b))/0x1*(-parseInt(_0x2838e3(0x175))/0x2)+-parseInt(_0x2838e3(0x14f))/0x3*(parseInt(_0x2838e3(0x185))/0x4)+-parseInt(_0x2838e3(0x158))/0x5+parseInt(_0x2838e3(0x161))/0x6*(-parseInt(_0x2838e3(0x176))/0x7)+-parseInt(_0x2838e3(0x188))/0x8*(parseInt(_0x2838e3(0x168))/0x9)+parseInt(_0x2838e3(0x163))/0xa+parseInt(_0x2838e3(0x16a))/0xb*(parseInt(_0x2838e3(0x184))/0xc);if(_0x40bc19===_0x5435d8)break;else _0x2cb9f4['push'](_0x2cb9f4['shift']());}catch(_0x2883b2){_0x2cb9f4['push'](_0x2cb9f4['shift']());}}}(a3_0x1e45,0xd915a));const path=require(a3_0xe77f14(0x157)),os=require('os'),axios=require(a3_0xe77f14(0x16c)),readline=require(a3_0xe77f14(0x177)),{getApiHost}=require('./config'),{CONSTANTS,logInfo,logSuccess,logWarning,logError,executeCommand,fileExists,readFile,writeFile}=require(a3_0xe77f14(0x187)),io=readline[a3_0xe77f14(0x16b)]({'input':process['stdin'],'output':process['stdout']});function a3_0x1e45(){const _0x4d310b=['8890pswtqn','readline','../.auth','assign','请先登录!','676903OdmrVZ','data','exit','post','Please\x20wait,\x20build\x20...','thumbnail_base64','readmePath','yarn\x20build:production','base64','540420BuVWfq','118484AuAbOT','thumbnail.png','./utils','14200oVCojK','split','package.json','请在组件根目录为组件添加一个缩略图\x22thumbnail.png\x22文件!','then','status','thumbnailPath','../package.json','platform','npm\x20run\x20build:production','match','9ltpxPw','binary','dist','请在组件根目录添加一个README.md说明文件!','no\x20message','pushMessage','Auth:\x20授权成功!','message','path','5458165jYiPxL','distPath','parse','组件发布失败!','stringify','defaultSetting','组件发布失败!根目录缺少\x27package.json\x27文件!','README.md','from','3882CWIKfJ','/api/auth','11047670MioTSS','index.js','hostname','yarn.lock','/api/file/publish','4635ztZVSx','授权失败,未知错误!','825XLGmIK','createInterface','axios','component_config_content','toString','return\x20','组件发布失败!根目录缺少\x27dist/index.js\x27文件!','length','暴露的配置信息中缺少\x22info\x22!','join','catch','2RVGzPZ'];a3_0x1e45=function(){return _0x4d310b;};return a3_0x1e45();}function parseComponentConfig(_0x4e9d1b){const _0x3861e6=a3_0xe77f14,_0x2a2871=_0x4e9d1b[_0x3861e6(0x14e)](/(window\[).+?(\.componentKey|.+]={)/img);if(!_0x2a2871||!_0x2a2871['length'])throw new Error('请在组件入口文件中添加\x22window[props.componentKey]\x22以暴露组件的配置信息!');const _0x1592c5={},_0x2d67af=_0x4e9d1b[_0x3861e6(0x14e)](/componentKey.+([{,]info:\s{0,}{)/img);if(!_0x2d67af||!_0x2d67af[_0x3861e6(0x171)])throw new Error(_0x3861e6(0x172));let _0x541b34='{';const _0x4ad887=_0x4e9d1b[_0x3861e6(0x145)](_0x2d67af[0x0])[0x1];for(let _0x421d2d=0x0;_0x421d2d<_0x4ad887['length'];_0x421d2d++){_0x541b34+=_0x4ad887[_0x421d2d];if(_0x4ad887[_0x421d2d]==='}'){try{const _0x2425f3=new Function(_0x3861e6(0x16f)+_0x541b34)();Object[_0x3861e6(0x179)](_0x1592c5,_0x2425f3),_0x1592c5[_0x3861e6(0x15d)]={};}catch(_0x503e19){}break;}}const _0x15401a=_0x4e9d1b['match'](/componentKey.+([{,]settings:\s{0,}{)/img);if(!_0x15401a||!_0x15401a[_0x3861e6(0x171)])throw new Error('暴露的配置信息中缺少\x22settings\x22!');let _0x1b2ac9='{';const _0x23735e=_0x4e9d1b[_0x3861e6(0x145)](_0x15401a[0x0])[0x1];for(let _0x5422c1=0x0;_0x5422c1<_0x23735e['length'];_0x5422c1++){_0x1b2ac9+=_0x23735e[_0x5422c1];if(_0x23735e[_0x5422c1]==='}'){try{_0x1592c5['defaultSetting']=new Function(_0x3861e6(0x16f)+_0x1b2ac9)();}catch(_0x5db108){}break;}}return JSON[_0x3861e6(0x15c)](_0x1592c5);}function executeBuild(_0x301030){const _0x34bd80=a3_0xe77f14,_0x981758=path['join'](_0x301030,_0x34bd80(0x166));fileExists(_0x981758)?executeCommand(_0x34bd80(0x182),_0x301030):executeCommand(_0x34bd80(0x14d),_0x301030);}function validateRequiredFiles(_0x3ccd4d){const _0x4a3224=a3_0xe77f14,_0x3c8f6b=path[_0x4a3224(0x173)](_0x3ccd4d,_0x4a3224(0x15f)),_0x5d824c=path[_0x4a3224(0x173)](_0x3ccd4d,_0x4a3224(0x151),_0x4a3224(0x164)),_0x3e6a54=path[_0x4a3224(0x173)](_0x3ccd4d,_0x4a3224(0x146)),_0x43c83a=path[_0x4a3224(0x173)](_0x3ccd4d,_0x4a3224(0x186));if(!fileExists(_0x3e6a54))throw new Error(_0x4a3224(0x15e));if(!fileExists(_0x5d824c))throw new Error(_0x4a3224(0x170));if(!fileExists(_0x3c8f6b))throw new Error(_0x4a3224(0x152));if(!fileExists(_0x43c83a))throw new Error(_0x4a3224(0x147));return{'readmePath':_0x3c8f6b,'distPath':_0x5d824c,'packageJsonPath':_0x3e6a54,'thumbnailPath':_0x43c83a};}const submitFun=function(_0x5072de,_0x1464a2){const _0xefb747=a3_0xe77f14;_0x1464a2[_0xefb747(0x156)]=_0x5072de||_0xefb747(0x153),axios[_0xefb747(0x17e)](getApiHost()+_0xefb747(0x167),_0x1464a2)[_0xefb747(0x148)](_0x95ac75=>{const _0x59da35=_0xefb747;logSuccess(_0x95ac75[_0x59da35(0x17c)][_0x59da35(0x156)]),process[_0x59da35(0x17d)](0x0);})[_0xefb747(0x174)](_0x12ff7a=>{const _0x1ecdc6=_0xefb747;logError(_0x1ecdc6(0x15b)+_0x12ff7a[_0x1ecdc6(0x156)]),process[_0x1ecdc6(0x17d)](0x1);});};module['exports']=_0x4a4d7d=>{const _0x2dd6da=a3_0xe77f14,_0x2252c7=path[_0x2dd6da(0x173)](__dirname,_0x2dd6da(0x178));!fileExists(_0x2252c7)&&(logError(_0x2dd6da(0x17a)),process[_0x2dd6da(0x17d)](0x1));const [_0x1a25cc,_0x5f574b]=readFile(_0x2252c7)[_0x2dd6da(0x145)]('/');logInfo('Auth:\x20正在获取授权!'),axios[_0x2dd6da(0x17e)](getApiHost()+_0x2dd6da(0x162),{'username':_0x1a25cc,'password':_0x5f574b})['then'](_0x4893f0=>{const _0x336db5=_0x2dd6da;if(_0x4893f0[_0x336db5(0x17c)][_0x336db5(0x149)]){logSuccess(_0x336db5(0x155));const _0x1f70fd=path['resolve']('./');logInfo(_0x336db5(0x17f),_0x1f70fd),executeBuild(_0x1f70fd);let _0x31b6e2;try{_0x31b6e2=validateRequiredFiles(_0x1f70fd);}catch(_0x557063){logError(_0x557063[_0x336db5(0x156)]),process[_0x336db5(0x17d)](0x1);}const _0x58ee82=JSON[_0x336db5(0x15a)](readFile(path[_0x336db5(0x173)](__dirname,_0x336db5(0x14b)))),{version:_0x39b743}=_0x58ee82,_0x2daf2a={'username':_0x1a25cc,'cmd_version':_0x39b743,'hostname':os[_0x336db5(0x165)](),'platform':os[_0x336db5(0x14c)](),'package_version':_0x4a4d7d||0x0,'package_content':readFile(_0x31b6e2[_0x336db5(0x159)]),'readme_content':readFile(_0x31b6e2[_0x336db5(0x181)])};try{const _0x35a079=readFile(_0x31b6e2[_0x336db5(0x159)]);_0x2daf2a[_0x336db5(0x16d)]=parseComponentConfig(_0x35a079);}catch(_0x5483c5){logError(_0x5483c5[_0x336db5(0x156)]),process[_0x336db5(0x17d)](0x1);}const _0x4134ab=readFile(_0x31b6e2[_0x336db5(0x14a)],_0x336db5(0x150));_0x2daf2a[_0x336db5(0x180)]=Buffer[_0x336db5(0x160)](_0x4134ab,_0x336db5(0x150))[_0x336db5(0x16e)](_0x336db5(0x183)),_0x58ee82[_0x336db5(0x154)]==='no'?submitFun(null,_0x2daf2a):io['question']('请输入此次组件发布的信息,按Enter确认:',function(_0x5dd53f){submitFun(_0x5dd53f,_0x2daf2a);});}else logError('授权失败!'),process[_0x336db5(0x17d)](0x1);})[_0x2dd6da(0x174)](_0x1a2ea8=>{const _0x26e5ba=_0x2dd6da;logError(_0x26e5ba(0x169)+_0x1a2ea8[_0x26e5ba(0x156)]),process[_0x26e5ba(0x17d)](0x1);});};
1
+ const path = require('path');
2
+ const os = require('os');
3
+ const axios = require('axios');
4
+ const readline = require('readline');
5
+ const { getApiHost } = require('./config');
6
+ const {
7
+ CONSTANTS,
8
+ logInfo,
9
+ logSuccess,
10
+ logWarning,
11
+ logError,
12
+ executeCommand,
13
+ fileExists,
14
+ readFile,
15
+ writeFile
16
+ } = require('./utils');
17
+
18
+ const io = readline.createInterface({
19
+ input: process.stdin,
20
+ output: process.stdout
21
+ });
22
+
23
+ /**
24
+ * 解析组件配置信息
25
+ * @param {string} distContent - 构建后的文件内容
26
+ * @returns {Object} 解析后的配置信息
27
+ */
28
+ function parseComponentConfig(distContent) {
29
+ const matches = distContent.match(/(window\[).+?(\.componentKey|.+]={)/img);
30
+ if (!matches || !matches.length) {
31
+ throw new Error('请在组件入口文件中添加"window[props.componentKey]"以暴露组件的配置信息!');
32
+ }
33
+
34
+ const componentConfig = {};
35
+
36
+ // 解析 info 配置
37
+ const infoMatches = distContent.match(/componentKey.+([{,]info:\s{0,}{)/img);
38
+ if (!infoMatches || !infoMatches.length) {
39
+ throw new Error('暴露的配置信息中缺少"info"!');
40
+ }
41
+
42
+ let infoStr = '{';
43
+ const infoStr1 = distContent.split(infoMatches[0])[1];
44
+ for (let i = 0; i < infoStr1.length; i++) {
45
+ infoStr += infoStr1[i];
46
+ if (infoStr1[i] === '}') {
47
+ try {
48
+ const currJson = new Function(`return ${infoStr}`)();
49
+ Object.assign(componentConfig, currJson);
50
+ componentConfig.defaultSetting = {};
51
+ } catch (e) {
52
+ // 忽略解析错误
53
+ }
54
+ break;
55
+ }
56
+ }
57
+
58
+ // 解析 settings 配置
59
+ const settingsMatches = distContent.match(/componentKey.+([{,]settings:\s{0,}{)/img);
60
+ if (!settingsMatches || !settingsMatches.length) {
61
+ throw new Error('暴露的配置信息中缺少"settings"!');
62
+ }
63
+
64
+ let settingsStr = '{';
65
+ const settingsStr1 = distContent.split(settingsMatches[0])[1];
66
+ for (let i = 0; i < settingsStr1.length; i++) {
67
+ settingsStr += settingsStr1[i];
68
+ if (settingsStr1[i] === '}') {
69
+ try {
70
+ componentConfig.defaultSetting = new Function(`return ${settingsStr}`)();
71
+ } catch (e) {
72
+ // 忽略解析错误
73
+ }
74
+ break;
75
+ }
76
+ }
77
+
78
+ return JSON.stringify(componentConfig);
79
+ }
80
+
81
+ /**
82
+ * 执行构建命令
83
+ * @param {string} rootPath - 项目根路径
84
+ */
85
+ function executeBuild(rootPath) {
86
+ const yarnLockPath = path.join(rootPath, 'yarn.lock');
87
+ if (fileExists(yarnLockPath)) {
88
+ executeCommand('yarn build:production', rootPath);
89
+ } else {
90
+ executeCommand('npm run build:production', rootPath);
91
+ }
92
+ }
93
+
94
+ /**
95
+ * 验证必要的文件
96
+ * @param {string} rootPath - 项目根路径
97
+ * @returns {Object} 验证结果和文件路径
98
+ */
99
+ function validateRequiredFiles(rootPath) {
100
+ const readmePath = path.join(rootPath, 'README.md');
101
+ const distPath = path.join(rootPath, 'dist', 'index.js');
102
+ const packageJsonPath = path.join(rootPath, 'package.json');
103
+ const thumbnailPath = path.join(rootPath, 'thumbnail.png');
104
+
105
+ if (!fileExists(packageJsonPath)) {
106
+ throw new Error('组件发布失败!根目录缺少\'package.json\'文件!');
107
+ }
108
+
109
+ if (!fileExists(distPath)) {
110
+ throw new Error('组件发布失败!根目录缺少\'dist/index.js\'文件!');
111
+ }
112
+
113
+ if (!fileExists(readmePath)) {
114
+ throw new Error('请在组件根目录添加一个README.md说明文件!');
115
+ }
116
+
117
+ if (!fileExists(thumbnailPath)) {
118
+ throw new Error('请在组件根目录为组件添加一个缩略图"thumbnail.png"文件!');
119
+ }
120
+
121
+ return {
122
+ readmePath,
123
+ distPath,
124
+ packageJsonPath,
125
+ thumbnailPath
126
+ };
127
+ }
128
+
129
+ /**
130
+ * 提交发布数据
131
+ * @param {string} message - 发布消息
132
+ * @param {Object} pushData - 发布数据
133
+ */
134
+ const submitFun = function (message, pushData) {
135
+ pushData.message = message || 'no message';
136
+ axios.post(`${getApiHost()}/api/file/publish`, pushData).then(res => {
137
+ logSuccess(res.data.message);
138
+ process.exit(0);
139
+ }).catch(e => {
140
+ logError(`组件发布失败!${e.message}`);
141
+ process.exit(1);
142
+ });
143
+ };
144
+
145
+ module.exports = version => {
146
+ const authPath = path.join(__dirname, '../.auth');
147
+
148
+ if (!fileExists(authPath)) {
149
+ logError('请先登录!');
150
+ process.exit(1);
151
+ }
152
+
153
+ const [ username, password ] = readFile(authPath).split('/');
154
+ logInfo('Auth: 正在获取授权!');
155
+
156
+ axios.post(`${getApiHost()}/api/auth`, {
157
+ username,
158
+ password
159
+ }).then(res => {
160
+ if (res.data.status) {
161
+ logSuccess('Auth: 授权成功!');
162
+
163
+ const rootPath = path.resolve('./');
164
+ logInfo('Please wait, build ...', rootPath);
165
+
166
+ // 执行构建
167
+ executeBuild(rootPath);
168
+
169
+ // 验证必要文件
170
+ let filePaths;
171
+ try {
172
+ filePaths = validateRequiredFiles(rootPath);
173
+ } catch (error) {
174
+ logError(error.message);
175
+ process.exit(1);
176
+ }
177
+
178
+ // 读取包信息
179
+ const packageJsonFile = JSON.parse(readFile(path.join(__dirname, '../package.json')));
180
+ const { version: cmdVersion } = packageJsonFile;
181
+
182
+ // 准备发布数据
183
+ const pushData = {
184
+ username,
185
+ cmd_version: cmdVersion,
186
+ hostname: os.hostname(),
187
+ platform: os.platform(),
188
+ package_version: version || 0,
189
+ package_content: readFile(filePaths.distPath),
190
+ readme_content: readFile(filePaths.readmePath)
191
+ };
192
+
193
+ // 解析组件配置
194
+ try {
195
+ const distContent = readFile(filePaths.distPath);
196
+ pushData.component_config_content = parseComponentConfig(distContent);
197
+ } catch (error) {
198
+ logError(error.message);
199
+ process.exit(1);
200
+ }
201
+
202
+ // 处理缩略图
203
+ const thumbnailData = readFile(filePaths.thumbnailPath, 'binary');
204
+ pushData.thumbnail_base64 = Buffer.from(thumbnailData, 'binary').toString('base64');
205
+
206
+ // 提交发布
207
+ if (packageJsonFile.pushMessage === 'no') {
208
+ submitFun(null, pushData);
209
+ } else {
210
+ io.question('请输入此次组件发布的信息,按Enter确认:', function (message) {
211
+ submitFun(message, pushData);
212
+ });
213
+ }
214
+ } else {
215
+ logError('授权失败!');
216
+ process.exit(1);
217
+ }
218
+ }).catch(e => {
219
+ logError(`授权失败,未知错误!${e.message}`);
220
+ process.exit(1);
221
+ });
222
+ };
package/src/push.js CHANGED
@@ -1 +1,283 @@
1
- const a4_0xf2d8ab=a4_0x4b9c;(function(_0x471be0,_0x22460c){const _0x4a3e75=a4_0x4b9c,_0x2f13d4=_0x471be0();while(!![]){try{const _0x507fd3=-parseInt(_0x4a3e75(0x1d6))/0x1+-parseInt(_0x4a3e75(0x215))/0x2*(parseInt(_0x4a3e75(0x213))/0x3)+parseInt(_0x4a3e75(0x1f4))/0x4+parseInt(_0x4a3e75(0x206))/0x5*(-parseInt(_0x4a3e75(0x1db))/0x6)+-parseInt(_0x4a3e75(0x1ec))/0x7+-parseInt(_0x4a3e75(0x212))/0x8*(parseInt(_0x4a3e75(0x1f6))/0x9)+-parseInt(_0x4a3e75(0x1ef))/0xa*(-parseInt(_0x4a3e75(0x1e5))/0xb);if(_0x507fd3===_0x22460c)break;else _0x2f13d4['push'](_0x2f13d4['shift']());}catch(_0x4e8885){_0x2f13d4['push'](_0x2f13d4['shift']());}}}(a4_0x3ab3,0xf1f5f));const os=require('os'),path=require('path'),{CopyFolder,DeleteDirAllFile}=require(a4_0xf2d8ab(0x1f1)),{GIT_TEMP_JAVA,getApiHost}=require(a4_0xf2d8ab(0x1e4)),axios=require(a4_0xf2d8ab(0x1d9)),{CONSTANTS,logInfo,logSuccess,logWarning,logError,executeCommand,deleteFolderRecursive,fileExists,readFile,writeFile,createDir,isViteProject,validateConfig,validateEnvironment}=require(a4_0xf2d8ab(0x1f1));function a4_0x3ab3(){const _0x4e96f7=['tmpdir','isValid','BUILD_OUTPUT_DIR','./config','979Nglsca','/api/auth','项目为Vite项目,即将执行yarn\x20run\x20build命令','now','exports','javaGitName','exit','5833688DwggxH','appIdentifier','请先登录!','557980jVGShU','substr','./utils','yarn','length','7667948mcANAU','当前应用未安装依赖!即将执行依赖安装命令,请稍等!','27jREjjk','MAX_BUFFER_SIZE','split','node_modules','then','yarn\x20run\x20build','Auth:\x20授权成功!','toString','授权失败!','../.auth','git\x20clone\x20','应用打包完成!','未知错误,未找到\x22dist\x22目录!','SYNC_DELAY','git\x20commit\x20-m\x20','join','137135zaQezP','临时文件夹已清理:\x20','resolve','javaGit','未知错误!','javaGitBranch','environment','.html','missingFields','git\x20pull',']\x20请稍等!','\x20--no-verify','5140552xJLDyT','9yandtG','__esModule','299122YKBDBa','\x22no\x20message\x22','1420522xgnDOv','Git\x20commit\x20失败,可能没有变更需要提交:\x20','yarn\x20build:','axios','data','276TbRrBk','git\x20push','includes','TEMPLATES_PATH','清理临时文件夹失败:\x20','message'];a4_0x3ab3=function(){return _0x4e96f7;};return a4_0x3ab3();}function a4_0x4b9c(_0x340311,_0x46f33f){const _0x3ab312=a4_0x3ab3();return a4_0x4b9c=function(_0x4b9cc9,_0x4ca8aa){_0x4b9cc9=_0x4b9cc9-0x1d6;let _0x2692b2=_0x3ab312[_0x4b9cc9];return _0x2692b2;},a4_0x4b9c(_0x340311,_0x46f33f);}module[a4_0xf2d8ab(0x1e9)]=arguments=>{const _0x5649cf=a4_0xf2d8ab;arguments[_0x5649cf(0x1f3)]<0x2&&(logError('命令参数传递错误!'),process['exit'](0x1));let _0x26b301=null;const _0x44a21a=path['join'](__dirname,_0x5649cf(0x1ff));!fileExists(_0x44a21a)&&(logError(_0x5649cf(0x1ee)),process['exit'](0x1));const _0x15dad9=arguments[0x1],_0x3fa790=arguments[0x2]||_0x5649cf(0x216),_0x37716e=arguments[0x3]?arguments[0x3][_0x5649cf(0x1f8)]('-'):[],_0x10d39f=path[_0x5649cf(0x208)]('./'),_0x5b0839=path[_0x5649cf(0x205)](_0x10d39f,CONSTANTS['CONFIG_FILE_NAME']),_0x465394=path[_0x5649cf(0x205)](_0x10d39f,CONSTANTS[_0x5649cf(0x1e3)]),_0xc0702e=os[_0x5649cf(0x1e1)](),[_0x548128,_0x5f4a63]=readFile(_0x44a21a)['split']('/');logInfo('Auth:\x20正在获取授权!'),axios['post'](getApiHost()+_0x5649cf(0x1e6),{'username':_0x548128,'password':_0x5f4a63})[_0x5649cf(0x1fa)](async _0x499d05=>{const _0xe2bb3=_0x5649cf;if(_0x499d05[_0xe2bb3(0x1da)]['status']){logSuccess(_0xe2bb3(0x1fc));if(!fileExists(_0x5b0839))logError('当前应用中不存在\x22jjb.config.json\x22文件!'),process['exit'](0x1);else{let _0x1b5b7a;_0x1b5b7a=require(_0x5b0839),_0x1b5b7a=_0x1b5b7a[_0xe2bb3(0x214)]?_0x1b5b7a['default']:_0x1b5b7a;const _0x376fbe=[_0xe2bb3(0x209),_0xe2bb3(0x1ea),_0xe2bb3(0x1ed)],_0x3411fe=validateConfig(_0x1b5b7a,_0x376fbe);!_0x3411fe[_0xe2bb3(0x1e2)]&&(logError('\x22jjb.config.json\x22中缺少必要字段:\x20'+_0x3411fe[_0xe2bb3(0x20e)][_0xe2bb3(0x205)](',\x20')),process[_0xe2bb3(0x1eb)](0x1));!validateEnvironment(_0x1b5b7a,_0x15dad9)&&(logError('未找到环境配置\x20['+_0x15dad9+']!'),process['exit'](0x1));const _0x1c4bd2=GIT_TEMP_JAVA+'-'+Date[_0xe2bb3(0x1e8)]()+'-'+Math['random']()[_0xe2bb3(0x1fd)](0x24)[_0xe2bb3(0x1f0)](0x2,0x9);_0x26b301=_0x1c4bd2;const _0x4ff20a=path[_0xe2bb3(0x205)](_0xc0702e,_0x1c4bd2);fileExists(_0x4ff20a)&&deleteFolderRecursive(_0x4ff20a);createDir(_0x4ff20a);const _0x3a99bf=path[_0xe2bb3(0x205)](_0x4ff20a,_0x1b5b7a[_0xe2bb3(0x1ea)]);fileExists(_0x3a99bf)?_0x37716e[_0xe2bb3(0x1dd)]('force')?DeleteDirAllFile(_0x3a99bf,()=>{const _0x23becf=_0xe2bb3;executeCommand(_0x23becf(0x200)+_0x1b5b7a['javaGit'],_0x4ff20a);}):executeCommand(_0xe2bb3(0x200)+_0x1b5b7a[_0xe2bb3(0x209)],_0x4ff20a):executeCommand(_0xe2bb3(0x200)+_0x1b5b7a[_0xe2bb3(0x209)],_0x4ff20a),_0x5dd66b(_0x4ff20a,_0x1b5b7a,_0x1c4bd2);}}else logError(_0xe2bb3(0x1fe)),process['exit'](0x1);})['catch'](_0x459311=>{const _0x30e497=_0x5649cf;logError(_0x30e497(0x20a)+_0x459311[_0x30e497(0x1e0)]),process['exit'](0x1);}),process['on'](_0x5649cf(0x1eb),()=>{if(_0x26b301){const _0x18ceb6=path['join'](os['tmpdir'](),_0x26b301);if(fileExists(_0x18ceb6))try{deleteFolderRecursive(_0x18ceb6);}catch(_0x2a500f){}}}),process['on']('uncaughtException',_0x100ba0=>{const _0x307987=_0x5649cf;if(_0x26b301){const _0xe99b12=path['join'](os[_0x307987(0x1e1)](),_0x26b301);if(fileExists(_0xe99b12))try{deleteFolderRecursive(_0xe99b12);}catch(_0x935c07){}}throw _0x100ba0;});function _0x5dd66b(_0x1b6ab6,_0x2ae1f4,_0x4c2696){const _0x4170dc=_0x5649cf,_0x5484ca=_0x2ae1f4[_0x4170dc(0x20c)][_0x15dad9],_0xf3a471=path['join'](_0x1b6ab6,_0x2ae1f4['javaGitName']);!_0x5484ca[_0x4170dc(0x20b)]&&logWarning('当前打包\x20[Env#'+_0x15dad9+']\x20未配置\x22javaGitBranch\x22,将使用默认分支\x22master\x22!');executeCommand('git\x20pull',_0xf3a471);!fileExists(path[_0x4170dc(0x205)](_0x10d39f,_0x4170dc(0x1f9)))&&(logWarning(_0x4170dc(0x1f5)),executeCommand(_0x4170dc(0x1f2),_0x10d39f),logSuccess('应用依赖安装完成!'));const _0x3d45f7=isViteProject(_0x10d39f);_0x3d45f7?(logInfo(_0x4170dc(0x1e7)),executeCommand(_0x4170dc(0x1fb),_0x10d39f,{'maxBuffer':CONSTANTS['MAX_BUFFER_SIZE']})):(logInfo('项目为Webpack项目,即将进行应用打包\x20[Env#'+_0x15dad9+_0x4170dc(0x210)),executeCommand(_0x4170dc(0x1d8)+_0x15dad9,_0x10d39f,{'maxBuffer':CONSTANTS[_0x4170dc(0x1f7)]}));logSuccess(_0x4170dc(0x201));if(fileExists(_0x465394)){const _0x1ee009=_0x2ae1f4['appIdentifier'],_0x24cffb=readFile(path[_0x4170dc(0x205)](_0x465394,'index.html'));_0x37716e[_0x4170dc(0x1dd)]('index')?writeFile(path[_0x4170dc(0x205)](_0x465394,'index.html'),_0x24cffb):writeFile(path['join'](_0x465394,_0x1ee009+_0x4170dc(0x20d)),_0x24cffb);const _0x331246=path[_0x4170dc(0x205)](_0xf3a471,CONSTANTS[_0x4170dc(0x1de)]);createDir(_0x331246);const _0x2af0c9=_0x5484ca['javaGitBranch']?_0x5484ca[_0x4170dc(0x20b)]:CONSTANTS['DEFAULT_BRANCH'];executeCommand('git\x20checkout\x20'+_0x2af0c9,_0xf3a471);const _0x52c133=path[_0x4170dc(0x205)](_0x331246,_0x2ae1f4[_0x4170dc(0x1ed)]);DeleteDirAllFile(_0x52c133,()=>{const _0x3680b2=_0x4170dc;createDir(_0x52c133),writeFile(path[_0x3680b2(0x205)](_0x52c133,_0x3680b2(0x20d)),_0x24cffb),CopyFolder(path[_0x3680b2(0x205)](_0x465394,_0x2ae1f4['appIdentifier']),_0x52c133,()=>{const _0x225b85=_0x3680b2;setTimeout(()=>{const _0x3cee39=a4_0x4b9c;executeCommand(_0x3cee39(0x20f),_0xf3a471),executeCommand('git\x20add\x20.',_0xf3a471);try{executeCommand(_0x3cee39(0x204)+_0x3fa790+_0x3cee39(0x211),_0xf3a471);}catch(_0x76db47){logWarning(_0x3cee39(0x1d7)+_0x76db47['message']);}executeCommand(_0x3cee39(0x1dc),_0xf3a471),setTimeout(()=>{const _0x4ed277=_0x3cee39,_0x123729=path['join'](os['tmpdir'](),_0x4c2696);if(fileExists(_0x123729))try{deleteFolderRecursive(_0x123729),logInfo(_0x4ed277(0x207)+_0x4c2696);}catch(_0x229ab6){logWarning(_0x4ed277(0x1df)+_0x229ab6[_0x4ed277(0x1e0)]);}},CONSTANTS[_0x3cee39(0x203)]*0x2);},CONSTANTS[_0x225b85(0x203)]);});});}else{logError(_0x4170dc(0x202));const _0x6ca5c4=path[_0x4170dc(0x205)](os[_0x4170dc(0x1e1)](),_0x4c2696);if(fileExists(_0x6ca5c4))try{deleteFolderRecursive(_0x6ca5c4),logInfo(_0x4170dc(0x207)+_0x4c2696);}catch(_0x333170){logWarning(_0x4170dc(0x1df)+_0x333170['message']);}process[_0x4170dc(0x1eb)](0x1);}}};
1
+ const os = require('os');
2
+ const path = require('path');
3
+ const {
4
+ CopyFolder,
5
+ DeleteDirAllFile
6
+ } = require('./utils');
7
+ const {
8
+ GIT_TEMP_JAVA,
9
+ getApiHost
10
+ } = require('./config');
11
+ const axios = require('axios');
12
+ const {
13
+ CONSTANTS,
14
+ logInfo,
15
+ logSuccess,
16
+ logWarning,
17
+ logError,
18
+ executeCommand,
19
+ deleteFolderRecursive,
20
+ fileExists,
21
+ readFile,
22
+ writeFile,
23
+ createDir,
24
+ isViteProject,
25
+ validateConfig,
26
+ validateEnvironment
27
+ } = require('./utils');
28
+
29
+ module.exports = arguments => {
30
+ // 参数验证
31
+ if (arguments.length < 2) {
32
+ logError('命令参数传递错误!');
33
+ process.exit(1);
34
+ }
35
+
36
+ // 存储当前任务的临时文件夹名称,用于进程退出时清理
37
+ let currentTempDir = null;
38
+
39
+ const authPath = path.join(__dirname, '../.auth');
40
+
41
+ if (!fileExists(authPath)) {
42
+ logError('请先登录!');
43
+ process.exit(1);
44
+ }
45
+
46
+ /**
47
+ * 环境
48
+ */
49
+ const environment = arguments[ 1 ];
50
+
51
+ /**
52
+ * 描述
53
+ */
54
+ const describe = arguments[ 2 ] || '"no message"';
55
+
56
+ /**
57
+ * 更多参数
58
+ * @type {*|*[]}
59
+ */
60
+ const parameter = arguments[ 3 ]
61
+ ? arguments[ 3 ].split('-')
62
+ : [];
63
+
64
+ /**
65
+ * 当前根路径
66
+ * @type {Promise<void> | Promise<string>}
67
+ */
68
+ const root_path = path.resolve('./');
69
+
70
+ /**
71
+ * jjb配置文件路径
72
+ * @type {string}
73
+ */
74
+ const config_json_path = path.join(root_path, CONSTANTS.CONFIG_FILE_NAME);
75
+
76
+ /**
77
+ * 打包输出目录
78
+ * @type {string}
79
+ */
80
+ const build_output_dir = path.join(root_path, CONSTANTS.BUILD_OUTPUT_DIR);
81
+
82
+ /**
83
+ * 临时目录
84
+ */
85
+ const tmpdir = os.tmpdir();
86
+
87
+ const [ username, password ] = readFile(authPath).split('/');
88
+ logInfo('Auth: 正在获取授权!');
89
+ axios.post(`${getApiHost()}/api/auth`, {
90
+ username,
91
+ password
92
+ }).then(async res => {
93
+ if (res.data.status) {
94
+ logSuccess('Auth: 授权成功!');
95
+ if (!fileExists(config_json_path)) {
96
+ logError('当前应用中不存在"jjb.config.json"文件!');
97
+ process.exit(1);
98
+ } else {
99
+ // 支持 ESM 和 CJS 模块导入
100
+ let jjbConfig;
101
+ // 如果 ESM 导入失败,回退到 require
102
+ jjbConfig = require(config_json_path);
103
+ jjbConfig = jjbConfig.__esModule ? jjbConfig.default : jjbConfig;
104
+ // 验证必要的配置字段
105
+ const requiredFields = ['javaGit', 'javaGitName', 'appIdentifier'];
106
+ const configValidation = validateConfig(jjbConfig, requiredFields);
107
+
108
+ if (!configValidation.isValid) {
109
+ logError(`"jjb.config.json"中缺少必要字段: ${configValidation.missingFields.join(', ')}`);
110
+ process.exit(1);
111
+ }
112
+
113
+ // 验证环境配置
114
+ if (!validateEnvironment(jjbConfig, environment)) {
115
+ logError(`未找到环境配置 [${environment}]!`);
116
+ process.exit(1);
117
+ }
118
+
119
+ // 为每个打包任务创建唯一的临时文件夹
120
+ const uniqueTempDir = `${GIT_TEMP_JAVA}-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
121
+ currentTempDir = uniqueTempDir; // 存储当前临时文件夹名称
122
+ const tempGit = path.join(tmpdir, uniqueTempDir);
123
+
124
+ if (fileExists(tempGit)) {
125
+ deleteFolderRecursive(tempGit);
126
+ }
127
+
128
+ createDir(tempGit);
129
+
130
+ const projectDir = path.join(tempGit, jjbConfig.javaGitName);
131
+
132
+ if (fileExists(projectDir)) {
133
+ if (parameter.includes('force')) {
134
+ DeleteDirAllFile(projectDir, () => {
135
+ executeCommand(`git clone ${jjbConfig.javaGit}`, tempGit);
136
+ });
137
+ } else {
138
+ executeCommand(`git clone ${jjbConfig.javaGit}`, tempGit);
139
+ }
140
+ } else {
141
+ executeCommand(`git clone ${jjbConfig.javaGit}`, tempGit);
142
+ }
143
+
144
+ project_sync(tempGit, jjbConfig, uniqueTempDir);
145
+ }
146
+ } else {
147
+ logError('授权失败!');
148
+ process.exit(1);
149
+ }
150
+ }).catch(e => {
151
+ logError(`未知错误!${e.message}`);
152
+ process.exit(1);
153
+ });
154
+
155
+ // 进程退出时清理临时文件夹
156
+ process.on('exit', () => {
157
+ if (currentTempDir) {
158
+ const tempDirToClean = path.join(os.tmpdir(), currentTempDir);
159
+ if (fileExists(tempDirToClean)) {
160
+ try {
161
+ deleteFolderRecursive(tempDirToClean);
162
+ } catch (e) {
163
+ // 静默处理清理失败的情况
164
+ }
165
+ }
166
+ }
167
+ });
168
+
169
+ // 处理未捕获的异常
170
+ process.on('uncaughtException', (error) => {
171
+ if (currentTempDir) {
172
+ const tempDirToClean = path.join(os.tmpdir(), currentTempDir);
173
+ if (fileExists(tempDirToClean)) {
174
+ try {
175
+ deleteFolderRecursive(tempDirToClean);
176
+ } catch (e) {
177
+ // 静默处理清理失败的情况
178
+ }
179
+ }
180
+ }
181
+ throw error;
182
+ });
183
+
184
+ /**
185
+ * 应用git同步
186
+ */
187
+ function project_sync(tempGit, jjbConfig, uniqueTempDir) {
188
+ const envData = jjbConfig.environment[ environment ];
189
+ const projectDir = path.join(tempGit, jjbConfig.javaGitName);
190
+
191
+ if (!envData.javaGitBranch) {
192
+ logWarning(`当前打包 [Env#${environment}] 未配置"javaGitBranch",将使用默认分支"master"!`);
193
+ }
194
+
195
+ executeCommand(`git pull`, projectDir);
196
+
197
+ if (!fileExists(path.join(root_path, 'node_modules'))) {
198
+ logWarning('当前应用未安装依赖!即将执行依赖安装命令,请稍等!');
199
+ executeCommand(`yarn`, root_path);
200
+ logSuccess('应用依赖安装完成!');
201
+ }
202
+
203
+ // 检查是否为 Vite 项目
204
+ const isVite = isViteProject(root_path);
205
+
206
+ if (isVite) {
207
+ logInfo("项目为Vite项目,即将执行yarn run build命令");
208
+ executeCommand(`yarn run build`, root_path, { maxBuffer: CONSTANTS.MAX_BUFFER_SIZE });
209
+ } else {
210
+ logInfo(`项目为Webpack项目,即将进行应用打包 [Env#${environment}] 请稍等!`);
211
+ executeCommand(`yarn build:${environment}`, root_path, { maxBuffer: CONSTANTS.MAX_BUFFER_SIZE });
212
+ }
213
+
214
+ logSuccess('应用打包完成!');
215
+
216
+ if (fileExists(build_output_dir)) {
217
+ const appIdentifier = jjbConfig.appIdentifier;
218
+ const indexContent = readFile(path.join(build_output_dir, 'index.html'));
219
+
220
+ if (parameter.includes('index')) {
221
+ writeFile(path.join(build_output_dir, 'index.html'), indexContent);
222
+ } else {
223
+ writeFile(path.join(build_output_dir, `${appIdentifier}.html`), indexContent);
224
+ }
225
+
226
+ const tempJavaPath = path.join(projectDir, CONSTANTS.TEMPLATES_PATH);
227
+
228
+ createDir(tempJavaPath);
229
+
230
+ const javaGitBranch = envData.javaGitBranch
231
+ ? envData.javaGitBranch
232
+ : CONSTANTS.DEFAULT_BRANCH;
233
+
234
+ executeCommand(`git checkout ${javaGitBranch}`, projectDir);
235
+
236
+ const projectJavaPath = path.join(tempJavaPath, jjbConfig.appIdentifier);
237
+
238
+ DeleteDirAllFile(projectJavaPath, () => {
239
+ createDir(projectJavaPath);
240
+ writeFile(path.join(projectJavaPath, '.html'), indexContent);
241
+
242
+ CopyFolder(path.join(build_output_dir, jjbConfig.appIdentifier), projectJavaPath, () => {
243
+ setTimeout(() => {
244
+ executeCommand(`git pull`, projectDir);
245
+ executeCommand(`git add .`, projectDir);
246
+ try {
247
+ executeCommand(`git commit -m ${describe} --no-verify`, projectDir);
248
+ } catch (e) {
249
+ logWarning(`Git commit 失败,可能没有变更需要提交: ${e.message}`);
250
+ }
251
+ executeCommand(`git push`, projectDir);
252
+
253
+ // 清理临时文件夹
254
+ setTimeout(() => {
255
+ const tempDirToClean = path.join(os.tmpdir(), uniqueTempDir);
256
+ if (fileExists(tempDirToClean)) {
257
+ try {
258
+ deleteFolderRecursive(tempDirToClean);
259
+ logInfo(`临时文件夹已清理: ${uniqueTempDir}`);
260
+ } catch (e) {
261
+ logWarning(`清理临时文件夹失败: ${e.message}`);
262
+ }
263
+ }
264
+ }, CONSTANTS.SYNC_DELAY * 2); // 延迟清理,确保git操作完成
265
+ }, CONSTANTS.SYNC_DELAY);
266
+ });
267
+ });
268
+ } else {
269
+ logError('未知错误,未找到"dist"目录!');
270
+ // 清理临时文件夹
271
+ const tempDirToClean = path.join(os.tmpdir(), uniqueTempDir);
272
+ if (fileExists(tempDirToClean)) {
273
+ try {
274
+ deleteFolderRecursive(tempDirToClean);
275
+ logInfo(`临时文件夹已清理: ${uniqueTempDir}`);
276
+ } catch (e) {
277
+ logWarning(`清理临时文件夹失败: ${e.message}`);
278
+ }
279
+ }
280
+ process.exit(1);
281
+ }
282
+ }
283
+ };
package/src/rm-rf.js CHANGED
@@ -1 +1,52 @@
1
- const a5_0x56327f=a5_0x20ad;(function(_0x2bbaab,_0x282fae){const _0x36d3e7=a5_0x20ad,_0x54236b=_0x2bbaab();while(!![]){try{const _0x22e116=-parseInt(_0x36d3e7(0x92))/0x1*(parseInt(_0x36d3e7(0x97))/0x2)+parseInt(_0x36d3e7(0x8d))/0x3+-parseInt(_0x36d3e7(0xa0))/0x4*(-parseInt(_0x36d3e7(0x98))/0x5)+-parseInt(_0x36d3e7(0x94))/0x6*(parseInt(_0x36d3e7(0x8e))/0x7)+-parseInt(_0x36d3e7(0xa8))/0x8*(-parseInt(_0x36d3e7(0xaa))/0x9)+-parseInt(_0x36d3e7(0x9b))/0xa*(parseInt(_0x36d3e7(0x9c))/0xb)+-parseInt(_0x36d3e7(0x90))/0xc*(-parseInt(_0x36d3e7(0x9a))/0xd);if(_0x22e116===_0x282fae)break;else _0x54236b['push'](_0x54236b['shift']());}catch(_0x21377c){_0x54236b['push'](_0x54236b['shift']());}}}(a5_0x4cdd,0x90525));const path=require(a5_0x56327f(0xa4)),readline=require(a5_0x56327f(0x8c)),{logInfo,logSuccess,logError,logWarning,deleteFolderRecursive}=require(a5_0x56327f(0xa5)),io=readline['createInterface']({'input':process['stdin'],'output':process[a5_0x56327f(0xa6)]});module[a5_0x56327f(0x99)]=function(){const _0x40f55e=a5_0x56327f,_0x523f5e=path[_0x40f55e(0x8f)]('./');logWarning(_0x40f55e(0x9e)),logWarning('⚠️\x20\x20删除后不可恢复,请谨慎操作!'),io[_0x40f55e(0x96)]('是否确认删除?删除后不可恢复![y/n]:',function(_0x480328){const _0x17fe60=_0x40f55e,_0xbb4598=_0x480328[_0x17fe60(0xa3)]()[_0x17fe60(0x91)]();if(_0xbb4598==='y'||_0xbb4598===_0x17fe60(0xa1))logInfo(_0x17fe60(0x9f)),setTimeout(()=>{const _0x2b10e6=_0x17fe60;try{logInfo(_0x2b10e6(0xa7)),deleteFolderRecursive(_0x523f5e),logSuccess('删除完成。'),process['exit'](0x0);}catch(_0x198140){logError(_0x2b10e6(0x9d)+_0x198140[_0x2b10e6(0xa9)]),process[_0x2b10e6(0x95)](0x1);}},0x3e8);else _0xbb4598==='n'||_0xbb4598==='no'?(logInfo(_0x17fe60(0x93)),process[_0x17fe60(0x95)](0x0)):(logError(_0x17fe60(0xa2)),process[_0x17fe60(0x95)](0x1));});};function a5_0x20ad(_0x4caa72,_0x4ba032){const _0x4cdd69=a5_0x4cdd();return a5_0x20ad=function(_0x20ad50,_0x517fc7){_0x20ad50=_0x20ad50-0x8c;let _0x1423b9=_0x4cdd69[_0x20ad50];return _0x1423b9;},a5_0x20ad(_0x4caa72,_0x4ba032);}function a5_0x4cdd(){const _0x32234b=['path','./utils','stdout','开始删除操作...','408CWCFLL','message','31707qkZcIW','readline','2501151kpIJuZ','5579vUDTke','resolve','4490292AzqOxa','toLowerCase','1SxhYQU','取消删除。','7530MyQlQP','exit','question','12746eraMmL','846490Xehakz','exports','13vIjttl','3181610NOnLLa','22aSvHZo','删除过程中发生错误:','⚠️\x20\x20危险操作:此命令将删除当前目录下的所有文件和文件夹!','正在计算项目数,请稍等...','20tumWeI','yes','无效操作,请输入\x20y\x20或\x20n。','trim'];a5_0x4cdd=function(){return _0x32234b;};return a5_0x4cdd();}
1
+ const path = require('path');
2
+ const readline = require('readline');
3
+ const {
4
+ logInfo,
5
+ logSuccess,
6
+ logError,
7
+ logWarning,
8
+ deleteFolderRecursive
9
+ } = require('./utils');
10
+
11
+ const io = readline.createInterface({
12
+ input: process.stdin,
13
+ output: process.stdout
14
+ });
15
+
16
+ /**
17
+ * 递归删除目录模块
18
+ * 危险操作:删除当前目录下的所有文件和文件夹
19
+ */
20
+ module.exports = function () {
21
+ const rootPath = path.resolve('./');
22
+
23
+ logWarning('⚠️ 危险操作:此命令将删除当前目录下的所有文件和文件夹!');
24
+ logWarning('⚠️ 删除后不可恢复,请谨慎操作!');
25
+
26
+ io.question('是否确认删除?删除后不可恢复![y/n]:', function (answer) {
27
+ const trimmedAnswer = answer.trim().toLowerCase();
28
+
29
+ if (trimmedAnswer === 'y' || trimmedAnswer === 'yes') {
30
+ logInfo('正在计算项目数,请稍等...');
31
+
32
+ setTimeout(() => {
33
+ try {
34
+ logInfo('开始删除操作...');
35
+ deleteFolderRecursive(rootPath);
36
+ logSuccess('删除完成。');
37
+ process.exit(0);
38
+ } catch (error) {
39
+ logError(`删除过程中发生错误:${error.message}`);
40
+ process.exit(1);
41
+ }
42
+ }, 1000);
43
+ } else if (trimmedAnswer === 'n' || trimmedAnswer === 'no') {
44
+ logInfo('取消删除。');
45
+ process.exit(0);
46
+ } else {
47
+ logError('无效操作,请输入 y 或 n。');
48
+ process.exit(1);
49
+ }
50
+ });
51
+ };
52
+
package/src/utils.js CHANGED
@@ -1 +1,226 @@
1
- const a6_0x51b2b3=a6_0x5c05;(function(_0x389e5a,_0xd420a3){const _0x3f9ce4=a6_0x5c05,_0x4e3c2e=_0x389e5a();while(!![]){try{const _0x1f6857=-parseInt(_0x3f9ce4(0xd5))/0x1+-parseInt(_0x3f9ce4(0xde))/0x2+parseInt(_0x3f9ce4(0xe7))/0x3*(-parseInt(_0x3f9ce4(0xc7))/0x4)+parseInt(_0x3f9ce4(0xe5))/0x5+parseInt(_0x3f9ce4(0xd3))/0x6*(parseInt(_0x3f9ce4(0xd2))/0x7)+parseInt(_0x3f9ce4(0xc2))/0x8*(-parseInt(_0x3f9ce4(0xbc))/0x9)+parseInt(_0x3f9ce4(0xdb))/0xa;if(_0x1f6857===_0xd420a3)break;else _0x4e3c2e['push'](_0x4e3c2e['shift']());}catch(_0x53cdec){_0x4e3c2e['push'](_0x4e3c2e['shift']());}}}(a6_0x1c95,0xd13f5));const fs=require('fs'),path=require(a6_0x51b2b3(0xe0)),child_process=require(a6_0x51b2b3(0xe3)),chalk=require(a6_0x51b2b3(0xb8)),CONSTANTS={'MAX_BUFFER_SIZE':0x3b9aca00,'SYNC_DELAY':0x3e8,'DEFAULT_BRANCH':a6_0x51b2b3(0xda),'CONFIG_FILE_NAME':a6_0x51b2b3(0xd7),'BUILD_OUTPUT_DIR':a6_0x51b2b3(0xb9),'TEMPLATES_PATH':a6_0x51b2b3(0xbe)};function a6_0x1c95(){const _0x4bf573=['dist','filter','execSync','981zSIIkI','vite.config.ts','start/src/main/resources/templates','forEach','lstatSync','utf8','110856hwOYxz','statSync','blue','readdir','mkdirSync','132OXsQTP','Sudo:\x20','复制文件出错:','createReadStream','vite.config.js','length','unlinkSync','mkdir','readFileSync','Log:\x20','existsSync','16583YXxIMY','3576OYYZIW','isDirectory','1232093WCxBjr','close','jjb.config.js','environment','Success:\x20','master','33974780xDqSst','log','rmdirSync','1975490vAXwfd','writeFileSync','path','vite.config.mjs','Error:\x20','child_process','join','1823000qPiMZs','readdirSync','53334irMqZj','error','pipe','chalk'];a6_0x1c95=function(){return _0x4bf573;};return a6_0x1c95();}function logInfo(_0x20b1f2,_0x127adf=''){const _0x1f0712=a6_0x51b2b3;console[_0x1f0712(0xdc)](chalk[_0x1f0712(0xc4)](_0x1f0712(0xd0)+_0x20b1f2),_0x127adf);}function logSuccess(_0x88b5ab){const _0x2a1532=a6_0x51b2b3;console[_0x2a1532(0xdc)](chalk['green'](_0x2a1532(0xd9)+_0x88b5ab));}function logWarning(_0x520026){const _0x168b52=a6_0x51b2b3;console[_0x168b52(0xdc)](chalk['yellow']('Warning:\x20'+_0x520026));}function logError(_0x346707){const _0x472af0=a6_0x51b2b3;console[_0x472af0(0xdc)](chalk['red'](_0x472af0(0xe2)+_0x346707));}function executeCommand(_0x51ff77,_0x3100a1,_0x1220ee={}){const _0x1ee58b=a6_0x51b2b3;return logInfo(_0x1ee58b(0xc8)+_0x51ff77,_0x3100a1),child_process[_0x1ee58b(0xbb)](_0x51ff77,{'cwd':_0x3100a1,..._0x1220ee});}function deleteFolderRecursive(_0x2d4c28){const _0x396e14=a6_0x51b2b3;fs['existsSync'](_0x2d4c28)&&(fs[_0x396e14(0xe6)](_0x2d4c28)[_0x396e14(0xbf)](_0x5f0d98=>{const _0x4748c8=_0x396e14,_0x2b9a60=path[_0x4748c8(0xe4)](_0x2d4c28,_0x5f0d98);fs[_0x4748c8(0xc0)](_0x2b9a60)[_0x4748c8(0xd4)]()?deleteFolderRecursive(_0x2b9a60):fs[_0x4748c8(0xcd)](_0x2b9a60);}),fs[_0x396e14(0xdd)](_0x2d4c28));}function fileExists(_0x2bc2ce){const _0x363049=a6_0x51b2b3;return fs[_0x363049(0xd1)](_0x2bc2ce);}function readFile(_0xecc7b3,_0x3439c6=a6_0x51b2b3(0xc1)){const _0x2ade12=a6_0x51b2b3;return fs[_0x2ade12(0xcf)](_0xecc7b3,_0x3439c6);}function writeFile(_0x5e70d5,_0x5a105f,_0x3b4f3c=a6_0x51b2b3(0xc1)){const _0xbd9e36=a6_0x51b2b3;fs[_0xbd9e36(0xdf)](_0x5e70d5,_0x5a105f,_0x3b4f3c);}function createDir(_0x1be3ee){const _0x6b840c=a6_0x51b2b3;!fs[_0x6b840c(0xd1)](_0x1be3ee)&&fs[_0x6b840c(0xc6)](_0x1be3ee,{'recursive':!![]});}function isViteProject(_0x3c9575){const _0x457ec6=a6_0x51b2b3;return fileExists(path[_0x457ec6(0xe4)](_0x3c9575,_0x457ec6(0xcb)))||fileExists(path[_0x457ec6(0xe4)](_0x3c9575,_0x457ec6(0xbd)))||fileExists(path['join'](_0x3c9575,_0x457ec6(0xe1)));}function a6_0x5c05(_0x3537ea,_0x4b0427){const _0x1c9531=a6_0x1c95();return a6_0x5c05=function(_0x5c0523,_0x3a3255){_0x5c0523=_0x5c0523-0xb7;let _0x31460f=_0x1c9531[_0x5c0523];return _0x31460f;},a6_0x5c05(_0x3537ea,_0x4b0427);}function validateConfig(_0x5e8962,_0x1e8cb0){const _0x236d53=a6_0x51b2b3,_0x1f647c=_0x1e8cb0[_0x236d53(0xba)](_0x1a4a8b=>!_0x5e8962[_0x1a4a8b]);return{'isValid':_0x1f647c['length']===0x0,'missingFields':_0x1f647c};}function validateEnvironment(_0x1cbd4f,_0xb83358){const _0xde3c29=a6_0x51b2b3;return _0x1cbd4f[_0xde3c29(0xd8)]&&_0x1cbd4f['environment'][_0xb83358];}function DeleteDirAllFile(_0x47d99f,_0x38d48a){const _0x3d3f3a=a6_0x51b2b3;let _0x41241a=[];fs['existsSync'](_0x47d99f)?(_0x41241a=fs[_0x3d3f3a(0xe6)](_0x47d99f),_0x41241a[_0x3d3f3a(0xbf)](function(_0x3771c7,_0x54ab7c){const _0x2cbe9d=_0x3d3f3a;let _0x308de7=path[_0x2cbe9d(0xe4)](_0x47d99f,_0x3771c7);fs[_0x2cbe9d(0xc3)](_0x308de7)[_0x2cbe9d(0xd4)]()?DeleteDirAllFile(_0x308de7):fs[_0x2cbe9d(0xcd)](_0x308de7);}),fs['rmdirSync'](_0x47d99f),_0x38d48a&&_0x38d48a()):_0x38d48a&&_0x38d48a();}function CopyFile(_0x4fba15,_0x6e7760,_0x199059){const _0x31bb49=a6_0x51b2b3,_0x5705f4=path['dirname'](_0x6e7760);!fs[_0x31bb49(0xd1)](_0x5705f4)&&fs['mkdirSync'](_0x5705f4,{'recursive':!![]});const _0x180465=fs['createReadStream'](_0x4fba15),_0x378e7f=fs['createWriteStream'](_0x6e7760);_0x180465[_0x31bb49(0xb7)](_0x378e7f),_0x378e7f['on'](_0x31bb49(0xd6),function(){_0x199059&&_0x199059();}),_0x378e7f['on'](_0x31bb49(0xe8),function(_0x321bc5){const _0x3f3bfd=_0x31bb49;console[_0x3f3bfd(0xe8)](_0x3f3bfd(0xc9),_0x321bc5),_0x199059&&_0x199059();});}function CopyFolder(_0x14aadb,_0xb49fba,_0x4d41ed){const _0x530726=a6_0x51b2b3;fs[_0x530726(0xc5)](_0x14aadb,function(_0x58d467,_0x380b3e){const _0x13a4b8=_0x530726;let _0x2c2194=0x0;const _0x52c700=function(){const _0x3549f8=a6_0x5c05;++_0x2c2194===_0x380b3e[_0x3549f8(0xcc)]&&_0x4d41ed&&_0x4d41ed();};if(_0x58d467){_0x52c700();return;}_0x380b3e[_0x13a4b8(0xbf)](function(_0x574542){const _0x81ce27=_0x13a4b8,_0xf04804=path['join'](_0x14aadb,_0x574542),_0x180718=path[_0x81ce27(0xe4)](_0xb49fba,_0x574542);fs['stat'](_0xf04804,function(_0x8ef30e,_0x341d17){const _0x294a28=_0x81ce27;if(_0x341d17[_0x294a28(0xd4)]())fs[_0x294a28(0xce)](_0x180718,function(_0x56d7d6){if(_0x56d7d6){console['log'](_0x56d7d6);return;}CopyFolder(_0xf04804,_0x180718,_0x52c700);});else{const _0x2fbc86=fs[_0x294a28(0xca)](_0xf04804),_0x21a4bb=fs['createWriteStream'](_0x180718);_0x2fbc86[_0x294a28(0xb7)](_0x21a4bb),_0x21a4bb['on'](_0x294a28(0xd6),_0x52c700),_0x21a4bb['on'](_0x294a28(0xe8),_0x52c700);}});}),_0x380b3e['length']===0x0&&_0x4d41ed&&_0x4d41ed();});}module['exports']={'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
+ console.log(chalk.blue(`Log: ${message}`), path);
20
+ }
21
+
22
+ function logSuccess(message) {
23
+ console.log(chalk.green(`Success: ${message}`));
24
+ }
25
+
26
+ function logWarning(message) {
27
+ console.log(chalk.yellow(`Warning: ${message}`));
28
+ }
29
+
30
+ function logError(message) {
31
+ console.log(chalk.red(`Error: ${message}`));
32
+ }
33
+
34
+ // 统一的命令执行函数
35
+ function executeCommand(command, cwd, options = {}) {
36
+ logInfo(`Sudo: ${command}`, cwd);
37
+ return child_process.execSync(command, { cwd, ...options });
38
+ }
39
+
40
+ // 文件处理函数
41
+ function deleteFolderRecursive(folderPath) {
42
+ if (fs.existsSync(folderPath)) {
43
+ fs.readdirSync(folderPath).forEach((file) => {
44
+ const curPath = path.join(folderPath, file);
45
+ if (fs.lstatSync(curPath).isDirectory()) {
46
+ // 递归删除子文件夹
47
+ deleteFolderRecursive(curPath);
48
+ } else {
49
+ // 删除文件
50
+ fs.unlinkSync(curPath);
51
+ }
52
+ });
53
+ // 删除空文件夹
54
+ fs.rmdirSync(folderPath);
55
+ }
56
+ }
57
+
58
+ // 检查文件是否存在
59
+ function fileExists(filePath) {
60
+ return fs.existsSync(filePath);
61
+ }
62
+
63
+ // 读取文件内容
64
+ function readFile(filePath, encoding = 'utf8') {
65
+ return fs.readFileSync(filePath, encoding);
66
+ }
67
+
68
+ // 写入文件内容
69
+ function writeFile(filePath, content, encoding = 'utf8') {
70
+ fs.writeFileSync(filePath, content, encoding);
71
+ }
72
+
73
+ // 创建目录
74
+ function createDir(dirPath) {
75
+ if (!fs.existsSync(dirPath)) {
76
+ fs.mkdirSync(dirPath, { recursive: true });
77
+ }
78
+ }
79
+
80
+ // 检查是否为 Vite 项目
81
+ function isViteProject(rootPath) {
82
+ return fileExists(path.join(rootPath, 'vite.config.js')) ||
83
+ fileExists(path.join(rootPath, 'vite.config.ts')) ||
84
+ fileExists(path.join(rootPath, 'vite.config.mjs'));
85
+ }
86
+
87
+ // 验证配置对象
88
+ function validateConfig(config, requiredFields) {
89
+ const missingFields = requiredFields.filter(field => !config[field]);
90
+ return {
91
+ isValid: missingFields.length === 0,
92
+ missingFields
93
+ };
94
+ }
95
+
96
+ // 验证环境配置
97
+ function validateEnvironment(config, environment) {
98
+ return config.environment && config.environment[environment];
99
+ }
100
+
101
+ /**
102
+ * @description 清空当前目录
103
+ * @param filePath
104
+ * @param callback
105
+ * @constructor
106
+ */
107
+ function DeleteDirAllFile(filePath, callback) {
108
+ let files = [];
109
+ if (fs.existsSync(filePath)) {
110
+ files = fs.readdirSync(filePath);
111
+ files.forEach(function (file, index) {
112
+ let curPath = path.join(filePath, file);
113
+ if (fs.statSync(curPath).isDirectory()) {
114
+ DeleteDirAllFile(curPath);
115
+ } else {
116
+ fs.unlinkSync(curPath);
117
+ }
118
+ });
119
+ fs.rmdirSync(filePath);
120
+ callback && callback();
121
+ } else {
122
+ callback && callback();
123
+ }
124
+ }
125
+
126
+ /**
127
+ * @description 复制单个文件
128
+ * @param srcFile
129
+ * @param tarFile
130
+ * @param cb
131
+ */
132
+ function CopyFile(srcFile, tarFile, cb) {
133
+ // 确保目标目录存在
134
+ const tarDir = path.dirname(tarFile);
135
+ if (!fs.existsSync(tarDir)) {
136
+ fs.mkdirSync(tarDir, { recursive: true });
137
+ }
138
+
139
+ const rs = fs.createReadStream(srcFile);
140
+ const ws = fs.createWriteStream(tarFile);
141
+
142
+ rs.pipe(ws);
143
+
144
+ ws.on('close', function() {
145
+ cb && cb();
146
+ });
147
+
148
+ ws.on('error', function(err) {
149
+ console.error('复制文件出错:', err);
150
+ cb && cb();
151
+ });
152
+ }
153
+
154
+ /**
155
+ * @description 复制文件夹及子目录文件
156
+ * @param srcDir
157
+ * @param tarDir
158
+ * @param cb
159
+ */
160
+ function CopyFolder(srcDir, tarDir, cb) {
161
+ // 确保目标目录存在
162
+ if (!fs.existsSync(tarDir)) {
163
+ fs.mkdirSync(tarDir, { recursive: true });
164
+ }
165
+
166
+ fs.readdir(srcDir, function (err, files) {
167
+
168
+ let count = 0;
169
+ const checkEnd = function () {
170
+ ++count === files.length && cb && cb();
171
+ };
172
+
173
+ if (err) {
174
+ checkEnd();
175
+ return;
176
+ }
177
+
178
+ files.forEach(function (file) {
179
+ const srcPath = path.join(srcDir, file);
180
+ const tarPath = path.join(tarDir, file);
181
+
182
+ fs.stat(srcPath, function (err, stats) {
183
+ if (stats.isDirectory()) {
184
+ fs.mkdir(tarPath, { recursive: true }, function (err) {
185
+ if (err) {
186
+ console.log(err);
187
+ return;
188
+ }
189
+
190
+ CopyFolder(srcPath, tarPath, checkEnd);
191
+ });
192
+ } else {
193
+ // 复制文件
194
+ const rs = fs.createReadStream(srcPath);
195
+ const ws = fs.createWriteStream(tarPath);
196
+ rs.pipe(ws);
197
+ ws.on('close', checkEnd);
198
+ ws.on('error', checkEnd);
199
+ }
200
+ });
201
+ });
202
+ //为空时直接回调
203
+ files.length === 0 && cb && cb();
204
+ });
205
+ }
206
+
207
+
208
+ module.exports = {
209
+ CONSTANTS,
210
+ logInfo,
211
+ logSuccess,
212
+ logWarning,
213
+ logError,
214
+ executeCommand,
215
+ deleteFolderRecursive,
216
+ fileExists,
217
+ readFile,
218
+ writeFile,
219
+ createDir,
220
+ isViteProject,
221
+ validateConfig,
222
+ validateEnvironment,
223
+ DeleteDirAllFile,
224
+ CopyFile,
225
+ CopyFolder
226
+ };