-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.ts
More file actions
42 lines (35 loc) · 1.32 KB
/
plugin.ts
File metadata and controls
42 lines (35 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import type { Plugin } from "@opencode-ai/plugin";
import { mkdir, readdir, copyFile } from "node:fs/promises";
import path from "node:path";
const VERSION = "0.3.3";
async function copyDir(src: string, dest: string): Promise<void> {
await mkdir(dest, { recursive: true });
for (const entry of await readdir(src, { withFileTypes: true })) {
const s = path.join(src, entry.name);
const d = path.join(dest, entry.name);
entry.isDirectory() ? await copyDir(s, d) : await copyFile(s, d);
}
}
const plugin: Plugin = async ({ directory }) => ({
config: async (config) => {
const targetDir = path.join(directory, ".opencode");
const marker = path.join(targetDir, "skills", "intellisearch", ".version");
try {
if ((await Bun.file(marker).text()).trim() === VERSION) return;
} catch {
// not installed
}
const pkgDir = import.meta.dirname;
await copyDir(
path.join(pkgDir, "assets", "skills", "intellisearch"),
path.join(targetDir, "skills", "intellisearch"),
);
await mkdir(path.join(targetDir, "commands"), { recursive: true });
await copyFile(
path.join(pkgDir, "assets", "commands", "search-intelligently.md"),
path.join(targetDir, "commands", "search-intelligently.md"),
);
await Bun.write(marker, VERSION);
},
});
export default plugin;