crabatool 1.0.518 → 1.0.703

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
@@ -182,7 +182,11 @@ async function checkFast(args) {
182
182
  if (success) {
183
183
  console.log('更新完成!');
184
184
  } else {
185
- console.log(`更新失败,请检查网络连接或手动执行:npm install crabatool --registry ${config.registry}`);
185
+ const utils = require('./lib/utils.js');
186
+ const installCmd = utils.isRunningGlobally()
187
+ ? `npm install -g crabatool --registry ${config.registry}`
188
+ : `npm install crabatool --registry ${config.registry}`;
189
+ console.log(`更新失败,请检查网络连接或手动执行:${installCmd}`);
186
190
  }
187
191
  process.exit(success ? 0 : 1);
188
192
  return false;
@@ -216,10 +220,14 @@ async function checkFast(args) {
216
220
 
217
221
  // crabatool -upload -host 接收地址 -webPath 平台源码根路径
218
222
  if (args.includes('-upload')) {
223
+ console.log('开始打包craba')
219
224
  start.bindAndCheckConfig('-targetPath');
220
225
  if (!require('./tool/compress.js').run()) {
226
+ console.log('打包异常,终止上传');
221
227
  return false;
222
228
  } // 打包压缩js和css
229
+
230
+ console.log('开始上传craba')
223
231
  require('./tool/crabapublish.js').upload();
224
232
  return false;
225
233
  }
package/lib/utils.js CHANGED
@@ -8,6 +8,7 @@ var logErr = console.dir.bind(console);
8
8
  var compressing = require('compressing');
9
9
  var axios = require('axios');
10
10
  var os = require('os');
11
+ const { execSync } = require('child_process');
11
12
 
12
13
  if (!String.prototype.replaceAll) {
13
14
  String.prototype.replaceAll = function(search, replacement) {
@@ -60,6 +61,25 @@ class Utils {
60
61
  this.cryptoKey = '$wssf20119@.Z+Q$';
61
62
  }
62
63
 
64
+ isRunningGlobally() {
65
+ try {
66
+ const currentScriptPath = path.resolve(process.argv[1]);
67
+ const globalNodeModules = execSync('npm root -g', { encoding: 'utf8' }).trim();
68
+ const normalizedGlobal = path.resolve(globalNodeModules);
69
+
70
+ return currentScriptPath.startsWith(normalizedGlobal);
71
+ } catch (e) {
72
+ // 备用方案:检查是否在PATH中
73
+ try {
74
+ const scriptDir = path.dirname(process.argv[1]);
75
+ const pathDirs = process.env.PATH.split(path.delimiter);
76
+ return pathDirs.some(dir => path.resolve(dir) === path.resolve(scriptDir));
77
+ } catch {
78
+ return false;
79
+ }
80
+ }
81
+ }
82
+
63
83
  removePathPrefix(fullPath, prefix) {
64
84
  // 规范化路径(统一分隔符为当前系统的分隔符)
65
85
  const normalizedFullPath = path.normalize(fullPath);
@@ -850,7 +870,6 @@ class Utils {
850
870
  // 获取当前 npm 版本(若未安装或异常则返回空字符串)
851
871
  getNpmVersion(cwd) {
852
872
  try {
853
- const execSync = require('child_process').execSync;
854
873
  const out = execSync('npm -v', { cwd: cwd || process.cwd() });
855
874
  return String(out).trim();
856
875
  } catch (e) {
@@ -860,7 +879,6 @@ class Utils {
860
879
 
861
880
  // 获取 Git 用户信息(优先读取项目目录下的本地配置)
862
881
  getGitUser(cwd) {
863
- const execSync = require('child_process').execSync;
864
882
  let name = '',
865
883
  email = '';
866
884
  try {
@@ -875,7 +893,7 @@ class Utils {
875
893
  // 获取当前 Git 分支名(优先使用 git 命令,失败则返回空)
876
894
  getCurrentBranch(cwd) {
877
895
  try {
878
- const execSync = require('child_process').execSync;
896
+
879
897
  const out = execSync('git rev-parse --abbrev-ref HEAD', { cwd: cwd || process.cwd() });
880
898
  return String(out).trim();
881
899
  } catch (e) {
@@ -886,7 +904,6 @@ class Utils {
886
904
  // 获取远程仓库 URL(origin)
887
905
  getRemoteUrl(cwd) {
888
906
  try {
889
- const execSync = require('child_process').execSync;
890
907
  const out = execSync('git config --get remote.origin.url', { cwd: cwd || process.cwd() });
891
908
  return String(out).trim();
892
909
  } catch (e) {
@@ -940,8 +957,6 @@ class Utils {
940
957
  }
941
958
 
942
959
  gitpush(msg) {
943
- const execSync = require('child_process').execSync;
944
-
945
960
  var webPath = config.webPath || config.targetPath || config.skinPath;
946
961
  console.log('cd ' + webPath);
947
962
  //execSync('cd ' + webPath, { cwd: webPath }); // 必须切换到web路径,有些是在node_modules路径下
@@ -1130,6 +1145,7 @@ class Utils {
1130
1145
  crabaTool: {
1131
1146
  version: config.Version || 'unknown',
1132
1147
  startTime: new Date().toISOString(),
1148
+ runningMode: this.isRunningGlobally() ? 'global' : 'local',
1133
1149
  },
1134
1150
  craba: {
1135
1151
  version: crabaLocal.version || '',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crabatool",
3
- "version": "1.0.518",
3
+ "version": "1.0.703",
4
4
  "description": "crabatool",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -11,7 +11,6 @@
11
11
  "shell-doc": "node ./test/test.js -convertJavadoc -targetPath F:/docs/shell -outPath F:/docs/shell.json",
12
12
  "jxc-doc": "node ./test/test.js -convertJavadoc -targetPath F:/docs/jxc -outPath F:/docs/jxc.json",
13
13
  "sale-doc": "node ./test/test.js -convertJavadoc -targetPath F:/docs/sale -outPath F:/docs/sale.json",
14
- "ngp-parent-doc": "node ./test/test.js -convertJavadoc -targetPath F:/docs/ngp-parent -outPath F:/docs/ngp-parent.json -modName ngp-parent",
15
14
  "start": "node run.js",
16
15
  "test": "node ./test/test.js",
17
16
  "run": "node ./test/test.js -run -webPath F:/basicweb/www -refresh true",
@@ -1,9 +1,11 @@
1
- const { spawn } = require('child_process');
1
+ const { spawn, execSync } = require('child_process');
2
2
  const chalk = require('chalk');
3
3
  const path = require('path');
4
4
  const fs = require('fs');
5
5
  const ProgressBar = require('./progressbar.js');
6
6
  const config = require('../lib/config.js');
7
+ const utils = require('../lib/utils.js');
8
+
7
9
 
8
10
  class AutoUpdate {
9
11
  constructor() {
@@ -301,7 +303,14 @@ class AutoUpdate {
301
303
  performUpdate(silent = false) {
302
304
  return new Promise((resolve) => {
303
305
  const command = 'npm';
304
- const args = ['install', this.packageName, '--registry', this.registry];
306
+ const args = ['install'];
307
+
308
+ // 根据运行环境决定是否使用全局安装
309
+ if (utils.isRunningGlobally()) {
310
+ args.push('-g');
311
+ }
312
+
313
+ args.push(this.packageName, '--registry', this.registry);
305
314
 
306
315
  // 初始化进度条(非静默模式)
307
316
  if (!silent) {
@@ -342,7 +351,17 @@ class AutoUpdate {
342
351
  // 尝试获取版本信息
343
352
  let version = null;
344
353
  try {
345
- const packageJsonPath = path.join(process.cwd(), 'node_modules', this.packageName, 'package.json');
354
+ let packageJsonPath;
355
+
356
+ if (utils.isRunningGlobally()) {
357
+ // 全局安装:从全局 node_modules 获取
358
+ const globalNodeModules = execSync('npm root -g', { encoding: 'utf8' }).trim();
359
+ packageJsonPath = path.join(globalNodeModules, this.packageName, 'package.json');
360
+ } else {
361
+ // 本地安装:从当前目录 node_modules 获取
362
+ packageJsonPath = path.join(process.cwd(), 'node_modules', this.packageName, 'package.json');
363
+ }
364
+
346
365
  if (fs.existsSync(packageJsonPath)) {
347
366
  const packageInfo = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
348
367
  version = packageInfo.version;
package/tool/compress.js CHANGED
@@ -26,6 +26,7 @@ module.exports.run = function() {
26
26
  fs.unlinkSync(_zipName);
27
27
  }
28
28
 
29
+ console.log('版本号+1', _pkgPath);
29
30
  utils.addPackageVersion(_pkgPath); // 版本号+1
30
31
 
31
32
  // 版本号发生改变, 推送git仓库
@@ -69,7 +70,8 @@ function checkJsOk() {
69
70
 
70
71
  function checkJsHasZ(jsName) {
71
72
  var crabaJs = path.join(_tempJsPath, jsName);
72
- var contentJs = fs.readFileSync(crabaJs);
73
+ var contentJs = fs.readFileSync(crabaJs).toString();
74
+ console.log('检查压缩后的js里面是否有黑名单替换', crabaJs);
73
75
  if (contentJs.indexOf('_Z_') < 0) {
74
76
  var tips = '发版警告!!!upload craba失败!!!' + jsName + '文件的黑名单类名(_Z_)替换失败,终止打包和上传任务;请重试打包。';
75
77
  utils.postWeebhooks(tips);
@@ -167,6 +169,7 @@ function doCompress() {
167
169
  }
168
170
 
169
171
  function compressCrabaJs(inNames, outName, onEnd) {
172
+ console.log('打包压缩文件', outName);
170
173
  inNames = inNames.map((s) => {
171
174
  return path.join(_jsPath, s);
172
175
  });
@@ -13,7 +13,7 @@ var _pkgPath = path.join(_jsPath, 'package.json');
13
13
  var pkg = utils.readPackage(_pkgPath);
14
14
 
15
15
  module.exports.upload = function() {
16
- console.log('开始打包zip和上传');
16
+ console.log('开始打包zip和上传资源');
17
17
  doUploadPkg(config.version, _pkgPath, doZipCraba); // 先上传package版本信息文件,然后上传craba.zip资源包,再然后调用自动化测试
18
18
  }
19
19
 
@@ -27,6 +27,7 @@ function doUploadPkg(version, pkgPath, cb) {
27
27
  formData.append('my_file', fs.createReadStream(pkgPath));
28
28
  var headers = formData.getHeaders();
29
29
 
30
+ console.log('上传版本管理文件', pkgPath)
30
31
  axios({
31
32
  method: 'POST',
32
33
  url: apis,
@@ -39,9 +40,10 @@ function doUploadPkg(version, pkgPath, cb) {
39
40
  }
40
41
  }).then(function(response) {
41
42
  //console.log(response.data);
43
+ console.log('版本上传成功');
42
44
  if (cb) cb(version);
43
45
  }).catch(function(err) {
44
- console.log(err.message);
46
+ console.log('版本上传失败', err.message);
45
47
  });
46
48
  }
47
49
 
@@ -70,7 +72,7 @@ function doUploadCraba(version) {
70
72
 
71
73
  var text = new Date().toString() + " " + config.modName + '打包完成,上传资源' + pkg.version + '到' + version;
72
74
  console.log(text);
73
-
75
+
74
76
  //utils.postWeebhooks(text);
75
77
 
76
78
  axios({
@@ -165,8 +165,9 @@ function replaceBlackFunction(content, options) {
165
165
 
166
166
  var txt = fs.readFileSync(blackFile);
167
167
  var list = txt.toString().split('\r\n');
168
-
168
+ utils.debug("黑名单内容", list.length);
169
169
  var index = 0;
170
+
170
171
  list.forEach(function(name) {
171
172
  if (!name || name.trim() == '' || name.startsWith('#')) return;
172
173
 
package/tool/start.js CHANGED
@@ -277,11 +277,17 @@ class Start {
277
277
  console.log('💡 提示:重新启动 crabaTool 以使用最新版本');
278
278
  } else {
279
279
  console.log('⚠️ 更新失败,请检查网络连接或手动执行:');
280
- console.log(`npm install crabatool --registry ${config.registry}`);
280
+ const installCmd = utils.isRunningGlobally()
281
+ ? `npm install -g crabatool --registry ${config.registry}`
282
+ : `npm install crabatool --registry ${config.registry}`;
283
+ console.log(installCmd);
281
284
  }
282
285
  } catch (error) {
283
286
  console.log('❌ 更新过程中出现错误:', error.message);
284
- console.log(`💡 请手动执行:npm install crabatool --registry ${config.registry}`);
287
+ const installCmd = utils.isRunningGlobally()
288
+ ? `npm install -g crabatool --registry ${config.registry}`
289
+ : `npm install crabatool --registry ${config.registry}`;
290
+ console.log(`💡 请手动执行:${installCmd}`);
285
291
  }
286
292
 
287
293
  // 更新完成后返回主菜单
package/tool/upgrade.js CHANGED
@@ -13,11 +13,11 @@ class Upgrade {
13
13
  }
14
14
 
15
15
  getVersionUrl() {
16
- return utils.joinPath(config.SourceHost, "setup/" + config.version + "/package.json");
16
+ return utils.joinPath(config.SourceHost, "setup/" + config.version + "/package.json?_v_=" + new Date().getTime());
17
17
  }
18
18
 
19
19
  getCrabaFileUrl() {
20
- return utils.joinPath(config.SourceHost, "setup/" + config.version + "/craba.zip");
20
+ return utils.joinPath(config.SourceHost, "setup/" + config.version + "/craba.zip?_v_=" + new Date().getTime());
21
21
  }
22
22
 
23
23
  getLocalVersion() {