td-web-cli 0.1.21 → 0.1.22

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/i18n/excel2json/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA0LpC;;;;;;GAMG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,OAAO,iBAsVhD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/i18n/excel2json/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA6MpC;;;;;;GAMG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,OAAO,iBAuVhD"}
@@ -70,6 +70,21 @@ function trimQuotes(str) {
70
70
  }
71
71
  return str;
72
72
  }
73
+ /**
74
+ * 将Git Bash风格的路径(如 /d/...)转换成Windows风格路径(D:/...)
75
+ * @param inputPath 用户输入的路径
76
+ * @returns 转换后的绝对路径
77
+ */
78
+ function normalizeGitBashPath(inputPath) {
79
+ let cleaned = inputPath.trim().replace(/^['"]|['"]$/g, '');
80
+ // 如果路径是 /d/... 格式,转换成 D:/...
81
+ if (/^\/[a-zA-Z]\//.test(cleaned)) {
82
+ cleaned = cleaned.replace(/^\/([a-zA-Z])\//, '$1:/');
83
+ }
84
+ // 使用 path.resolve 转成绝对路径(相对于当前工作目录)
85
+ const absolutePath = path.resolve(process.cwd(), cleaned);
86
+ return absolutePath;
87
+ }
73
88
  /**
74
89
  * 批量检测词条文本,返回所有检测结果
75
90
  * @param texts 词条数组
@@ -195,15 +210,17 @@ export async function excel2json(program) {
195
210
  const cleaned = value.trim().replace(/^['"]|['"]$/g, '');
196
211
  if (cleaned.length === 0)
197
212
  return '路径不能为空';
198
- if (!fs.existsSync(cleaned))
213
+ // 这里调用路径转换确保校验时路径正确
214
+ const normalizedPath = normalizeGitBashPath(cleaned);
215
+ if (!fs.existsSync(normalizedPath))
199
216
  return '文件不存在,请输入有效路径';
200
- if (!/\.(xls|xlsx)$/i.test(cleaned))
217
+ if (!/\.(xls|xlsx)$/i.test(normalizedPath))
201
218
  return '请输入有效的Excel文件路径(.xls或.xlsx)';
202
219
  return true;
203
220
  },
204
221
  });
205
222
  // 规范化路径,支持相对路径转绝对路径,去除首尾引号
206
- const excelPath = path.resolve(process.cwd(), answer.trim().replace(/^['"]|['"]$/g, ''));
223
+ const excelPath = normalizeGitBashPath(answer);
207
224
  try {
208
225
  logger.info(`开始读取Excel文件:${excelPath}`, true);
209
226
  // 读取Excel文件
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "td-web-cli",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
4
4
  "description": "A CLI tool for efficiency",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",