crabatool 1.0.819 → 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 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
- require('./tool/upgrade.js').updateCraba();
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
- require('./tool/upgrade.js').checkUpdateCraba();
183
+ upgrade.checkUpdateCraba();
183
184
  return false;
184
185
  }
185
186
 
186
187
  if (args.includes('-v')) {
187
- var data = require('./tool/upgrade.js').getNewVersion();
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
- async executeCommand(command, repoPath = config.webPath, timeout = 30000) {
1240
- this._log(`执行: ${command}`);
1241
+ executeCommand(command) {
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: repoPath,
1245
- timeout,
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crabatool",
3
- "version": "1.0.819",
3
+ "version": "1.0.828",
4
4
  "description": "crabatool",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -93,13 +93,19 @@ function buildFolder(options) {
93
93
  if (config.exp) {
94
94
  var list = config.exp.split(';');
95
95
  list.forEach(function(item) {
96
+ if (!item) return;
96
97
  var arr = item.split('=');
97
- var key = arr[0].trim();
98
+ var key = (arr[0] || '').trim();
99
+ if (!key) return;
100
+
98
101
  var value;
99
102
  if (key == '$versionDate$') {
100
103
  value = new Date().toString('yyyyMMddhh');
101
- } else {
104
+ } else if (arr.length > 1 && arr[1] != null) {
102
105
  value = arr[1].trim();
106
+ } else {
107
+ utils.log('exp变量格式不正确,已忽略:' + item);
108
+ return;
103
109
  }
104
110
  content = content.replaceAll(key, value);
105
111
 
@@ -280,4 +286,4 @@ function copyByteToCache(filePath, content, stats, options) {
280
286
  utils.debug("拷贝到缓存:" + cachePath);
281
287
  fs.writeFileSync(cachePath, content, 'utf8');
282
288
  fs.utimesSync(cachePath, stats.atime, stats.mtime); // 必须同步文件时间
283
- }
289
+ }
package/tool/upgrade.js CHANGED
@@ -58,50 +58,35 @@ class Upgrade {
58
58
  return { version: version, date: vDate };
59
59
  }
60
60
 
61
- async checkUpdateCraba() {
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 = await utils.executeCommand(
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.stderr}`);
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
- console.log(gitCmd);
93
-
94
- const pushResult = await utils.executeCommand(
95
- gitCmd,
96
- 60000 // 推送可能需要更长时间
97
- );
82
+ const pushResult = utils.executeCommand(gitCmd);
98
83
 
99
84
  if (!pushResult.success) {
100
- console.log(`没有推送权限: ${pushResult.stderr}`);
85
+ console.log(`没有推送权限: ${pushResult.msg}`);
101
86
  return false;
102
87
  }
103
88
 
104
- if (this.classifyError(pushResult.stderr || pushResult.message, pushResult.code)) {
89
+ if (this.classifyError(pushResult.msg)) {
105
90
  return false;
106
91
  }
107
92
 
@@ -111,9 +96,9 @@ class Upgrade {
111
96
  /**
112
97
  * 错误分类
113
98
  */
114
- classifyError(stderr, code) {
115
- if (!stderr) return false;
116
- const err = stderr.toLowerCase();
99
+ classifyError(msg) {
100
+ if (!msg) return false;
101
+ const err = msg.toLowerCase();
117
102
  if (err.includes('permission denied') || err.includes('not allowed')) {
118
103
  return 'PERMISSION_DENIED';
119
104
  }
@@ -129,10 +114,10 @@ class Upgrade {
129
114
  if (err.includes('cannot lock ref') || err.includes('would be overwritten')) {
130
115
  return 'CONFLICT_ERROR';
131
116
  }
132
- if (code === 128 || err.includes('fatal:')) {
117
+ if (err.includes('fatal:')) {
133
118
  return 'GIT_FATAL_ERROR';
134
119
  }
135
- if (err.includes('timeout') || code === 124) {
120
+ if (err.includes('timeout')) {
136
121
  return 'TIMEOUT_ERROR';
137
122
  }
138
123
 
@@ -140,7 +125,7 @@ class Upgrade {
140
125
  }
141
126
 
142
127
 
143
- checkUpdateCrabaNext() {
128
+ checkUpdateCraba() {
144
129
  var host = config.SourceHost;
145
130
  var version = config.version; // 默认临时目录下
146
131
  var host = config.host || config.SourceHost;
@@ -170,7 +155,7 @@ class Upgrade {
170
155
  if (data.success && data.remark && data.remark.length > 0) {
171
156
  //console.log(data.remark);
172
157
  that.gitLogs = data.remark; // 先记录日志列表
173
- that.updateCraba(); // 需要更新平台
158
+ that.updateCraba(null, true); // 需要更新平台
174
159
  } else {
175
160
  console.log('没有检测到更新标记,无需更新平台资源');
176
161
  }
@@ -208,9 +193,18 @@ class Upgrade {
208
193
  });
209
194
  }
210
195
 
211
- updateCraba(cb) {
196
+ updateCraba(cb, check) {
212
197
  utils.cleardirsSync(config.SaveFilePath);
213
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
+
214
208
  this.cb = cb;
215
209
  this.projectPath = config.webPath;
216
210