@koishi-ce/plugin-explorer 1.0.0
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/dist/abap-5QO_8uqP.js +1 -0
- package/dist/apex-5UlMAo5f.js +1 -0
- package/dist/azcli-ue5GhsHI.js +1 -0
- package/dist/bat-C6DzPBcU.js +1 -0
- package/dist/bicep-B6UDBWZN.js +2 -0
- package/dist/cameligo-BoKy-zSd.js +1 -0
- package/dist/clojure-D8WHGr6v.js +1 -0
- package/dist/coffee-C16Mnhbm.js +1 -0
- package/dist/cpp-_HbkGdoj.js +1 -0
- package/dist/csharp-DeGXkEgi.js +1 -0
- package/dist/csp-DGVEba9U.js +1 -0
- package/dist/css-DmO2GtiT.js +3 -0
- package/dist/css.worker-4rXhrMqv.js +93 -0
- package/dist/cssMode-1LtGlOpZ.js +1 -0
- package/dist/cypher-5654EJL_.js +1 -0
- package/dist/dart-BjXVSQM-.js +1 -0
- package/dist/dockerfile-DSA8TJLS.js +1 -0
- package/dist/ecl-DoDWSDGs.js +1 -0
- package/dist/editor.api-Bc6KxOlv.js +847 -0
- package/dist/editor.worker--KrnRFp2.js +30 -0
- package/dist/elixir-CzC02SL7.js +1 -0
- package/dist/flow9-B0wWbREE.js +1 -0
- package/dist/freemarker2-CISI4Fea.js +3 -0
- package/dist/fsharp-DRGCXPNW.js +1 -0
- package/dist/go-CyErB8P9.js +1 -0
- package/dist/graphql-CNnvnjR8.js +1 -0
- package/dist/handlebars-DvKdinkY.js +1 -0
- package/dist/hcl-D4a6HBjk.js +1 -0
- package/dist/html-DAvggYiF.js +1 -0
- package/dist/html.worker-Cq5BYliY.js +506 -0
- package/dist/htmlMode-CcNdoR2q.js +1 -0
- package/dist/index.css +2 -0
- package/dist/index.js +5 -0
- package/dist/ini-CpSjysbn.js +1 -0
- package/dist/java-DkRrYYRp.js +1 -0
- package/dist/javascript-CnOtpH9W.js +1 -0
- package/dist/json.worker-CZ-LFiWx.js +62 -0
- package/dist/jsonMode-C4WTYRiD.js +7 -0
- package/dist/julia-DXDdnD4p.js +1 -0
- package/dist/kotlin-BNDyMshT.js +1 -0
- package/dist/less-3yDKfG4U.js +2 -0
- package/dist/lexon-DBbVOF6F.js +1 -0
- package/dist/liquid-BmHgnygX.js +1 -0
- package/dist/lspLanguageFeatures-sAtNnmvG.js +4 -0
- package/dist/lua-CqDy9oHE.js +1 -0
- package/dist/m3-DyBtJGhR.js +1 -0
- package/dist/markdown-DIkeztiD.js +1 -0
- package/dist/mdx-D83lx9Wh.js +1 -0
- package/dist/mips-BUbWxz0r.js +1 -0
- package/dist/msdax-95fojGvn.js +1 -0
- package/dist/mysql-CX3tETwr.js +1 -0
- package/dist/objective-c-CK2i53vc.js +1 -0
- package/dist/pascal-wnGRqmNG.js +1 -0
- package/dist/pascaligo-DR2NqTqc.js +1 -0
- package/dist/perl-DXuijcFO.js +1 -0
- package/dist/pgsql-BFvD7ctB.js +1 -0
- package/dist/php-FZHoZ5C_.js +1 -0
- package/dist/pla-Cmb_VVG6.js +1 -0
- package/dist/postiats-DUwtyBVk.js +1 -0
- package/dist/powerquery-wUlwxvME.js +1 -0
- package/dist/powershell-Wf4X7WOf.js +1 -0
- package/dist/protobuf-CcMDFVG6.js +2 -0
- package/dist/pug-OPBd_9cN.js +1 -0
- package/dist/python-FXl0z-xu.js +1 -0
- package/dist/qsharp-C4P6iWbB.js +1 -0
- package/dist/r-FHjiK9Ff.js +1 -0
- package/dist/razor-B0ToKtbH.js +1 -0
- package/dist/redis-CLJ_Tkzp.js +1 -0
- package/dist/redshift-Cn0YgnO8.js +1 -0
- package/dist/register-BMDkZZEK.js +1 -0
- package/dist/restructuredtext-Ckzl4aRZ.js +1 -0
- package/dist/ruby-Dhjv9xsd.js +1 -0
- package/dist/rust-Bq7le2bN.js +1 -0
- package/dist/sb-Da-ijGg8.js +1 -0
- package/dist/scala-Bth6QY64.js +1 -0
- package/dist/scheme-BHXdn3HT.js +1 -0
- package/dist/scss-DVPfVfp2.js +3 -0
- package/dist/shell-DYY2DoAm.js +1 -0
- package/dist/solidity-C2dWya5C.js +1 -0
- package/dist/sophia-BdPli0VA.js +1 -0
- package/dist/sparql-Ca6NBL_y.js +1 -0
- package/dist/sql-CE5EfRV1.js +1 -0
- package/dist/st-BKcHiAlg.js +1 -0
- package/dist/swift-v0LuaFKN.js +1 -0
- package/dist/systemverilog-BRC61WOW.js +1 -0
- package/dist/tcl-Xx48oN1j.js +1 -0
- package/dist/toggleHighContrast-CvRejRMg.js +51 -0
- package/dist/ts.worker-BlgIolvr.js +67738 -0
- package/dist/tsMode-DIVsNbAC.js +11 -0
- package/dist/twig-Dq5WyzaF.js +1 -0
- package/dist/typescript-BhLUcgeg.js +1 -0
- package/dist/typespec-DVZXVZWY.js +1 -0
- package/dist/vb--Ows3SAS.js +1 -0
- package/dist/wgsl-gwRTfDFE.js +298 -0
- package/dist/workers-BbGPbtro.js +1 -0
- package/dist/xml-KQkUiUv0.js +1 -0
- package/dist/yaml-CG_Z0tAN.js +1 -0
- package/lib/assets/zh-CN-ZoUUQH0N.yml +3 -0
- package/lib/index.d.ts +91 -0
- package/lib/index.mjs +135 -0
- package/locales/de-DE.yml +3 -0
- package/locales/en-US.yml +3 -0
- package/locales/fr-FR.yml +3 -0
- package/locales/ja-JP.yml +3 -0
- package/locales/ru-RU.yml +3 -0
- package/locales/zh-CN.yml +3 -0
- package/locales/zh-TW.yml +3 -0
- package/package.json +79 -0
- package/src/index.ts +283 -0
package/package.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@koishi-ce/plugin-explorer",
|
|
3
|
+
"description": "File explorer and editor for Koishi",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.mjs",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"source": "./src/index.ts",
|
|
11
|
+
"types": "./lib/index.d.ts",
|
|
12
|
+
"import": "./lib/index.mjs",
|
|
13
|
+
"default": "./lib/index.mjs"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"lib",
|
|
19
|
+
"dist",
|
|
20
|
+
"src",
|
|
21
|
+
"locales"
|
|
22
|
+
],
|
|
23
|
+
"contributors": [
|
|
24
|
+
"Shigma <shigma10826@gmail.com>",
|
|
25
|
+
"Oppenheymu <oppenheymu@gmail.com>"
|
|
26
|
+
],
|
|
27
|
+
"license": "AGPL-3.0",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/Koishi-CE/koishi.git",
|
|
31
|
+
"directory": "plugins/webui/explorer"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/Koishi-CE/koishi/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://koishi.chat/plugins/console/explorer.html",
|
|
37
|
+
"keywords": [
|
|
38
|
+
"bot",
|
|
39
|
+
"chatbot",
|
|
40
|
+
"koishi",
|
|
41
|
+
"plugin",
|
|
42
|
+
"file",
|
|
43
|
+
"tree",
|
|
44
|
+
"editor",
|
|
45
|
+
"explorer"
|
|
46
|
+
],
|
|
47
|
+
"koishi": {
|
|
48
|
+
"public": [
|
|
49
|
+
"dist"
|
|
50
|
+
],
|
|
51
|
+
"description": {
|
|
52
|
+
"en": "File explorer and editor",
|
|
53
|
+
"zh": "资源管理器和文件编辑器"
|
|
54
|
+
},
|
|
55
|
+
"service": {
|
|
56
|
+
"required": [
|
|
57
|
+
"console"
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"@koishijs/plugin-console": "^5.30.11",
|
|
63
|
+
"koishi": "^4.18.11"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@koishi-ce/client": "^1.0.0",
|
|
67
|
+
"@koishi-ce/plugin-console": "^1.0.0",
|
|
68
|
+
"@types/throttle-debounce": "^2.1.0",
|
|
69
|
+
"@koishi-ce/koishi": "^1.0.0",
|
|
70
|
+
"monaco-editor": "~0.56.0"
|
|
71
|
+
},
|
|
72
|
+
"dependencies": {
|
|
73
|
+
"@koishi-ce/console": "^1.0.0",
|
|
74
|
+
"anymatch": "^3.1.3",
|
|
75
|
+
"chardet": "^2.2.0",
|
|
76
|
+
"chokidar": "^5.0.0",
|
|
77
|
+
"file-type": "^22.0.2"
|
|
78
|
+
}
|
|
79
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* explorer 插件(服务端):网页文件管理器的 node 侧实现。
|
|
3
|
+
*
|
|
4
|
+
* 以 DataService 形式向控制台客户端推送根目录的完整文件树(Entry[]),
|
|
5
|
+
* 并注册 explorer/read、write、mkdir、remove、rename、refresh 六个
|
|
6
|
+
* RPC 事件(均要求 authority >= 4),供浏览器端执行实际的文件操作。
|
|
7
|
+
* 浏览器端对应实现在 ../client/(index.vue 文件树 + monaco 编辑器)。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
mkdir,
|
|
12
|
+
readdir,
|
|
13
|
+
readFile,
|
|
14
|
+
readlink,
|
|
15
|
+
rename,
|
|
16
|
+
rm,
|
|
17
|
+
writeFile,
|
|
18
|
+
} from "node:fs/promises";
|
|
19
|
+
import { join, relative, resolve } from "node:path";
|
|
20
|
+
import { DataService } from "@koishi-ce/console";
|
|
21
|
+
import { type Context, type Dict, Schema } from "@koishi-ce/koishi";
|
|
22
|
+
import type { Tester } from "anymatch";
|
|
23
|
+
import * as anymatchModule from "anymatch";
|
|
24
|
+
|
|
25
|
+
// anymatch 的 d.ts 为 ESM 形态而实现为 CJS,nodenext 互操作视图会给 default 多包一层;
|
|
26
|
+
// 运行时 namespace.default 即真实的 matchers => Tester 函数(module.exports),断言穿透取用
|
|
27
|
+
const anymatch =
|
|
28
|
+
anymatchModule.default as unknown as typeof anymatchModule.default.default;
|
|
29
|
+
|
|
30
|
+
import { detect } from "chardet";
|
|
31
|
+
import type { FSWatcher } from "chokidar";
|
|
32
|
+
import { fileTypeFromBuffer } from "file-type";
|
|
33
|
+
import zhCN from "../locales/zh-CN.yml";
|
|
34
|
+
|
|
35
|
+
declare module "@koishi-ce/console" {
|
|
36
|
+
namespace Console {
|
|
37
|
+
interface Services {
|
|
38
|
+
explorer: Explorer;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface Events {
|
|
43
|
+
"explorer/read"(filename: string, binary?: boolean): Promise<File>;
|
|
44
|
+
"explorer/write"(
|
|
45
|
+
filename: string,
|
|
46
|
+
content: string,
|
|
47
|
+
binary?: boolean,
|
|
48
|
+
): Promise<void>;
|
|
49
|
+
"explorer/mkdir"(filename: string): Promise<void>;
|
|
50
|
+
"explorer/remove"(filename: string): Promise<void>;
|
|
51
|
+
"explorer/rename"(oldValue: string, newValue: string): Promise<void>;
|
|
52
|
+
"explorer/refresh"(): void;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** explorer/read 事件返回给客户端的文件内容:base64 编码 + 探测出的元信息。 */
|
|
57
|
+
export interface File {
|
|
58
|
+
/** 文件内容的 base64 编码(客户端用 Binary.fromBase64 解码) */
|
|
59
|
+
base64: string;
|
|
60
|
+
/** 由 file-type 从文件头字节探测出的 MIME 类型,识别为文本时不存在 */
|
|
61
|
+
mime?: string;
|
|
62
|
+
/** 由 chardet 探测出的文本编码(如 UTF-8) */
|
|
63
|
+
encoding?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** 文件树节点:文件 / 目录 / 符号链接三类,由 traverse() 递归生成。 */
|
|
67
|
+
export interface Entry {
|
|
68
|
+
type: "file" | "directory" | "symlink";
|
|
69
|
+
/** 显示名(不含路径) */
|
|
70
|
+
name: string;
|
|
71
|
+
/** 打开文件后由客户端补充的 MIME 类型(决定预览方式) */
|
|
72
|
+
mime?: string;
|
|
73
|
+
/** 符号链接指向的目标路径 */
|
|
74
|
+
target?: string;
|
|
75
|
+
/** 客户端补全的完整相对路径(以 / 开头,由各层目录名拼接) */
|
|
76
|
+
filename?: string;
|
|
77
|
+
/** 子节点列表(仅目录节点存在) */
|
|
78
|
+
children?: this[];
|
|
79
|
+
/** 上次保存的内容(客户端记录,用于判断是否有未保存修改) */
|
|
80
|
+
oldValue?: string;
|
|
81
|
+
/** 当前内容(编辑器实时值,保存后与 oldValue 对齐) */
|
|
82
|
+
newValue?: string;
|
|
83
|
+
/** 正在进行的读取请求(客户端用于展示加载动画) */
|
|
84
|
+
loading?: Promise<File>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* explorer 数据服务:向客户端广播根目录的文件树。
|
|
89
|
+
*
|
|
90
|
+
* 继承 DataService,get() 的结果经 console 数据通道以 "explorer" 键下发,
|
|
91
|
+
* 客户端通过 store.explorer 读取。配置项见下方 namespace Explorer 的
|
|
92
|
+
* Config(root 相对 ctx.baseDir 解析;ignored 为 anymatch 通配列表)。
|
|
93
|
+
*/
|
|
94
|
+
class Explorer extends DataService<Entry[]> {
|
|
95
|
+
// 配置 schema 的值侧由类静态承载(erasableSyntaxOnly 不允许 namespace 内运行时值),
|
|
96
|
+
// 类型侧见下方 namespace Explorer 的 Config
|
|
97
|
+
static Config: Schema<Explorer.Config> = Schema.object({
|
|
98
|
+
root: Schema.string().default(""),
|
|
99
|
+
ignored: Schema.array(String)
|
|
100
|
+
.role("table")
|
|
101
|
+
.default(["**/node_modules", "**/.*", "cache"]),
|
|
102
|
+
}).i18n({
|
|
103
|
+
"zh-CN": zhCN,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
task!: Promise<Entry[]>;
|
|
107
|
+
/** 已创建的文件监视器集合(键为路径),stop() 时统一关闭 */
|
|
108
|
+
watchers: Dict<FSWatcher> = Object.create(null);
|
|
109
|
+
/** 由 ignored 配置编译出的 anymatch 过滤器 */
|
|
110
|
+
globFilter: Tester;
|
|
111
|
+
/** 文件树的根目录(ctx.baseDir + 配置的 root 解析出的绝对路径) */
|
|
112
|
+
root: string;
|
|
113
|
+
|
|
114
|
+
constructor(ctx: Context, config: Explorer.Config) {
|
|
115
|
+
super(ctx, "explorer", { authority: 4 });
|
|
116
|
+
|
|
117
|
+
ctx.console.addEntry(
|
|
118
|
+
process.env["KOISHI_BASE"]
|
|
119
|
+
? [
|
|
120
|
+
`${process.env["KOISHI_BASE"]}/dist/index.js`,
|
|
121
|
+
`${process.env["KOISHI_BASE"]}/dist/style.css`,
|
|
122
|
+
]
|
|
123
|
+
: process.env["KOISHI_ENV"] === "browser"
|
|
124
|
+
? [import.meta.url.replace(/\/src\/[^/]+$/, "/client/index.ts")]
|
|
125
|
+
: {
|
|
126
|
+
dev: resolve(__dirname, "../client/index.ts"),
|
|
127
|
+
prod: resolve(__dirname, "../dist"),
|
|
128
|
+
},
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
this.globFilter = anymatch(config.ignored ?? []);
|
|
132
|
+
this.root = resolve(ctx.baseDir, config.root ?? "");
|
|
133
|
+
|
|
134
|
+
// 以下六个监听器是浏览器端发出的文件操作 RPC:
|
|
135
|
+
// 客户端传入的 filename 均为相对 root 的路径,写操作完成后
|
|
136
|
+
// 调用 this.refresh() 让文件树重新下发
|
|
137
|
+
|
|
138
|
+
// 读取文件内容(base64)并附带探测出的 MIME 类型与文本编码
|
|
139
|
+
ctx.console.addListener(
|
|
140
|
+
"explorer/read",
|
|
141
|
+
async (filename) => {
|
|
142
|
+
filename = join(this.root, filename);
|
|
143
|
+
const buffer = await readFile(filename);
|
|
144
|
+
const result = await fileTypeFromBuffer(buffer);
|
|
145
|
+
const encoding = detect(buffer);
|
|
146
|
+
// exactOptionalPropertyTypes:探测失败时不上键,与原先携带 undefined
|
|
147
|
+
// 值的对象在 JSON 序列化后表现一致
|
|
148
|
+
const file: File = { base64: buffer.toString("base64") };
|
|
149
|
+
if (result) file.mime = result.mime;
|
|
150
|
+
if (encoding) file.encoding = encoding;
|
|
151
|
+
return file;
|
|
152
|
+
},
|
|
153
|
+
{ authority: 4 },
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
// 写入文件:binary 为 true 时 content 为 base64(上传场景),
|
|
157
|
+
// 否则视为 utf8 文本(编辑器保存)
|
|
158
|
+
ctx.console.addListener(
|
|
159
|
+
"explorer/write",
|
|
160
|
+
async (filename, content, binary) => {
|
|
161
|
+
filename = join(this.root, filename);
|
|
162
|
+
if (binary) {
|
|
163
|
+
const buffer = Buffer.from(content, "base64");
|
|
164
|
+
await writeFile(filename, buffer);
|
|
165
|
+
} else {
|
|
166
|
+
await writeFile(filename, content, "utf8");
|
|
167
|
+
}
|
|
168
|
+
this.refresh();
|
|
169
|
+
},
|
|
170
|
+
{ authority: 4 },
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
ctx.console.addListener(
|
|
174
|
+
"explorer/mkdir",
|
|
175
|
+
async (filename) => {
|
|
176
|
+
filename = join(this.root, filename);
|
|
177
|
+
await mkdir(filename);
|
|
178
|
+
this.refresh();
|
|
179
|
+
},
|
|
180
|
+
{ authority: 4 },
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
ctx.console.addListener(
|
|
184
|
+
"explorer/remove",
|
|
185
|
+
async (filename) => {
|
|
186
|
+
filename = join(this.root, filename);
|
|
187
|
+
await rm(filename, { recursive: true });
|
|
188
|
+
this.refresh();
|
|
189
|
+
},
|
|
190
|
+
{ authority: 4 },
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
ctx.console.addListener(
|
|
194
|
+
"explorer/rename",
|
|
195
|
+
async (oldValue, newValue) => {
|
|
196
|
+
oldValue = join(this.root, oldValue);
|
|
197
|
+
newValue = join(this.root, newValue);
|
|
198
|
+
await rename(oldValue, newValue);
|
|
199
|
+
this.refresh();
|
|
200
|
+
},
|
|
201
|
+
{ authority: 4 },
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
ctx.console.addListener(
|
|
205
|
+
"explorer/refresh",
|
|
206
|
+
() => {
|
|
207
|
+
this.refresh();
|
|
208
|
+
},
|
|
209
|
+
{ authority: 4 },
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
override stop() {
|
|
214
|
+
// 插件停用:关闭所有已创建的文件监视器
|
|
215
|
+
for (const watcher of Object.values(this.watchers)) {
|
|
216
|
+
watcher.close();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* 递归遍历目录,生成排序后的文件树。
|
|
222
|
+
* 排序规则:目录排在最前,其余按名称字母序;被 globFilter
|
|
223
|
+
* 命中的路径(node_modules、隐藏文件等)直接跳过。
|
|
224
|
+
*/
|
|
225
|
+
private async traverse(root: string): Promise<Entry[]> {
|
|
226
|
+
const dirents = await readdir(root, { withFileTypes: true });
|
|
227
|
+
return Promise.all(
|
|
228
|
+
dirents.map(async (dirent): Promise<Entry | undefined> => {
|
|
229
|
+
const filename = join(root, dirent.name);
|
|
230
|
+
if (this.globFilter(relative(this.root, filename))) return;
|
|
231
|
+
if (dirent.isFile()) {
|
|
232
|
+
return { type: "file", name: dirent.name };
|
|
233
|
+
} else if (dirent.isDirectory()) {
|
|
234
|
+
return {
|
|
235
|
+
type: "directory",
|
|
236
|
+
name: dirent.name,
|
|
237
|
+
children: await this.traverse(filename),
|
|
238
|
+
};
|
|
239
|
+
} else if (dirent.isSymbolicLink()) {
|
|
240
|
+
return {
|
|
241
|
+
type: "symlink",
|
|
242
|
+
name: dirent.name,
|
|
243
|
+
target: await readlink(filename),
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
// 其余类型(FIFO / socket 等)不展示,显式返回以通过 noImplicitReturns
|
|
247
|
+
return;
|
|
248
|
+
}),
|
|
249
|
+
).then((entries) =>
|
|
250
|
+
entries
|
|
251
|
+
.filter((entry): entry is Entry => !!entry)
|
|
252
|
+
.sort((a, b) => {
|
|
253
|
+
if (a.type !== b.type) return a.type === "directory" ? -1 : 1;
|
|
254
|
+
return a.name.localeCompare(b.name);
|
|
255
|
+
}),
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** 实际执行遍历(供 get() 缓存层调用)。 */
|
|
260
|
+
private async _get() {
|
|
261
|
+
return this.traverse(this.root);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* 获取文件树。
|
|
266
|
+
* @param forced 为 true 时强制重新遍历;否则复用进行中的 Promise,
|
|
267
|
+
* 避免并发请求触发重复遍历
|
|
268
|
+
*/
|
|
269
|
+
override async get(forced = false) {
|
|
270
|
+
if (!forced && this.task) return this.task;
|
|
271
|
+
return (this.task = this._get());
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
namespace Explorer {
|
|
276
|
+
/** 插件配置(见类静态 Config 的 Schema 定义)。 */
|
|
277
|
+
export interface Config {
|
|
278
|
+
root?: string;
|
|
279
|
+
ignored?: string[];
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export default Explorer;
|