MCPcopy
hub / github.com/anomalyco/opencode / plugin

Function plugin

packages/opencode/test/plugin/install.test.ts:58–103  ·  view source on GitHub ↗
(
  dir: string,
  kinds?: Array<"server" | "tui">,
  opts?: {
    server?: Record<string, unknown>
    tui?: Record<string, unknown>
  },
  themes?: string[],
)

Source from the content-addressed store, hash-verified

56}
57
58async function plugin(
59 dir: string,
60 kinds?: Array<"server" | "tui">,
61 opts?: {
62 server?: Record<string, unknown>
63 tui?: Record<string, unknown>
64 },
65 themes?: string[],
66) {
67 const p = path.join(dir, "plugin")
68 const server = kinds?.includes("server") ?? false
69 const tui = kinds?.includes("tui") ?? false
70 const exports: Record<string, unknown> = {}
71 if (server) {
72 exports["./server"] = opts?.server
73 ? {
74 import: "./server.js",
75 config: opts.server,
76 }
77 : "./server.js"
78 }
79 if (tui) {
80 exports["./tui"] = opts?.tui
81 ? {
82 import: "./tui.js",
83 config: opts.tui,
84 }
85 : "./tui.js"
86 }
87 await fs.mkdir(p, { recursive: true })
88 await Bun.write(
89 path.join(p, "package.json"),
90 JSON.stringify(
91 {
92 name: "acme",
93 version: "1.0.0",
94 ...(server ? { main: "./server.js" } : {}),
95 ...(Object.keys(exports).length ? { exports } : {}),
96 ...(themes?.length ? { "oc-themes": themes } : {}),
97 },
98 null,
99 2,
100 ),
101 )
102 return p
103}
104
105async function read(file: string) {
106 return Filesystem.readJson<{

Callers 3

install.test.tsFile · 0.70
AppFunction · 0.50
index.tsFile · 0.50

Calls 1

writeMethod · 0.80

Tested by

no test coverage detected