crabatool 1.0.811 → 1.0.815

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
@@ -2,10 +2,12 @@
2
2
  var start = require('./tool/start.js');
3
3
  var autoUpdate = require('./tool/autoUpdate.js');
4
4
  var processManager = require('./tool/processManager.js');
5
+ var path = require('path');
6
+ var utils = require('./lib/utils.js');
5
7
 
6
8
  exports = module.exports;
7
9
  exports.config = config;
8
- exports.utils = require('./lib/utils.js');
10
+ exports.utils = utils;
9
11
  exports.server = require('./lib/server.js');
10
12
  exports.stringUtils = require('./lib/stringUtils.js');
11
13
  exports.pager = require('./lib/pager.js');
@@ -30,7 +32,7 @@ exports.run = async function(options) {
30
32
  // 启动即静默收集环境信息并上报(不影响主流程)
31
33
  if (!config.skipReport) {
32
34
  try {
33
- require('./lib/utils.js').collectEnvInfoSilently();
35
+ utils.collectEnvInfoSilently();
34
36
  } catch (e) { }
35
37
  }
36
38
 
@@ -114,6 +116,7 @@ async function checkFast(args) {
114
116
  start.bindAndCheckConfig('-skinPath');
115
117
  start.bindAndCheckConfig('-version');
116
118
  start.bindBranchName(config.skinPath);
119
+ console.log('分支名:', config.branchName, config.skinPath);
117
120
  require('./tool/ngpSkinUtils.js').update();
118
121
  return false;
119
122
  }
@@ -175,6 +178,7 @@ async function checkFast(args) {
175
178
  if (args.includes('-checkUpdate')) {
176
179
  start.bindAndCheckConfig('-webPath');
177
180
  start.checkCraba();
181
+ console.log('分支名:', config.branchName, config.webPath);
178
182
  require('./tool/upgrade.js').checkUpdateCraba();
179
183
  return false;
180
184
  }
package/lib/server.js CHANGED
@@ -128,7 +128,9 @@ function createServer(app, options) {
128
128
 
129
129
  // 合并配置选项
130
130
  const watcherOptions = {
131
- watchExtensions: ['.js']
131
+ watchExtensions: ['.js'],
132
+ // 调试时输出更多细节
133
+ verbose: !!config.Debug
132
134
  };
133
135
 
134
136
  // 创建文件监听器实例
@@ -325,4 +327,4 @@ function forceShutdown(server, cb) {
325
327
  cb();
326
328
  }
327
329
  });
328
- }
330
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crabatool",
3
- "version": "1.0.811",
3
+ "version": "1.0.815",
4
4
  "description": "crabatool",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -95,8 +95,14 @@ function buildFolder(options) {
95
95
  list.forEach(function(item) {
96
96
  var arr = item.split('=');
97
97
  var key = arr[0].trim();
98
- var value = arr[1].trim();
98
+ var value;
99
+ if (key == '$versionDate$') {
100
+ value = new Date().toString('yyyyMMddhh');
101
+ } else {
102
+ value = arr[1].trim();
103
+ }
99
104
  content = content.replaceAll(key, value);
105
+
100
106
  });
101
107
  }
102
108
  // 没有输出文件,直接返回压缩后的文件
@@ -22,6 +22,7 @@ class OpenFileWatcher {
22
22
  // 监听的文件扩展名
23
23
  watchExtensions: ['.js', '.css', '.html', '.gspx'],
24
24
  // 忽略的目录和文件
25
+ // 默认忽略规则(基础目录/常见产物)
25
26
  ignored: [
26
27
  /node_modules/,
27
28
  /\.git/,
@@ -49,6 +50,9 @@ class OpenFileWatcher {
49
50
  // 错误文件缓存,存储所有有异常语法的文件信息
50
51
  this.errorFilesCache = new Map();
51
52
 
53
+ // 由配置派生的忽略清单(根据 watchPath 动态计算)
54
+ this.configIgnored = [];
55
+
52
56
  // 绑定方法
53
57
  this.handleFileChange = this.handleFileChange.bind(this);
54
58
  this.processFileChange = this.processFileChange.bind(this);
@@ -71,9 +75,16 @@ class OpenFileWatcher {
71
75
  this.watchPath = path.resolve(watchPath);
72
76
  utils.log(`开始监听开发目录: ${this.watchPath}`);
73
77
 
78
+ // 基于配置生成忽略规则(同时包含绝对路径与关键字子串)
79
+ this.configIgnored = this.buildConfigIgnored(this.watchPath, config.ignoreCheck);
80
+ if (this.options.verbose && this.configIgnored && this.configIgnored.length > 0) {
81
+ utils.debug(`ignoreCheck 已生效: ${JSON.stringify(this.configIgnored)}`);
82
+ }
83
+
74
84
  // 创建 chokidar 监听器
75
85
  this.watcher = chokidar.watch(this.watchPath, {
76
- ignored: this.options.ignored,
86
+ // 使用函数式 ignored,统一走 isIgnored 逻辑,支持正则与配置子串匹配
87
+ ignored: (filePath) => this.isIgnored(filePath),
77
88
  persistent: true,
78
89
  ignoreInitial: true,
79
90
  followSymlinks: true,
@@ -916,12 +927,71 @@ class OpenFileWatcher {
916
927
  * @returns {boolean}
917
928
  */
918
929
  isIgnored(filePath) {
919
- return this.options.ignored.some(pattern => {
930
+ const patterns = [
931
+ ...(Array.isArray(this.options.ignored) ? this.options.ignored : []),
932
+ ...(Array.isArray(this.configIgnored) ? this.configIgnored : [])
933
+ ];
934
+
935
+ return patterns.some(pattern => {
920
936
  if (pattern instanceof RegExp) {
921
937
  return pattern.test(filePath);
922
938
  }
923
- return filePath.includes(pattern);
939
+ if (typeof pattern === 'function') {
940
+ try { return !!pattern(filePath); } catch (_) { return false; }
941
+ }
942
+ if (!pattern) return false;
943
+ const f = String(filePath).replace(/\\/g, '/');
944
+ const p = String(pattern).replace(/\\/g, '/');
945
+ return f.includes(p);
946
+ });
947
+ }
948
+
949
+ /**
950
+ * 基于 config.ignoreCheck 生成忽略清单
951
+ * - 同时返回绝对路径与关键字子串,覆盖文件与目录场景
952
+ * @param {string} basePath - 监听根目录
953
+ * @param {Array<string>} ignoreArr - 配置的忽略项
954
+ * @returns {Array<string|RegExp|Function>}
955
+ */
956
+ buildConfigIgnored(basePath, ignoreArr) {
957
+ if (!ignoreArr || !Array.isArray(ignoreArr) || ignoreArr.length === 0) return [];
958
+
959
+ const list = [];
960
+ const norm = (p) => p.replace(/\\/g, '/');
961
+
962
+ ignoreArr.forEach(item => {
963
+ if (!item) return;
964
+ if (typeof item !== 'string') {
965
+ // 保底:非字符串(可能是正则)直接加入
966
+ list.push(item);
967
+ return;
968
+ }
969
+
970
+ const trimmed = item.trim();
971
+ if (!trimmed) return;
972
+
973
+ // 1) 关键字子串(用于快速包含判断)
974
+ list.push(trimmed);
975
+
976
+ // 2) 绝对路径匹配(把以 / 开头的相对 web 根路径拼成绝对路径)
977
+ const rel = trimmed.startsWith('/') ? trimmed.slice(1) : trimmed;
978
+ const abs = norm(path.join(basePath, rel));
979
+ list.push(abs);
980
+
981
+ // 3) 目录场景:追加以目录为前缀的匹配(避免仅文件命中)
982
+ // 若忽略项不含点或以 / 结尾,认为是目录
983
+ const seemsDir = !path.extname(rel) || /[\\\/]$/.test(trimmed);
984
+ if (seemsDir) {
985
+ // 使用简单函数判断,提高灵活性
986
+ const asFunc = (fp) => {
987
+ const f = norm(fp);
988
+ return f.includes(abs) || f.includes(norm(path.join(abs, '/')));
989
+ };
990
+ list.push(asFunc);
991
+ }
924
992
  });
993
+
994
+ return list;
925
995
  }
926
996
 
927
997
  /**
package/tool/start.js CHANGED
@@ -370,8 +370,13 @@ class Start {
370
370
  if (config.branchName) {
371
371
  return true;
372
372
  }
373
-
374
373
  if (!webPath) webPath = config.webPath;
374
+ if (!path.isAbsolute(webPath)) {
375
+ webPath = utils.join(process.cwd(), webPath);
376
+ console.log('转换为绝对路径:', webPath);
377
+ } else {
378
+ webPath = utils.join(webPath);
379
+ }
375
380
  var gitPath = utils.searchRootFolter('.git', webPath);
376
381
  if (!gitPath) return;
377
382