feat(tui): discover project plugins
This commit is contained in:
parent
a2885d1662
commit
068c32df39
4 changed files with 61 additions and 1 deletions
|
|
@ -33,6 +33,7 @@ import { useToast } from "../ui/toast"
|
|||
import { useAttention } from "../context/attention"
|
||||
import { abbreviateHome } from "../util/path-format"
|
||||
import { builtins } from "./builtins"
|
||||
import { discoverTuiPlugins } from "./discovery"
|
||||
|
||||
export interface PackageResolver {
|
||||
readonly resolve: (spec: string) => Promise<string | undefined>
|
||||
|
|
@ -353,7 +354,7 @@ export function PluginProvider(props: ParentProps<{ packages: PackageResolver }>
|
|||
.filter(([, registration]) => registration.active)
|
||||
.map(([id]) => deactivate(id)),
|
||||
)
|
||||
const entries = config.data.plugins ?? []
|
||||
const entries = [...(await discoverTuiPlugins(paths.cwd)), ...(config.data.plugins ?? [])]
|
||||
batch(() => {
|
||||
setStore("registrations", reconcileStore({}))
|
||||
setStore("states", [])
|
||||
|
|
|
|||
16
packages/tui/src/plugin/discovery.ts
Normal file
16
packages/tui/src/plugin/discovery.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import { readdir } from "node:fs/promises"
|
||||
import path from "node:path"
|
||||
|
||||
const extensions = new Set([".cjs", ".cts", ".js", ".jsx", ".mjs", ".mts", ".ts", ".tsx"])
|
||||
|
||||
export async function discoverTuiPlugins(cwd: string) {
|
||||
const directory = path.join(cwd, ".opencode", "plugins", "tui")
|
||||
const entries = await readdir(directory, { withFileTypes: true }).catch((error: unknown) => {
|
||||
if (error && typeof error === "object" && Reflect.get(error, "code") === "ENOENT") return []
|
||||
return Promise.reject(error)
|
||||
})
|
||||
return entries
|
||||
.filter((entry) => (entry.isFile() || entry.isSymbolicLink()) && extensions.has(path.extname(entry.name)))
|
||||
.map((entry) => path.join(directory, entry.name))
|
||||
.sort()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue