-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopencode-plugin.js
More file actions
36 lines (29 loc) · 1.16 KB
/
Copy pathopencode-plugin.js
File metadata and controls
36 lines (29 loc) · 1.16 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
import { existsSync, mkdirSync, readdirSync, copyFileSync } from "fs";
import { join, dirname } from "path";
import { fileURLToPath } from "url";
const __dirname = dirname(fileURLToPath(import.meta.url));
const SKILLS_SOURCE = join(__dirname, "skills");
function copySkills(sourceDir, targetBase) {
if (!existsSync(sourceDir)) return;
const targetDir = join(targetBase, ".opencode", "skills");
if (!existsSync(targetDir)) mkdirSync(targetDir, { recursive: true });
for (const entry of readdirSync(sourceDir, { withFileTypes: true })) {
if (!entry.isDirectory()) continue;
const src = join(sourceDir, entry.name, "SKILL.md");
const dstDir = join(targetDir, entry.name);
const dst = join(dstDir, "SKILL.md");
if (existsSync(src) && !existsSync(dst)) {
mkdirSync(dstDir, { recursive: true });
copyFileSync(src, dst);
}
}
}
export const WorkflowKitPlugin = async ({ directory }) => {
if (directory) copySkills(SKILLS_SOURCE, directory);
const home = process.env.HOME || process.env.USERPROFILE;
if (home) {
const globalTarget = join(home, ".config", "opencode");
copySkills(SKILLS_SOURCE, globalTarget);
}
return {};
};