crabatool 1.0.820 → 1.0.828
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/index.js +4 -3
- package/lib/utils.js +26 -3
- package/package.json +1 -1
- package/tool/upgrade.js +29 -33
package/index.js
CHANGED
|
@@ -4,6 +4,7 @@ var autoUpdate = require('./tool/autoUpdate.js');
|
|
|
4
4
|
var processManager = require('./tool/processManager.js');
|
|
5
5
|
var path = require('path');
|
|
6
6
|
var utils = require('./lib/utils.js');
|
|
7
|
+
const upgrade = require('./tool/upgrade.js');
|
|
7
8
|
|
|
8
9
|
exports = module.exports;
|
|
9
10
|
exports.config = config;
|
|
@@ -161,7 +162,7 @@ async function checkFast(args) {
|
|
|
161
162
|
if (args.includes('-update')) {
|
|
162
163
|
start.bindAndCheckConfig('-webPath');
|
|
163
164
|
start.checkCraba();
|
|
164
|
-
|
|
165
|
+
upgrade.updateCraba();
|
|
165
166
|
return false;
|
|
166
167
|
}
|
|
167
168
|
|
|
@@ -179,12 +180,12 @@ async function checkFast(args) {
|
|
|
179
180
|
start.bindAndCheckConfig('-webPath');
|
|
180
181
|
start.checkCraba();
|
|
181
182
|
console.log('分支名:', config.branchName, config.webPath);
|
|
182
|
-
|
|
183
|
+
upgrade.checkUpdateCraba();
|
|
183
184
|
return false;
|
|
184
185
|
}
|
|
185
186
|
|
|
186
187
|
if (args.includes('-v')) {
|
|
187
|
-
var data =
|
|
188
|
+
var data = upgrade.getNewVersion();
|
|
188
189
|
console.log(data);
|
|
189
190
|
return false;
|
|
190
191
|
}
|
package/lib/utils.js
CHANGED
|
@@ -9,8 +9,10 @@ var compressing = require('compressing');
|
|
|
9
9
|
var axios = require('axios');
|
|
10
10
|
var os = require('os');
|
|
11
11
|
const { execSync } = require('child_process');
|
|
12
|
+
/*
|
|
12
13
|
const util = require('util');
|
|
13
14
|
const execPromise = util.promisify(execSync);
|
|
15
|
+
*/
|
|
14
16
|
|
|
15
17
|
if (!String.prototype.replaceAll) {
|
|
16
18
|
String.prototype.replaceAll = function(search, replacement) {
|
|
@@ -1236,13 +1238,33 @@ class Utils {
|
|
|
1236
1238
|
/**
|
|
1237
1239
|
* 在指定目录执行命令
|
|
1238
1240
|
*/
|
|
1239
|
-
|
|
1241
|
+
executeCommand(command) {
|
|
1240
1242
|
console.log(`执行: ${command}`);
|
|
1241
1243
|
|
|
1244
|
+
var webPath = config.webPath || config.targetPath || config.skinPath;
|
|
1245
|
+
console.log('执行命令路径:' + webPath);
|
|
1246
|
+
|
|
1247
|
+
try {
|
|
1248
|
+
var msg = execSync(command, { cwd: webPath });
|
|
1249
|
+
console.log(msg);
|
|
1250
|
+
return {
|
|
1251
|
+
success: true,
|
|
1252
|
+
msg: String(msg).trim()
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
catch (ex) {
|
|
1256
|
+
console.log(ex);
|
|
1257
|
+
return {
|
|
1258
|
+
success: false,
|
|
1259
|
+
msg: String(ex.message).trim()
|
|
1260
|
+
};
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
/*
|
|
1242
1264
|
try {
|
|
1243
1265
|
const { stdout, stderr } = await execPromise(command, {
|
|
1244
|
-
cwd:
|
|
1245
|
-
|
|
1266
|
+
cwd: webPath,
|
|
1267
|
+
300000,
|
|
1246
1268
|
maxBuffer: 10 * 1024 * 1024,
|
|
1247
1269
|
encoding: 'utf-8'
|
|
1248
1270
|
});
|
|
@@ -1256,6 +1278,7 @@ class Utils {
|
|
|
1256
1278
|
error: error.message
|
|
1257
1279
|
};
|
|
1258
1280
|
}
|
|
1281
|
+
*/
|
|
1259
1282
|
}
|
|
1260
1283
|
}
|
|
1261
1284
|
var utils = new Utils();
|
package/package.json
CHANGED
package/tool/upgrade.js
CHANGED
|
@@ -58,48 +58,35 @@ class Upgrade {
|
|
|
58
58
|
return { version: version, date: vDate };
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
var result = await this.checkGitPermission();
|
|
63
|
-
if (!result) {
|
|
64
|
-
console.log('没有git推送权限,取消craba的更新操作');
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
console.log('当前git有推送权限,开始检查更新craba');
|
|
69
|
-
|
|
70
|
-
this.checkUpdateCrabaNext();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async checkGitPermission() {
|
|
61
|
+
checkGitPermission() {
|
|
74
62
|
//git commit --allow-empty -m "测试空提交"
|
|
75
63
|
console.log('检查当前git是否有推送权限');
|
|
76
64
|
|
|
65
|
+
var branchName = config.branchName || config.version;
|
|
66
|
+
branchName = branchName.replace('origin/', '');
|
|
67
|
+
|
|
68
|
+
utils.executeCommand(`git fetch origin && git merge origin/${branchName} --no-edit`);
|
|
69
|
+
|
|
77
70
|
console.log('🚀 创建空白提交...');
|
|
78
|
-
const commitResult =
|
|
71
|
+
const commitResult = utils.executeCommand(
|
|
79
72
|
'git commit --allow-empty -m "[检测推送权限测试提交] 空白提交,无需关注" --no-verify'
|
|
80
73
|
);
|
|
81
|
-
|
|
82
74
|
if (!commitResult.success) {
|
|
83
|
-
console.log(`创建测试提交失败: ${commitResult.
|
|
75
|
+
console.log(`创建测试提交失败: ${commitResult.msg}`);
|
|
84
76
|
return false;
|
|
85
77
|
}
|
|
86
78
|
|
|
87
|
-
var branchName = config.branchName || config.version;
|
|
88
|
-
branchName = branchName.replace('origin/', '');
|
|
89
79
|
|
|
90
|
-
var gitCmd = `git push origin ${branchName}`;
|
|
80
|
+
var gitCmd = `git push origin ${branchName} --force`;
|
|
91
81
|
console.log('🚀 执行推送测试是否有权限...');
|
|
92
|
-
const pushResult =
|
|
93
|
-
gitCmd,
|
|
94
|
-
60000 // 推送可能需要更长时间
|
|
95
|
-
);
|
|
82
|
+
const pushResult = utils.executeCommand(gitCmd);
|
|
96
83
|
|
|
97
84
|
if (!pushResult.success) {
|
|
98
|
-
console.log(`没有推送权限: ${pushResult.
|
|
85
|
+
console.log(`没有推送权限: ${pushResult.msg}`);
|
|
99
86
|
return false;
|
|
100
87
|
}
|
|
101
88
|
|
|
102
|
-
if (this.classifyError(pushResult.
|
|
89
|
+
if (this.classifyError(pushResult.msg)) {
|
|
103
90
|
return false;
|
|
104
91
|
}
|
|
105
92
|
|
|
@@ -109,9 +96,9 @@ class Upgrade {
|
|
|
109
96
|
/**
|
|
110
97
|
* 错误分类
|
|
111
98
|
*/
|
|
112
|
-
classifyError(
|
|
113
|
-
if (!
|
|
114
|
-
const err =
|
|
99
|
+
classifyError(msg) {
|
|
100
|
+
if (!msg) return false;
|
|
101
|
+
const err = msg.toLowerCase();
|
|
115
102
|
if (err.includes('permission denied') || err.includes('not allowed')) {
|
|
116
103
|
return 'PERMISSION_DENIED';
|
|
117
104
|
}
|
|
@@ -127,10 +114,10 @@ class Upgrade {
|
|
|
127
114
|
if (err.includes('cannot lock ref') || err.includes('would be overwritten')) {
|
|
128
115
|
return 'CONFLICT_ERROR';
|
|
129
116
|
}
|
|
130
|
-
if (
|
|
117
|
+
if (err.includes('fatal:')) {
|
|
131
118
|
return 'GIT_FATAL_ERROR';
|
|
132
119
|
}
|
|
133
|
-
if (err.includes('timeout')
|
|
120
|
+
if (err.includes('timeout')) {
|
|
134
121
|
return 'TIMEOUT_ERROR';
|
|
135
122
|
}
|
|
136
123
|
|
|
@@ -138,7 +125,7 @@ class Upgrade {
|
|
|
138
125
|
}
|
|
139
126
|
|
|
140
127
|
|
|
141
|
-
|
|
128
|
+
checkUpdateCraba() {
|
|
142
129
|
var host = config.SourceHost;
|
|
143
130
|
var version = config.version; // 默认临时目录下
|
|
144
131
|
var host = config.host || config.SourceHost;
|
|
@@ -168,7 +155,7 @@ class Upgrade {
|
|
|
168
155
|
if (data.success && data.remark && data.remark.length > 0) {
|
|
169
156
|
//console.log(data.remark);
|
|
170
157
|
that.gitLogs = data.remark; // 先记录日志列表
|
|
171
|
-
that.updateCraba(); // 需要更新平台
|
|
158
|
+
that.updateCraba(null, true); // 需要更新平台
|
|
172
159
|
} else {
|
|
173
160
|
console.log('没有检测到更新标记,无需更新平台资源');
|
|
174
161
|
}
|
|
@@ -206,9 +193,18 @@ class Upgrade {
|
|
|
206
193
|
});
|
|
207
194
|
}
|
|
208
195
|
|
|
209
|
-
updateCraba(cb) {
|
|
196
|
+
updateCraba(cb, check) {
|
|
210
197
|
utils.cleardirsSync(config.SaveFilePath);
|
|
211
198
|
|
|
199
|
+
if (check) {
|
|
200
|
+
var result = this.checkGitPermission();
|
|
201
|
+
if (!result) {
|
|
202
|
+
console.log('-------------当前git没有推送权限,取消craba的更新操作----------');
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
console.log('当前git有推送权限,开始下载并更新craba');
|
|
206
|
+
}
|
|
207
|
+
|
|
212
208
|
this.cb = cb;
|
|
213
209
|
this.projectPath = config.webPath;
|
|
214
210
|
|