@chatcode/chatcode-cli-test 1.0.28 → 1.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +86 -0
- package/dist/cli.js +737 -737
- package/package.json +6 -6
package/bin/cli.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from 'node:child_process'
|
|
3
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
4
|
+
import { createRequire } from 'node:module'
|
|
5
|
+
import { dirname, join } from 'node:path'
|
|
6
|
+
import { fileURLToPath } from 'node:url'
|
|
7
|
+
|
|
8
|
+
const require = createRequire(import.meta.url)
|
|
9
|
+
const here = dirname(fileURLToPath(import.meta.url))
|
|
10
|
+
const root = join(here, '..')
|
|
11
|
+
const args = process.argv.slice(2)
|
|
12
|
+
const platformKey = `${process.platform}-${process.arch}`
|
|
13
|
+
const executableName = process.platform === 'win32' ? 'chatcode-cli.exe' : 'chatcode-cli'
|
|
14
|
+
const mainPackage = JSON.parse(
|
|
15
|
+
readFileSync(join(root, 'package.json'), 'utf8'),
|
|
16
|
+
)
|
|
17
|
+
const mainPackageName = mainPackage.name
|
|
18
|
+
|
|
19
|
+
function resolveOptionalBinary() {
|
|
20
|
+
if (process.env.CHATCODE_CLI_FORCE_NODE === '1') return null
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const packageName = `${mainPackageName}-${platformKey}`
|
|
24
|
+
const executablePath = require.resolve(`${packageName}/${executableName}`)
|
|
25
|
+
const nativePackage = JSON.parse(
|
|
26
|
+
readFileSync(join(dirname(executablePath), 'package.json'), 'utf8'),
|
|
27
|
+
)
|
|
28
|
+
const versionMatches = nativePackage.version === mainPackage.version
|
|
29
|
+
const formatMatches =
|
|
30
|
+
nativePackage.chatcodeNativePackageFormat ===
|
|
31
|
+
mainPackage.chatcodeNativePackageFormat
|
|
32
|
+
if (!versionMatches || !formatMatches) {
|
|
33
|
+
console.warn(
|
|
34
|
+
`Ignoring ${packageName}@${nativePackage.version}: expected version ${mainPackage.version} and native package format ${mainPackage.chatcodeNativePackageFormat}. Using the bundled Node build instead.`,
|
|
35
|
+
)
|
|
36
|
+
return null
|
|
37
|
+
}
|
|
38
|
+
return executablePath
|
|
39
|
+
} catch (_) {
|
|
40
|
+
return null
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function resolveLocalBinary() {
|
|
45
|
+
if (process.env.CHATCODE_CLI_FORCE_NODE === '1') return null
|
|
46
|
+
|
|
47
|
+
const localBinary = join(root, 'dist', 'native', platformKey, executableName)
|
|
48
|
+
return existsSync(localBinary) ? localBinary : null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function run(command, commandArgs) {
|
|
52
|
+
const result = spawnSync(command, commandArgs, {
|
|
53
|
+
stdio: 'inherit',
|
|
54
|
+
windowsHide: false,
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
if (result.error) return result.error
|
|
58
|
+
if (result.signal) {
|
|
59
|
+
process.kill(process.pid, result.signal)
|
|
60
|
+
process.exit(1)
|
|
61
|
+
}
|
|
62
|
+
process.exit(result.status ?? 1)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const nativeBinary = resolveLocalBinary() ?? resolveOptionalBinary()
|
|
66
|
+
if (nativeBinary) {
|
|
67
|
+
const error = run(nativeBinary, args)
|
|
68
|
+
if (error && error.code !== 'ENOENT') {
|
|
69
|
+
console.error(`Failed to run native ChatCode CLI binary: ${error.message}`)
|
|
70
|
+
process.exit(1)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const fallbackCli = join(root, 'dist', 'cli.js')
|
|
75
|
+
if (!existsSync(fallbackCli)) {
|
|
76
|
+
console.error(
|
|
77
|
+
`ChatCode CLI is not installed correctly: missing ${fallbackCli}`,
|
|
78
|
+
)
|
|
79
|
+
process.exit(1)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const error = run(process.execPath, [fallbackCli, ...args])
|
|
83
|
+
if (error) {
|
|
84
|
+
console.error(`Failed to run ChatCode CLI: ${error.message}`)
|
|
85
|
+
process.exit(1)
|
|
86
|
+
}
|