* Create a wrapper script in config-home/chrome/ (typically ~/.ncode/chrome/) * that invokes the given command. This is necessary because Chrome's native * host manifest "path" field cannot contain arguments. * * @param command - The full command to execute (e.g., "/path/to/ncode --chrome-native
(command: string)
| 309 | * @returns The path to the wrapper script |
| 310 | */ |
| 311 | async function createWrapperScript(command: string): Promise<string> { |
| 312 | const platform = getPlatform() |
| 313 | const chromeDir = join(getClaudeConfigHomeDir(), 'chrome') |
| 314 | const wrapperPath = |
| 315 | platform === 'windows' |
| 316 | ? join(chromeDir, 'chrome-native-host.bat') |
| 317 | : join(chromeDir, 'chrome-native-host') |
| 318 | |
| 319 | const scriptContent = |
| 320 | platform === 'windows' |
| 321 | ? `@echo off |
| 322 | REM Chrome native host wrapper script |
| 323 | REM Generated by NCode - do not edit manually |
| 324 | ${command} |
| 325 | ` |
| 326 | : `#!/bin/sh |
| 327 | # Chrome native host wrapper script |
| 328 | # Generated by NCode - do not edit manually |
| 329 | exec ${command} |
| 330 | ` |
| 331 | |
| 332 | // Check if content matches to avoid unnecessary writes |
| 333 | const existingContent = await readFile(wrapperPath, 'utf-8').catch(() => null) |
| 334 | if (existingContent === scriptContent) { |
| 335 | return wrapperPath |
| 336 | } |
| 337 | |
| 338 | await mkdir(chromeDir, { recursive: true }) |
| 339 | await writeFile(wrapperPath, scriptContent) |
| 340 | |
| 341 | if (platform !== 'windows') { |
| 342 | await chmod(wrapperPath, 0o755) |
| 343 | } |
| 344 | |
| 345 | logForDebugging( |
| 346 | `[Code in Chrome] Created Chrome native host wrapper script: ${wrapperPath}`, |
| 347 | ) |
| 348 | return wrapperPath |
| 349 | } |
| 350 | |
| 351 | /** |
| 352 | * Get cached value of whether Chrome extension is installed. Returns |
no test coverage detected