Skip to content

Commit

Permalink
feat(explorer): add root config
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jul 18, 2023
1 parent ede5428 commit ef123f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
15 changes: 10 additions & 5 deletions plugins/explorer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { FSWatcher, watch } from 'chokidar'
import { detect } from 'chardet'
import FileType from 'file-type'
import anymatch, { Tester } from 'anymatch'
import zhCN from './locales/zh-CN.yml'

declare module '@koishijs/plugin-console' {
namespace Console {
Expand Down Expand Up @@ -62,13 +63,14 @@ class Explorer extends DataService<Entry[]> {

this.globFilter = anymatch(config.ignored)

this.watcher = watch(ctx.baseDir, {
cwd: ctx.baseDir,
const cwd = resolve(ctx.baseDir, config.root)
this.watcher = watch(cwd, {
cwd,
ignored: config.ignored,
})

ctx.console.addListener('explorer/read', async (filename, binary) => {
filename = join(ctx.baseDir, filename)
filename = join(cwd, filename)
const buffer = await readFile(filename)
const result = await FileType.fromBuffer(buffer)
return {
Expand Down Expand Up @@ -147,15 +149,18 @@ class Explorer extends DataService<Entry[]> {

namespace Explorer {
export interface Config {
root?: string
ignored?: string[]
}

export const Config: Schema<Config> = Schema.object({
root: Schema.string().default(''),
ignored: Schema
.array(String)
.role('table')
.default(['**/node_modules', '**/.*', 'data/accounts/*/data', 'cache'])
.description('要忽略的文件或目录。支持 [Glob Patterns](https://github.com/micromatch/micromatch) 语法。'),
.default(['**/node_modules', '**/.*', 'data/accounts/*/data', 'cache']),
}).i18n({
'zh-CN': zhCN,
})
}

Expand Down
3 changes: 3 additions & 0 deletions plugins/explorer/src/locales/zh-CN.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
root: 资源管理器的根目录,默认为当前工作路径。
ignored: 要忽略的文件或目录。支持 [Glob Patterns](https://github.com/micromatch/micromatch) 语法。

0 comments on commit ef123f0

Please sign in to comment.