-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcodex-acp.ts
More file actions
64 lines (56 loc) · 1.91 KB
/
Copy pathcodex-acp.ts
File metadata and controls
64 lines (56 loc) · 1.91 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { chmodSync, copyFileSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"
import { createRequire } from "node:module"
import path from "node:path"
const require = createRequire(import.meta.url)
interface CodexAcpManifest {
version: string
}
export interface BundledCodexAcp {
entryPath: string
scriptPath: string
version: string
}
function codexAcpPackageRoot(): string {
return path.dirname(require.resolve("@agentclientprotocol/codex-acp/package.json"))
}
export function bundleCodexAcp(
destinationDirectory: string,
platform: NodeJS.Platform = process.platform,
): BundledCodexAcp {
const packageRoot = codexAcpPackageRoot()
const manifest = JSON.parse(readFileSync(path.join(packageRoot, "package.json"), "utf8")) as CodexAcpManifest
const sourceScript = path.join(packageRoot, "dist", "index.js")
const scriptPath = path.join(destinationDirectory, "codex-acp.js")
const entryPath = path.join(destinationDirectory, platform === "win32" ? "codex-acp.cmd" : "codex-acp")
mkdirSync(destinationDirectory, { recursive: true })
copyFileSync(sourceScript, scriptPath)
if (platform === "win32") {
writeFileSync(
entryPath,
[
"@echo off",
"if defined WANTA_NODE_RUNTIME goto wanta_node",
'node "%~dp0codex-acp.js" %*',
"exit /b %ERRORLEVEL%",
":wanta_node",
"set ELECTRON_RUN_AS_NODE=1",
'"%WANTA_NODE_RUNTIME%" "%~dp0codex-acp.js" %*',
"exit /b %ERRORLEVEL%",
"",
].join("\r\n"),
)
} else {
writeFileSync(
entryPath,
[
"#!/bin/sh",
'script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)',
"node_runtime=${WANTA_NODE_RUNTIME:-node}",
'ELECTRON_RUN_AS_NODE=1 exec "$node_runtime" "$script_dir/codex-acp.js" "$@"',
"",
].join("\n"),
)
chmodSync(entryPath, 0o755)
}
return { entryPath, scriptPath, version: manifest.version }
}