jjb-cmd 2.4.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/src/config.js CHANGED
@@ -1 +1,122 @@
1
- const a2_0x45f77f=a2_0x1a65;(function(_0xb184fb,_0x3913a4){const _0x53b5b8=a2_0x1a65,_0x1e7d4a=_0xb184fb();while(!![]){try{const _0xd8418b=parseInt(_0x53b5b8(0x175))/0x1+parseInt(_0x53b5b8(0x185))/0x2*(-parseInt(_0x53b5b8(0x187))/0x3)+-parseInt(_0x53b5b8(0x169))/0x4*(parseInt(_0x53b5b8(0x17c))/0x5)+parseInt(_0x53b5b8(0x17f))/0x6*(parseInt(_0x53b5b8(0x16f))/0x7)+parseInt(_0x53b5b8(0x168))/0x8*(-parseInt(_0x53b5b8(0x182))/0x9)+parseInt(_0x53b5b8(0x176))/0xa+parseInt(_0x53b5b8(0x165))/0xb;if(_0xd8418b===_0x3913a4)break;else _0x1e7d4a['push'](_0x1e7d4a['shift']());}catch(_0x2a2c63){_0x1e7d4a['push'](_0x1e7d4a['shift']());}}}(a2_0x5920,0x8db69));function a2_0x1a65(_0x59f7ea,_0x401eb6){const _0x5920c5=a2_0x5920();return a2_0x1a65=function(_0x1a658f,_0x2628c5){_0x1a658f=_0x1a658f-0x162;let _0x1ee396=_0x5920c5[_0x1a658f];return _0x1ee396;},a2_0x1a65(_0x59f7ea,_0x401eb6);}const os=require('os'),path=require('path'),fs=require('fs'),API_HOST=a2_0x45f77f(0x16a),API_HOST_HTTPS=a2_0x45f77f(0x17a),API_HOST_TEST=a2_0x45f77f(0x164);function a2_0x5920(){const _0x3c11a5=['d4wQ7dzEjYPsgVbKnYei','ywPtT3xCG6b_vAxp6sTj','http://120.26.210.58:8089','6115582imSswy','API_HOST_TEST','CLOUD_PROJECT','9000368WKYTKz','17364RWgvLx','http://120.26.210.58:8088','dev','GIT_HOST','getApiHost','GIT_TEMP_JAVA','7SaoIRy','e9njpBd1nS_LREN8GFpR','FT3pKzxpRynFkmddJ9Bs','jjb-assembly-','CONFIG_FILE_HOST','7V-YUxhmh51Mdhgx4rq4','748053jCZrIP','3580860TJFBDI','tmpdir','TEMPLATE_FOLDER','parse','https://jcloud.cqjjb.cn','gPSit8aJsLVmNzuQ5Cy4','300IIZJAl','toString','API_HOST','1910202FGvrzN','now','join','9ccOVEE','jjb-assembly-java','GIT_JAVA_ENV_JSON','29010VXGdIo','FqNrmFAgrxasMrbbjvq9','3cTsWDG','readFileSync','../package.json','http'];a2_0x5920=function(){return _0x3c11a5;};return a2_0x5920();}exports[a2_0x45f77f(0x173)]='https://cdn.cqjjb.cn/jjb-cloud-config',exports[a2_0x45f77f(0x17e)]=API_HOST,exports[a2_0x45f77f(0x166)]=API_HOST_TEST,exports[a2_0x45f77f(0x16c)]='http://192.168.1.242:10985',exports['GIT_TEMP_DIR']=a2_0x45f77f(0x172)+Date[a2_0x45f77f(0x180)](),exports[a2_0x45f77f(0x16e)]=a2_0x45f77f(0x183),exports[a2_0x45f77f(0x184)]={'development':a2_0x45f77f(0x16b),'production':'prod','test':'test'},exports[a2_0x45f77f(0x167)]={'common':{'token':'G4HJRsHr9D7Ssmixegw2','projectId':0x117},'react-admin-component':{'token':a2_0x45f77f(0x171),'projectId':0x154},'jjb-dva-runtime':{'token':'hLqARY89CN6fUD3yg4NL','projectId':0x23b},'jjb-common-lib':{'token':a2_0x45f77f(0x170),'projectId':0x23c},'jjb-common-decorator':{'token':a2_0x45f77f(0x17b),'projectId':0x23e},'vue-unisass-component':{'token':a2_0x45f77f(0x162),'projectId':0x153},'react-component':{'token':'snBxJ2i5kYarGGcsojhY','projectId':0x33f},'micro-app-ts':{'token':a2_0x45f77f(0x174),'projectId':0x33e},'micro-app':{'token':a2_0x45f77f(0x186),'projectId':0x33d},'lib':{'token':a2_0x45f77f(0x163),'projectId':0x33c}},exports[a2_0x45f77f(0x178)]=os[a2_0x45f77f(0x177)]()+'\x5c'+exports['GIT_TEMP_DIR'],exports[a2_0x45f77f(0x16d)]=()=>{const _0x4821a6=a2_0x45f77f,_0x390f82=JSON[_0x4821a6(0x179)](fs[_0x4821a6(0x188)](path[_0x4821a6(0x181)](__dirname,_0x4821a6(0x189)))[_0x4821a6(0x17d)]());return _0x390f82['env']==='test'?API_HOST_TEST:_0x390f82['httpMethod']===_0x4821a6(0x18a)?API_HOST: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_0x2d3a(){const _0x1cae2b=['Sudo:\x20yarn\x20build:production','3453399lNGDQq','createInterface','join','pushMessage','match','existsSync','readFileSync','status','defaultSetting','stdin','question','index.js','post','toString','log','chalk','length','readme_content','./config','Error:\x20请在组件入口文件中添加“window[props.componentKey]”以暴露组件的配置信息!','319986Asyaak','dist','4DnazoR','exports','split','stringify','Error:\x20请在组件根目录添加一个README.md说明文件!','catch','Error:\x20授权失败!','path','Please\x20wait,\x20build\x20...,','5271565cuAEXN','15353965WNeLtf','Error:\x20组件发布失败!根目录缺少‘package.json’文件!','Auth:\x20授权成功!','Error:\x20组件发布失败!','blue','base64','Auth:\x20正在获取授权!','Error:\x20暴露的配置信息中缺少“settings”!','then','package.json','thumbnail_base64','exit','14oCDEja','133070XzYTSi','Error:\x20请先登录!','477XEYHRE','6350ZJAAJV','/api/auth','173kJjuYf','child_process','/yarn.lock','../package.json','message','Error:\x20请在组件根目录为组件添加一个缩略图“thumbnail.png”文件!','component_config_content','parse','stdout','yarn\x20build:production','1176296LayoFv','axios','green','from','execSync','Error:\x20暴露的配置信息中缺少“info”!','请输入此次组件发布的信息,按Enter确认:','no\x20message','resolve','red','README.md','Error:\x20组件发布失败!根目录缺少‘dist/index.js’文件!'];a3_0x2d3a=function(){return _0x1cae2b;};return a3_0x2d3a();}const a3_0x502284=a3_0x396c;(function(_0x1b996d,_0x1eb696){const _0x32a1fb=a3_0x396c,_0x376d82=_0x1b996d();while(!![]){try{const _0x43a072=-parseInt(_0x32a1fb(0x1dd))/0x1*(parseInt(_0x32a1fb(0x1db))/0x2)+-parseInt(_0x32a1fb(0x1f4))/0x3*(-parseInt(_0x32a1fb(0x20a))/0x4)+parseInt(_0x32a1fb(0x213))/0x5+-parseInt(_0x32a1fb(0x208))/0x6+parseInt(_0x32a1fb(0x1d7))/0x7*(-parseInt(_0x32a1fb(0x1e7))/0x8)+-parseInt(_0x32a1fb(0x1da))/0x9*(-parseInt(_0x32a1fb(0x1d8))/0xa)+-parseInt(_0x32a1fb(0x214))/0xb;if(_0x43a072===_0x1eb696)break;else _0x376d82['push'](_0x376d82['shift']());}catch(_0xb0117c){_0x376d82['push'](_0x376d82['shift']());}}}(a3_0x2d3a,0x96eee));const path=require(a3_0x502284(0x211)),fs=require('fs'),os=require('os'),axios=require(a3_0x502284(0x1e8)),chalk=require(a3_0x502284(0x203)),readline=require('readline'),io=readline[a3_0x502284(0x1f5)]({'input':process[a3_0x502284(0x1fd)],'output':process[a3_0x502284(0x1e5)]}),child_process=require(a3_0x502284(0x1de)),{getApiHost}=require(a3_0x502284(0x206)),submitFun=function(_0x1c13eb,_0x25924d){const _0x575ef6=a3_0x502284;_0x25924d[_0x575ef6(0x1e1)]=_0x1c13eb||_0x575ef6(0x1ee),axios['post'](getApiHost()+'/api/file/publish',_0x25924d)['then'](_0x1a0c43=>{const _0x4673e5=_0x575ef6;console[_0x4673e5(0x202)](chalk[_0x4673e5(0x1e9)](_0x1a0c43['data'][_0x4673e5(0x1e1)])),process[_0x4673e5(0x1d6)](0x0);})[_0x575ef6(0x20f)](_0x3a4f07=>{const _0x2960ec=_0x575ef6;console['log'](chalk[_0x2960ec(0x1f0)](_0x2960ec(0x217)+_0x3a4f07[_0x2960ec(0x1e1)])),process[_0x2960ec(0x1d6)](0x0);});};function a3_0x396c(_0xbf2ce1,_0x1a697b){const _0x2d3afa=a3_0x2d3a();return a3_0x396c=function(_0x396c41,_0x452481){_0x396c41=_0x396c41-0x1d4;let _0x1ed246=_0x2d3afa[_0x396c41];return _0x1ed246;},a3_0x396c(_0xbf2ce1,_0x1a697b);}module[a3_0x502284(0x20b)]=_0x50ee7d=>{const _0x5c45be=a3_0x502284,_0x1272a5=path[_0x5c45be(0x1f6)](__dirname,'../.auth');!fs[_0x5c45be(0x1f9)](_0x1272a5)&&(console['log'](chalk[_0x5c45be(0x1f0)](_0x5c45be(0x1d9))),process[_0x5c45be(0x1d6)](0x0));const [_0x4948ee,_0x4480f0]=fs[_0x5c45be(0x1fa)](_0x1272a5)[_0x5c45be(0x201)]()[_0x5c45be(0x20c)]('/');console[_0x5c45be(0x202)](_0x5c45be(0x21a)),axios[_0x5c45be(0x200)](getApiHost()+_0x5c45be(0x1dc),{'username':_0x4948ee,'password':_0x4480f0})[_0x5c45be(0x21c)](_0x8d160b=>{const _0x115053=_0x5c45be;if(_0x8d160b['data'][_0x115053(0x1fb)]){console['log'](chalk[_0x115053(0x1e9)](_0x115053(0x216)));const _0x1b9fff=path[_0x115053(0x1ef)]('./');console[_0x115053(0x202)](_0x115053(0x212)+_0x1b9fff);fs[_0x115053(0x1f9)](_0x1b9fff+_0x115053(0x1df))?(console[_0x115053(0x202)](chalk['blue'](_0x115053(0x1f3)),_0x1b9fff),child_process[_0x115053(0x1eb)](_0x115053(0x1e6),{'cwd':_0x1b9fff})):(console[_0x115053(0x202)](chalk[_0x115053(0x218)]('Sudo:\x20npm\x20build:production'),_0x1b9fff),child_process[_0x115053(0x1eb)]('npm\x20run\x20build:production',{'cwd':_0x1b9fff}));const _0x5605df=_0x1b9fff['indexOf']('/')!==-0x1?'/':'\x5c',_0x10ac56=''+_0x1b9fff+_0x5605df+_0x115053(0x1f1),_0x1889ca=''+_0x1b9fff+_0x5605df+_0x115053(0x209)+_0x5605df+_0x115053(0x1ff),_0xffeb3a=''+_0x1b9fff+_0x5605df+_0x115053(0x1d4),_0x2fe279=''+_0x1b9fff+_0x5605df+'thumbnail.png',_0x451d52=JSON[_0x115053(0x1e4)](fs[_0x115053(0x1fa)](path['join'](__dirname,_0x115053(0x1e0)))[_0x115053(0x201)]()),{version:_0x60488a}=_0x451d52,_0x4ee843={'username':_0x4948ee,'cmd_version':_0x60488a,'hostname':os['hostname'](),'platform':os['platform']()};if(fs['existsSync'](_0xffeb3a)){if(fs[_0x115053(0x1f9)](_0x1889ca)){_0x4ee843['package_version']=_0x50ee7d?_0x50ee7d:0x0,_0x4ee843['package_content']=fs[_0x115053(0x1fa)](_0x1889ca)[_0x115053(0x201)](),_0x4ee843[_0x115053(0x1e3)]={};const _0x1eb25d=fs['readFileSync'](_0x1889ca)[_0x115053(0x201)](),_0x343380=_0x1eb25d[_0x115053(0x1f8)](/(window\[).+?(\.componentKey|.+]={)/img);if(_0x343380&&_0x343380[_0x115053(0x204)]){const _0x16cc4e=_0x1eb25d[_0x115053(0x1f8)](/componentKey.+([{,]info:\s{0,}{)/img);if(_0x16cc4e&&_0x16cc4e['length']){let _0x49186b='{';const _0x3215a1=_0x1eb25d[_0x115053(0x20c)](_0x16cc4e[0x0])[0x1];for(let _0x47cd1b=0x0;_0x47cd1b<_0x3215a1[_0x115053(0x204)];_0x47cd1b++){_0x49186b+=_0x3215a1[_0x47cd1b];if(_0x3215a1[_0x47cd1b]==='}')try{const _0x13f5a3=new Function('return\x20'+_0x49186b)();_0x4ee843[_0x115053(0x1e3)]={..._0x13f5a3,'defaultSetting':{}};}catch(_0x3e8b1e){}}}else console[_0x115053(0x202)](chalk['red'](_0x115053(0x1ec))),process['exit'](0x0);const _0x412efa=_0x1eb25d[_0x115053(0x1f8)](/componentKey.+([{,]settings:\s{0,}{)/img);if(_0x412efa&&_0x412efa['length']){let _0x361c70='{';const _0x34faea=_0x1eb25d['split'](_0x412efa[0x0])[0x1];for(let _0x1d6ace=0x0;_0x1d6ace<_0x34faea[_0x115053(0x204)];_0x1d6ace++){_0x361c70+=_0x34faea[_0x1d6ace];if(_0x34faea[_0x1d6ace]==='}')try{_0x4ee843[_0x115053(0x1e3)][_0x115053(0x1fc)]=new Function('return\x20'+_0x361c70)();}catch(_0x4671a9){}}_0x4ee843[_0x115053(0x1e3)]=JSON[_0x115053(0x20d)](_0x4ee843[_0x115053(0x1e3)]);}else console[_0x115053(0x202)](chalk[_0x115053(0x1f0)](_0x115053(0x21b))),process['exit'](0x0);}else console[_0x115053(0x202)](chalk['red'](_0x115053(0x207))),process[_0x115053(0x1d6)](0x0);fs[_0x115053(0x1f9)](_0x10ac56)?_0x4ee843[_0x115053(0x205)]=fs['readFileSync'](_0x10ac56)[_0x115053(0x201)]():(console['log'](chalk[_0x115053(0x1f0)](_0x115053(0x20e))),process['exit'](0x0));if(!fs[_0x115053(0x1f9)](_0x2fe279))console[_0x115053(0x202)](_0x115053(0x1e2)),process[_0x115053(0x1d6)](0x0);else{const _0x1485b4=fs[_0x115053(0x1fa)](_0x2fe279);_0x4ee843[_0x115053(0x1d5)]=Buffer[_0x115053(0x1ea)](_0x1485b4)[_0x115053(0x201)](_0x115053(0x219));}_0x451d52[_0x115053(0x1f7)]==='no'?submitFun(null,_0x4ee843):io[_0x115053(0x1fe)](_0x115053(0x1ed),function(_0x83f582){submitFun(_0x83f582,_0x4ee843);});}else console[_0x115053(0x202)](chalk[_0x115053(0x1f0)](_0x115053(0x1f2))),process[_0x115053(0x1d6)](0x0);}else console[_0x115053(0x202)](chalk[_0x115053(0x1f0)](_0x115053(0x215))),process[_0x115053(0x1d6)](0x0);}else console[_0x115053(0x202)](chalk[_0x115053(0x1f0)](_0x115053(0x210))),process[_0x115053(0x1d6)](0x0);})[_0x5c45be(0x20f)](_0x264920=>{const _0x525e0f=_0x5c45be;console[_0x525e0f(0x202)](chalk[_0x525e0f(0x1f0)]('Error:\x20授权失败,未知错误!'),_0x264920[_0x525e0f(0x1e1)]),process[_0x525e0f(0x1d6)](0x0);});};
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_0x15f4b1=a4_0x494d;(function(_0x2bf845,_0x4667ef){const _0x58a47a=a4_0x494d,_0x4321bb=_0x2bf845();while(!![]){try{const _0x1618e1=-parseInt(_0x58a47a(0xbe))/0x1+-parseInt(_0x58a47a(0xe2))/0x2+parseInt(_0x58a47a(0xa9))/0x3*(-parseInt(_0x58a47a(0xea))/0x4)+-parseInt(_0x58a47a(0xbb))/0x5*(-parseInt(_0x58a47a(0xa0))/0x6)+parseInt(_0x58a47a(0xe7))/0x7+parseInt(_0x58a47a(0xab))/0x8+-parseInt(_0x58a47a(0xaa))/0x9*(-parseInt(_0x58a47a(0xa3))/0xa);if(_0x1618e1===_0x4667ef)break;else _0x4321bb['push'](_0x4321bb['shift']());}catch(_0x315302){_0x4321bb['push'](_0x4321bb['shift']());}}}(a4_0x5698,0x48944));const fs=require('fs'),os=require('os'),path=require(a4_0x15f4b1(0xd4)),child_process=require('child_process'),chalk=require('chalk'),{CopyFolder,DeleteDirAllFile}=require(a4_0x15f4b1(0xd5)),{GIT_TEMP_JAVA,getApiHost}=require(a4_0x15f4b1(0xb5)),axios=require(a4_0x15f4b1(0xcb));function deleteFolderRecursive(_0x2e39a9){const _0x490cf5=a4_0x15f4b1;fs[_0x490cf5(0xc7)](_0x2e39a9)&&(fs[_0x490cf5(0xa2)](_0x2e39a9)[_0x490cf5(0xe3)](_0x5463b=>{const _0x291fd6=_0x490cf5,_0x189080=path[_0x291fd6(0xb2)](_0x2e39a9,_0x5463b);fs[_0x291fd6(0xd2)](_0x189080)[_0x291fd6(0xd8)]()?deleteFolderRecursive(_0x189080):fs[_0x291fd6(0xad)](_0x189080);}),fs['rmdirSync'](_0x2e39a9));}module['exports']=arguments=>{const _0x7543e5=a4_0x15f4b1,_0xc325bc=path['join'](__dirname,_0x7543e5(0xa4));!fs[_0x7543e5(0xc7)](_0xc325bc)&&(console[_0x7543e5(0xba)](chalk[_0x7543e5(0xac)]('Error:\x20请先登录!')),process[_0x7543e5(0xc9)](0x0));const _0x5f4b38=arguments[0x1],_0x195adc=arguments[0x2]||_0x7543e5(0xb8),_0x44e1d1=arguments[0x3]?arguments[0x3][_0x7543e5(0xd3)]('-'):[],_0x35c61c=path[_0x7543e5(0xa1)]('./'),_0x11c1f5=_0x35c61c+'\x5cjjb.config.js',_0x13494b=_0x35c61c+_0x7543e5(0xd6),_0x3ad3bb=os[_0x7543e5(0xbf)](),[_0x4eb56d,_0x22ea11]=fs[_0x7543e5(0xaf)](_0xc325bc)[_0x7543e5(0xbc)]()[_0x7543e5(0xd3)]('/');console['log']('Auth:\x20正在获取授权!'),axios[_0x7543e5(0xb3)](getApiHost()+'/api/auth',{'username':_0x4eb56d,'password':_0x22ea11})[_0x7543e5(0xca)](_0x426084=>{const _0x12bd51=_0x7543e5;if(_0x426084['data'][_0x12bd51(0xd7)]){console[_0x12bd51(0xba)](chalk[_0x12bd51(0x9e)](_0x12bd51(0xbd)));if(!fs[_0x12bd51(0xc7)](_0x11c1f5))console['log'](chalk[_0x12bd51(0xac)]('Error:\x20当前应用中不存在“jjb.config.json”文件!')),process[_0x12bd51(0xc9)](0x0);else{const _0x4ea32b=require(_0x11c1f5);!_0x4ea32b['javaGit']&&(console['log'](chalk['red'](_0x12bd51(0xb4))),process[_0x12bd51(0xc9)](0x0));!_0x4ea32b[_0x12bd51(0xd9)]&&(console[_0x12bd51(0xba)](chalk[_0x12bd51(0xac)]('Error:\x20“jjb.config.json”中缺少“javaGitName”字段!')),process['exit'](0x0));const _0x59ecd6=_0x3ad3bb+'/'+GIT_TEMP_JAVA;fs[_0x12bd51(0xc7)](_0x59ecd6)&&deleteFolderRecursive(_0x59ecd6);fs[_0x12bd51(0xb6)](_0x59ecd6);const _0x10d604=_0x59ecd6+'/'+_0x4ea32b['javaGitName'];fs[_0x12bd51(0xc7)](_0x10d604)?_0x44e1d1[_0x12bd51(0xc0)]('force')?DeleteDirAllFile(_0x10d604,()=>{const _0x519981=_0x12bd51;console['log'](chalk[_0x519981(0xb9)](_0x519981(0xc1)+_0x4ea32b[_0x519981(0xa6)]),_0x59ecd6),child_process[_0x519981(0xe6)]('git\x20clone\x20'+_0x4ea32b['javaGit'],{'cwd':_0x59ecd6});}):(console[_0x12bd51(0xba)](chalk[_0x12bd51(0xb9)]('Sudo:\x20git\x20clone\x20'+_0x4ea32b['javaGit']),_0x59ecd6),child_process[_0x12bd51(0xe6)](_0x12bd51(0xb1)+_0x4ea32b['javaGit'],{'cwd':_0x59ecd6})):(console[_0x12bd51(0xba)](chalk[_0x12bd51(0xb9)](_0x12bd51(0xc1)+_0x4ea32b[_0x12bd51(0xa6)]),_0x59ecd6),child_process['execSync']('git\x20clone\x20'+_0x4ea32b['javaGit'],{'cwd':_0x59ecd6})),_0x4d8e52(_0x59ecd6,_0x4ea32b);}}else console[_0x12bd51(0xba)](chalk[_0x12bd51(0xac)](_0x12bd51(0xdd))),process[_0x12bd51(0xc9)](0x0);})['catch'](_0xde5e95=>{const _0x282ca9=_0x7543e5;console[_0x282ca9(0xba)](chalk[_0x282ca9(0xac)]('Error:\x20授权失败,未知错误!'),_0xde5e95[_0x282ca9(0xe5)]),process[_0x282ca9(0xc9)](0x0);});arguments[_0x7543e5(0xe1)]<0x2&&(console['log'](chalk['red'](_0x7543e5(0xc6))),process[_0x7543e5(0xc9)](0x0));function _0x4d8e52(_0x321200,_0x48fb2e){const _0x1449e8=_0x7543e5,_0x187d37=_0x48fb2e[_0x1449e8(0xe8)][_0x5f4b38],_0x4e999c=_0x321200+'/'+_0x48fb2e[_0x1449e8(0xd9)];!_0x187d37[_0x1449e8(0xa5)]&&console[_0x1449e8(0xba)](chalk[_0x1449e8(0xdc)](_0x1449e8(0xc4)+_0x5f4b38+_0x1449e8(0xda)));console['log'](chalk[_0x1449e8(0xb9)](_0x1449e8(0xec)),_0x4e999c),child_process[_0x1449e8(0xe6)](_0x1449e8(0xed),{'cwd':_0x4e999c});!fs[_0x1449e8(0xc7)](_0x35c61c+_0x1449e8(0xcc))&&(console['log'](chalk[_0x1449e8(0xdc)](_0x1449e8(0xe9))),console[_0x1449e8(0xba)](chalk[_0x1449e8(0xb9)]('Sudo:\x20yarn'),_0x35c61c),child_process[_0x1449e8(0xe6)](_0x1449e8(0xa8),{'cwd':_0x35c61c}),console['log'](chalk[_0x1449e8(0x9e)](_0x1449e8(0xd0))));console['log'](_0x1449e8(0xce)+_0x5f4b38+']\x20请稍等!'),console['log'](chalk[_0x1449e8(0xb9)](_0x1449e8(0xae)+_0x5f4b38),_0x35c61c),child_process[_0x1449e8(0xe6)](_0x1449e8(0xdf)+_0x5f4b38,{'cwd':_0x35c61c,'maxBuffer':0x3b9aca00}),console['log'](chalk[_0x1449e8(0x9e)](_0x1449e8(0xc2)));if(fs[_0x1449e8(0xc7)](_0x13494b)){const _0xe3f687=_0x48fb2e[_0x1449e8(0xcd)],_0x783259=fs[_0x1449e8(0xaf)](_0x13494b+_0x1449e8(0xd1));_0x44e1d1[_0x1449e8(0xc0)](_0x1449e8(0xcf))?fs[_0x1449e8(0xe0)](_0x13494b+'/index.html',_0x783259,'utf-8'):fs[_0x1449e8(0xe0)](_0x13494b+'/'+_0xe3f687+_0x1449e8(0xc3),_0x783259,_0x1449e8(0x9f));const _0x113759=_0x4e999c+'/start/src/main/resources/templates';!fs[_0x1449e8(0xc7)](_0x113759)&&fs['mkdirSync'](_0x113759);const _0x266e38=_0x187d37[_0x1449e8(0xa5)]?_0x187d37[_0x1449e8(0xa5)]:_0x1449e8(0xa7);console[_0x1449e8(0xba)](chalk[_0x1449e8(0xb9)]('Sudo:\x20git\x20checkout\x20'+_0x266e38),_0x4e999c),child_process['execSync']('git\x20checkout\x20'+_0x266e38,{'cwd':_0x4e999c});const _0xde9bb7=_0x113759+'/'+_0x48fb2e[_0x1449e8(0xcd)];DeleteDirAllFile(_0xde9bb7,()=>{const _0x1d4ae7=_0x1449e8;fs[_0x1d4ae7(0xb6)](_0xde9bb7),fs[_0x1d4ae7(0xe0)](_0xde9bb7+_0x1d4ae7(0xc3),_0x783259,_0x1d4ae7(0x9f)),CopyFolder(_0x13494b+'\x5c'+_0x48fb2e[_0x1d4ae7(0xcd)],_0xde9bb7,()=>{setTimeout(()=>{const _0x38d350=a4_0x494d;console[_0x38d350(0xba)](chalk[_0x38d350(0xb9)]('Sudo:\x20git\x20pull'),_0x4e999c),child_process[_0x38d350(0xe6)]('git\x20pull',{'cwd':_0x4e999c}),console['log'](chalk['blue'](_0x38d350(0xe4)),_0x4e999c),child_process[_0x38d350(0xe6)](_0x38d350(0xc8),{'cwd':_0x4e999c});try{console['log'](chalk[_0x38d350(0xb9)](_0x38d350(0xc5)+_0x195adc+'\x20--no-verify'),_0x4e999c),child_process[_0x38d350(0xe6)](_0x38d350(0xb0)+_0x195adc+_0x38d350(0xeb),{'cwd':_0x4e999c});}catch(_0x396ad7){console[_0x38d350(0xba)](chalk[_0x38d350(0xac)]('Error:\x20'+_0x396ad7[_0x38d350(0xe5)]));}console[_0x38d350(0xba)](chalk[_0x38d350(0xb9)](_0x38d350(0xde)),_0x4e999c),child_process['execSync'](_0x38d350(0xdb),{'cwd':_0x4e999c});},0x3e8);});});}else console['log'](chalk[_0x1449e8(0xac)](_0x1449e8(0xb7))),process[_0x1449e8(0xc9)](0x0);}};function a4_0x494d(_0xb95393,_0x3d1363){const _0x5698d6=a4_0x5698();return a4_0x494d=function(_0x494db6,_0xe95d04){_0x494db6=_0x494db6-0x9e;let _0x468682=_0x5698d6[_0x494db6];return _0x468682;},a4_0x494d(_0xb95393,_0x3d1363);}function a4_0x5698(){const _0x561abc=['exit','then','axios','/node_modules','appIdentifier','Log:\x20即将进行应用打包\x20[Env#','index','Log:\x20应用依赖安装完成!','/index.html','lstatSync','split','path','./tools','\x5cdist','status','isDirectory','javaGitName',']\x20未配置“javaGitBranch”,将使用默认分支“master”!','git\x20push','yellow','Error:\x20授权失败!','Sudo:\x20git\x20push','yarn\x20build:','writeFileSync','length','303364VKQzTu','forEach','Sudo:\x20git\x20add\x20.','message','execSync','3732561FhfaTD','environment','Warning:\x20当前应用未安装依赖!即将执行依赖安装命令,请稍等!','162924lYiBwm','\x20--no-verify','Sudo:\x20git\x20pull','git\x20pull','green','utf-8','6JbgSkQ','resolve','readdirSync','200YIbjYE','../.auth','javaGitBranch','javaGit','master','yarn','21yVlQGl','61524GaeRuo','1834000kXRqEZ','red','unlinkSync','Sudo:\x20yarn\x20build:','readFileSync','git\x20commit\x20-m\x20','git\x20clone\x20','join','post','Error:\x20“jjb.config.json”中缺少“javaGit”字段!','./config','mkdirSync','Error:\x20未知错误,未找到“dist”目录!','\x22no\x20message\x22','blue','log','1675645MKrGcX','toString','Auth:\x20授权成功!','500239aVbqVg','tmpdir','includes','Sudo:\x20git\x20clone\x20','Log:\x20应用打包完成!','.html','Warning:\x20当前打包\x20[Env#','Sudo:\x20git\x20commit\x20-m\x20','Error:\x20命令参数传递错误!','existsSync','git\x20add\x20.'];a4_0x5698=function(){return _0x561abc;};return a4_0x5698();}
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
+ };