crabatool 1.0.508 → 1.0.510

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/lib/jsoncrud.js CHANGED
@@ -67,11 +67,11 @@ class JSONCRUD {
67
67
  }
68
68
  }
69
69
 
70
- async batchCreate(entityName, items) {
70
+ async batchCreate(entityName, items) {
71
71
  await this.ready()
72
72
  this.verifyEntityExists(entityName)
73
73
  var _this = this;
74
- items.forEach(item=>{
74
+ items.forEach(item => {
75
75
  const newItem = {
76
76
  id: cuid.newCuidString(),//允许外部提前制定ID
77
77
  ...item,
@@ -119,7 +119,7 @@ class JSONCRUD {
119
119
  } else if (typeof v1 == 'number') {
120
120
  return sortOrder === 'acs' ? v1 > v2 : v1 < v2;
121
121
  } else {
122
- return sortOrder === 'asc' ? v1?.localeCompare(v2) : v2?.localeCompare(v1);
122
+ return sortOrder === 'asc' ? v1.localeCompare(v2) : v2.localeCompare(v1);
123
123
  }
124
124
  });
125
125
 
@@ -239,7 +239,7 @@ class JSONCRUD {
239
239
  if (stats.isFile()) {
240
240
  var entityName = file.substring(0, file.lastIndexOf('.'));
241
241
  var temp = await fs.readFile(filePath, 'utf-8')
242
- fileContent[entityName] = temp?JSON.parse(temp):{};
242
+ fileContent[entityName] = temp ? JSON.parse(temp) : {};
243
243
  } else if (stats.isDirectory()) {
244
244
  // 如果需要递归处理子目录,可以在这里调用readAllFilesInDirectory(filePath)
245
245
  }
package/lib/utils.js CHANGED
@@ -10,19 +10,27 @@ var axios = require('axios');
10
10
  var os = require('os');
11
11
 
12
12
  if (!String.prototype.replaceAll) {
13
- String.prototype.replaceAll = function (s1, s2) {
14
- return this.replace(new RegExp(s1, 'gm'), s2);
13
+ String.prototype.replaceAll = function(search, replacement) {
14
+ function escapeRegExp(string) {
15
+ return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
16
+ }
17
+
18
+ if (typeof search === 'string') {
19
+ search = escapeRegExp(search);
20
+ }
21
+
22
+ return this.replace(new RegExp(search, 'g'), replacement);
15
23
  };
16
24
  }
17
25
 
18
- Buffer.prototype.toByteArray = function () {
26
+ Buffer.prototype.toByteArray = function() {
19
27
  return Array.prototype.slice.call(this, 0);
20
28
  };
21
- Date.prototype.toString = function (format) {
29
+ Date.prototype.toString = function(format) {
22
30
  if (!format) format = 'yyyy-MM-dd hh:mm:ss';
23
31
  return this.format(format);
24
32
  };
25
- Date.prototype.format = function (fmt) {
33
+ Date.prototype.format = function(fmt) {
26
34
  var o = {
27
35
  'M+': this.getMonth() + 1, //月份
28
36
  'd+': this.getDate(), //日
@@ -42,7 +50,7 @@ Date.prototype.format = function (fmt) {
42
50
  );
43
51
  return fmt;
44
52
  };
45
- Date.prototype.toJSON = function () {
53
+ Date.prototype.toJSON = function() {
46
54
  return this.format('yyyy-MM-dd hh:mm:ss');
47
55
  };
48
56
 
@@ -163,7 +171,7 @@ class Utils {
163
171
  }
164
172
 
165
173
  var text = args[0];
166
- text = text.replace(/{-?[0-9]+}/g, function (match, format) {
174
+ text = text.replace(/{-?[0-9]+}/g, function(match, format) {
167
175
  var intVal = parseInt(match.substring(1, match.length - 1));
168
176
  var replace;
169
177
  if (intVal >= 0) {
@@ -376,7 +384,7 @@ class Utils {
376
384
  return;
377
385
  }
378
386
 
379
- fs.readdirSync(dirname).forEach(function (file) {
387
+ fs.readdirSync(dirname).forEach(function(file) {
380
388
  var filePath = utils.join(dirname, file);
381
389
  if (fs.statSync(filePath).isDirectory()) {
382
390
  //递归读取文件
@@ -510,11 +518,11 @@ class Utils {
510
518
  data: data,
511
519
  headers: { 'Content-Type': 'application/json' },
512
520
  })
513
- .then(function (response) {
521
+ .then(function(response) {
514
522
  //console.log("推送代码检测状态");
515
523
  //console.log(response.data);
516
524
  })
517
- .catch(function (error) {
525
+ .catch(function(error) {
518
526
  //console.log("推送代码检测失败:" + error.message);
519
527
  //console.log(error);
520
528
  });
@@ -607,7 +615,7 @@ class Utils {
607
615
  }
608
616
 
609
617
  var files = fs.readdirSync(source);
610
- files.forEach(function (fileName) {
618
+ files.forEach(function(fileName) {
611
619
  if (fileName == 'node_modules') {
612
620
  return;
613
621
  }
@@ -646,7 +654,7 @@ class Utils {
646
654
 
647
655
  copyFiles(source, dest, ignores, cb) {
648
656
  var files = utils.getFiles({ source: source, ignores: ignores });
649
- files.forEach(function (filePath) {
657
+ files.forEach(function(filePath) {
650
658
  var fileName = filePath.replace(source, ''); // 去掉根路径
651
659
  var destPath = utils.join(dest, fileName);
652
660
 
@@ -766,7 +774,7 @@ class Utils {
766
774
  timeout: config.timeout,
767
775
  responseType: 'stream',
768
776
  })
769
- .then(function (response) {
777
+ .then(function(response) {
770
778
  if (callback === true) {
771
779
  //fs.fchmodSync(path.dirname(savePath), '0711'); // 修改权限
772
780
  //fs.chmodSync(path.dirname(savePath), '0711');
@@ -778,7 +786,7 @@ class Utils {
778
786
  if (typeof callback == 'function') callback(savePath);
779
787
  });
780
788
  })
781
- .catch(function (error) {
789
+ .catch(function(error) {
782
790
  //console.log('[内网才能访问],network error');
783
791
  console.log(error.code, error.response.status, error.message);
784
792
  });
@@ -857,10 +865,10 @@ class Utils {
857
865
  email = '';
858
866
  try {
859
867
  name = String(execSync('git config user.name', { cwd: cwd || process.cwd() })).trim();
860
- } catch (e) {}
868
+ } catch (e) { }
861
869
  try {
862
870
  email = String(execSync('git config user.email', { cwd: cwd || process.cwd() })).trim();
863
- } catch (e) {}
871
+ } catch (e) { }
864
872
  return { name, email };
865
873
  }
866
874
 
@@ -1032,28 +1040,28 @@ class Utils {
1032
1040
 
1033
1041
  const git = envData.git;
1034
1042
  const project = envData.project;
1035
-
1043
+
1036
1044
  // 1. 提取关键信息
1037
1045
  const gitUser = git.user || {};
1038
1046
  const userName = gitUser.name || 'unknown';
1039
1047
  const userEmail = gitUser.email || 'unknown';
1040
1048
  const remoteUrl = git.remoteUrl || '';
1041
1049
  const projectPath = project.path || '';
1042
-
1050
+
1043
1051
  // 2. 标准化远程URL(去除协议和.git后缀,统一格式)
1044
1052
  let normalizedRemoteUrl = remoteUrl
1045
1053
  .replace(/^(https?:\/\/|git@|ssh:\/\/git@)/, '') // 去除协议前缀
1046
1054
  .replace(/\.git$/, '') // 去除.git后缀
1047
1055
  .replace(/:/g, '/') // 统一分隔符
1048
1056
  .toLowerCase(); // 转小写
1049
-
1057
+
1050
1058
  // 3. 提取项目路径特征(取最后两级目录)
1051
1059
  const pathParts = projectPath.split(path.sep).filter(p => p);
1052
1060
  const projectPathFeature = pathParts.slice(-2).join('/');
1053
-
1061
+
1054
1062
  // 4. 提取分支信息
1055
1063
  const branchName = git.branch || 'unknown';
1056
-
1064
+
1057
1065
  // 5. 构建标识符组件
1058
1066
  const components = [
1059
1067
  `user:${userName}:${userEmail}`,
@@ -1061,16 +1069,16 @@ class Utils {
1061
1069
  `branch:${branchName}`,
1062
1070
  `path:${projectPathFeature}`
1063
1071
  ];
1064
-
1072
+
1065
1073
  // 6. 生成哈希值确保唯一性
1066
1074
  const combinedString = components.join('|');
1067
1075
  const hash = this.md5(combinedString);
1068
-
1076
+
1069
1077
  // 7. 格式化输出:前缀-哈希前8位-哈希后8位
1070
1078
  const shortHash = hash.substring(0, 8);
1071
1079
  const tailHash = hash.substring(-8);
1072
1080
  const identifier = `proj-${shortHash}-${tailHash}`;
1073
-
1081
+
1074
1082
  return {
1075
1083
  identifier: identifier,
1076
1084
  hash: hash,
@@ -1159,7 +1167,7 @@ class Utils {
1159
1167
 
1160
1168
  // 异步上报,不阻塞主流程
1161
1169
  // setImmediate(function () {
1162
- utils.sendEnvToBackend(envData);
1170
+ utils.sendEnvToBackend(envData);
1163
1171
  // });
1164
1172
 
1165
1173
  return envData;
@@ -1190,10 +1198,10 @@ class Utils {
1190
1198
  headers: { 'Content-Type': 'application/json' },
1191
1199
  timeout: 2000,
1192
1200
  })
1193
- .then(function () {
1201
+ .then(function() {
1194
1202
  // 静默,不打印
1195
1203
  })
1196
- .catch(function (error) {
1204
+ .catch(function(error) {
1197
1205
  // 静默失败,不抛出
1198
1206
  if (config.Debug) {
1199
1207
  console.log('环境信息上报失败:' + (error && error.message ? error.message : error));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crabatool",
3
- "version": "1.0.508",
3
+ "version": "1.0.510",
4
4
  "description": "crabatool",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -10,6 +10,7 @@
10
10
  "javadocFile": "node ./test/test.js -convertJavadoc -filePath F:/docs/shell/com/wsgjp/ct/shell/biz/entity/Etype.html -outPath F:/docs/md",
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
+ "sale-doc": "node ./test/test.js -convertJavadoc -targetPath F:/docs/sale -outPath F:/docs/sale.json",
13
14
  "start": "node run.js",
14
15
  "test": "node ./test/test.js",
15
16
  "run": "node ./test/test.js -run -webPath F:/basicweb/www -refresh true",