(rootPath: string, hookUrl: string, token: string)
| 212 | } |
| 213 | |
| 214 | export function ensureOpencodeHookPlugin(rootPath: string, hookUrl: string, token: string): string { |
| 215 | const pluginDir = resolvePluginDir(rootPath); |
| 216 | mkdirSync(pluginDir, { recursive: true }); |
| 217 | ensurePluginRuntime(rootPath); |
| 218 | |
| 219 | const pluginPath = join(pluginDir, PLUGIN_FILENAME); |
| 220 | const nextSource = buildPluginSource(hookUrl, token); |
| 221 | |
| 222 | try { |
| 223 | const current = readFileSync(pluginPath, 'utf-8'); |
| 224 | if (current === nextSource) { |
| 225 | return pluginPath; |
| 226 | } |
| 227 | } catch { |
| 228 | // Ignore missing or unreadable file. |
| 229 | } |
| 230 | |
| 231 | writeFileSync(pluginPath, nextSource, 'utf-8'); |
| 232 | return pluginPath; |
| 233 | } |
no test coverage detected