td-web-cli 0.1.20 → 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.
package/README.md
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
- [环境要求](#环境要求)
|
|
10
10
|
- [安装](#安装)
|
|
11
|
-
- [开发](#开发)
|
|
12
11
|
- [使用](#使用)
|
|
12
|
+
- [开发](#开发)
|
|
13
13
|
- [构建](#构建)
|
|
14
14
|
- [发布](#发布)
|
|
15
15
|
- [项目结构](#项目结构)
|
|
@@ -18,16 +18,38 @@
|
|
|
18
18
|
|
|
19
19
|
## 环境要求
|
|
20
20
|
|
|
21
|
-
- Node.js >= 20.
|
|
22
|
-
- npm >= 10.
|
|
23
|
-
- TypeScript >= 5.x
|
|
21
|
+
- Node.js >= 20.18.2(推荐使用 22.x 或更高版本)
|
|
22
|
+
- npm >= 10.8.2
|
|
24
23
|
|
|
25
|
-
>
|
|
24
|
+
> **注意**:部分依赖可能要求更高版本,请根据实际情况调整。
|
|
26
25
|
|
|
27
26
|
---
|
|
28
27
|
|
|
29
28
|
## 安装
|
|
30
29
|
|
|
30
|
+
```bash
|
|
31
|
+
npm i -g td-web-cli
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 使用
|
|
37
|
+
|
|
38
|
+
### 命令行执行
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
td-web-cli
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 功能说明
|
|
45
|
+
|
|
46
|
+
- 多语言 Excel 转 JSON 工具。[详细功能说明请点击这里](https://github.com/qianyuzzf/td-web-cli/blob/master/docs/i18n/excel2json.md)
|
|
47
|
+
- 节假日查询工具。[详细功能说明请点击这里](https://github.com/qianyuzzf/td-web-cli/blob/master/docs/tools/getHolidayTime.md)
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## 开发
|
|
52
|
+
|
|
31
53
|
1. 克隆仓库
|
|
32
54
|
|
|
33
55
|
```bash
|
|
@@ -41,10 +63,6 @@ cd td-web-cli
|
|
|
41
63
|
npm install
|
|
42
64
|
```
|
|
43
65
|
|
|
44
|
-
---
|
|
45
|
-
|
|
46
|
-
## 开发
|
|
47
|
-
|
|
48
66
|
### 代码结构
|
|
49
67
|
|
|
50
68
|
- `src/` - TypeScript 源代码目录
|
|
@@ -63,23 +81,6 @@ td-web-cli # 确保本机未全局安装该工具
|
|
|
63
81
|
|
|
64
82
|
---
|
|
65
83
|
|
|
66
|
-
## 使用
|
|
67
|
-
|
|
68
|
-
### 命令行执行
|
|
69
|
-
|
|
70
|
-
执行 CLI 工具:
|
|
71
|
-
|
|
72
|
-
```bash
|
|
73
|
-
td-web-cli
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
### 功能说明
|
|
77
|
-
|
|
78
|
-
- 多语言 Excel 转 JSON 工具。[详细功能说明请点击这里](https://github.com/qianyuzzf/td-web-cli/blob/master/docs/i18n/excel2json.md)
|
|
79
|
-
- 节假日查询工具。[详细功能说明请点击这里](https://github.com/qianyuzzf/td-web-cli/blob/master/docs/tools/getHolidayTime.md)
|
|
80
|
-
|
|
81
|
-
---
|
|
82
|
-
|
|
83
84
|
## 构建
|
|
84
85
|
|
|
85
86
|
使用 TypeScript 编译项目:
|
|
@@ -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;
|
|
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
|
-
|
|
213
|
+
// 这里调用路径转换确保校验时路径正确
|
|
214
|
+
const normalizedPath = normalizeGitBashPath(cleaned);
|
|
215
|
+
if (!fs.existsSync(normalizedPath))
|
|
199
216
|
return '文件不存在,请输入有效路径';
|
|
200
|
-
if (!/\.(xls|xlsx)$/i.test(
|
|
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 =
|
|
223
|
+
const excelPath = normalizeGitBashPath(answer);
|
|
207
224
|
try {
|
|
208
225
|
logger.info(`开始读取Excel文件:${excelPath}`, true);
|
|
209
226
|
// 读取Excel文件
|