dsh-apis-plugin 0.2.2 → 0.2.3
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 +2 -2
- package/api-tools.js +14 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@ config/
|
|
|
30
30
|
└── api_doc.md
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
> cfg 文件名任意(`api.cfg`、`config.cfg`、`<host>.cfg`
|
|
33
|
+
> cfg 文件名任意(`api.cfg`、`config.cfg`、`<host>.cfg` 均可),扫描**递归**收集目录下所有 `*.cfg`(含任意深度子文件夹,限 5 层),集合身份只看里面的 `host` 字段;同一个子文件夹放多个 cfg 即为多个集合。**新增/修改 cfg 后需点「扫描」或重启生效。**
|
|
34
34
|
|
|
35
35
|
### 1. xxx.cfg(每个集合一份,必需)
|
|
36
36
|
|
|
@@ -41,7 +41,7 @@ key=value 行格式,`#` 注释,UTF-8 编码:
|
|
|
41
41
|
host=site-a.example.com
|
|
42
42
|
|
|
43
43
|
# 集合用途说明(可选),会展示在接口目录与手风琴中,方便 AI 理解查询范围
|
|
44
|
-
title
|
|
44
|
+
title=xxx
|
|
45
45
|
|
|
46
46
|
# 该集合的接口服务前缀:域名 + nginx 前缀 + 网关路由段
|
|
47
47
|
baseUrl=http://your-host/api
|
package/api-tools.js
CHANGED
|
@@ -26,10 +26,9 @@ function loadCfgFile(file) {
|
|
|
26
26
|
return cfg
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
//
|
|
29
|
+
// 扫描目录下的「接口集合」:递归遍历目录下所有 *.cfg(含根目录直放与任意深度子文件夹),
|
|
30
30
|
// 集合名取 cfg 的 host 字段(缺失时依次回退 baseUrl 的主机名、文件所在文件夹名)
|
|
31
31
|
function scanCollections(dir) {
|
|
32
|
-
if (!dir) return []
|
|
33
32
|
const out = []
|
|
34
33
|
const hostFromUrl = (url) => {
|
|
35
34
|
try {
|
|
@@ -42,16 +41,20 @@ function scanCollections(dir) {
|
|
|
42
41
|
const cfg = loadCfgFile(file)
|
|
43
42
|
if (cfg.apis.length) out.push({ name: cfg.host || hostFromUrl(cfg.baseUrl) || basename(dirname(file)), title: cfg.title || '', file, dir: dirname(file), baseUrl: cfg.baseUrl || '', apis: cfg.apis })
|
|
44
43
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
44
|
+
// 递归下钻,限深 5 层防符号链接成环
|
|
45
|
+
const walk = (d, depth) => {
|
|
46
|
+
if (depth > 5) return
|
|
47
|
+
let entries
|
|
48
|
+
try {
|
|
49
|
+
entries = readdirSync(d, { withFileTypes: true })
|
|
50
|
+
} catch { /* 目录不可读时跳过 */ }
|
|
51
|
+
for (const entry of entries ?? []) {
|
|
52
|
+
const p = join(d, entry.name)
|
|
53
|
+
if (entry.isDirectory()) walk(p, depth + 1)
|
|
54
|
+
else if (entry.isFile() && entry.name.endsWith('.cfg')) push(p)
|
|
53
55
|
}
|
|
54
|
-
}
|
|
56
|
+
}
|
|
57
|
+
if (dir) walk(dir, 0)
|
|
55
58
|
return out
|
|
56
59
|
}
|
|
57
60
|
|