@chatcode/chatcode-cli-test 1.0.8 → 1.0.10
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 +53 -42
- package/dist/cli.js +1408 -1408
- package/package.json +10 -8
- package/scripts/npm-preinstall.mjs +117 -0
package/bin/cli.js
CHANGED
|
@@ -1,59 +1,70 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Launcher shim (main package `bin`).
|
|
4
|
-
*
|
|
5
|
-
* Resolves the prebuilt native binary for the current platform from the
|
|
6
|
-
* matching optional dependency (`<mainPkgName>-<os>-<arch>`) and execs it.
|
|
7
|
-
* Those binaries are `bun build --compile` standalone executables, so the
|
|
8
|
-
* runtime is bun — which (unlike node) delivers mouse events on Windows, so
|
|
9
|
-
* fullscreen mouse works there.
|
|
10
|
-
*
|
|
11
|
-
* If no platform package is installed (unsupported platform, or
|
|
12
|
-
* optionalDependencies skipped), it falls back to the bundled node build
|
|
13
|
-
* (dist/cli.js). That works everywhere but, on Windows, has no fullscreen
|
|
14
|
-
* mouse — same limitation as before.
|
|
15
|
-
*/
|
|
16
2
|
import { spawnSync } from 'node:child_process'
|
|
17
|
-
import { createRequire } from 'node:module'
|
|
18
3
|
import { existsSync, readFileSync } from 'node:fs'
|
|
4
|
+
import { createRequire } from 'node:module'
|
|
19
5
|
import { dirname, join } from 'node:path'
|
|
20
|
-
import { fileURLToPath
|
|
6
|
+
import { fileURLToPath } from 'node:url'
|
|
21
7
|
|
|
22
8
|
const require = createRequire(import.meta.url)
|
|
23
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 mainPackageName = JSON.parse(
|
|
15
|
+
readFileSync(join(root, 'package.json'), 'utf8'),
|
|
16
|
+
).name
|
|
17
|
+
|
|
18
|
+
function resolveOptionalBinary() {
|
|
19
|
+
if (process.env.CHATCODE_CLI_FORCE_NODE === '1') return null
|
|
24
20
|
|
|
25
|
-
function resolveNativeBinary() {
|
|
26
|
-
const key = `${process.platform}-${process.arch}`
|
|
27
|
-
const exeName = process.platform === 'win32' ? 'chatcode-cli.exe' : 'chatcode-cli'
|
|
28
|
-
let mainName
|
|
29
21
|
try {
|
|
30
|
-
|
|
31
|
-
} catch {
|
|
22
|
+
return require.resolve(`${mainPackageName}-${platformKey}/${executableName}`)
|
|
23
|
+
} catch (_) {
|
|
32
24
|
return null
|
|
33
25
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function resolveLocalBinary() {
|
|
29
|
+
if (process.env.CHATCODE_CLI_FORCE_NODE === '1') return null
|
|
30
|
+
|
|
31
|
+
const localBinary = join(root, 'dist', 'native', platformKey, executableName)
|
|
32
|
+
return existsSync(localBinary) ? localBinary : null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function run(command, commandArgs) {
|
|
36
|
+
const result = spawnSync(command, commandArgs, {
|
|
37
|
+
stdio: 'inherit',
|
|
38
|
+
windowsHide: false,
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
if (result.error) return result.error
|
|
42
|
+
if (result.signal) {
|
|
43
|
+
process.kill(process.pid, result.signal)
|
|
44
|
+
process.exit(1)
|
|
43
45
|
}
|
|
46
|
+
process.exit(result.status ?? 1)
|
|
44
47
|
}
|
|
45
48
|
|
|
46
|
-
const
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (res.error) {
|
|
52
|
-
console.error(`Failed to launch native binary: ${res.error.message}`)
|
|
49
|
+
const nativeBinary = resolveLocalBinary() ?? resolveOptionalBinary()
|
|
50
|
+
if (nativeBinary) {
|
|
51
|
+
const error = run(nativeBinary, args)
|
|
52
|
+
if (error && error.code !== 'ENOENT') {
|
|
53
|
+
console.error(`Failed to run native ChatCode CLI binary: ${error.message}`)
|
|
53
54
|
process.exit(1)
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const fallbackCli = join(root, 'dist', 'cli.js')
|
|
59
|
+
if (!existsSync(fallbackCli)) {
|
|
60
|
+
console.error(
|
|
61
|
+
`ChatCode CLI is not installed correctly: missing ${fallbackCli}`,
|
|
62
|
+
)
|
|
63
|
+
process.exit(1)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const error = run(process.execPath, [fallbackCli, ...args])
|
|
67
|
+
if (error) {
|
|
68
|
+
console.error(`Failed to run ChatCode CLI: ${error.message}`)
|
|
69
|
+
process.exit(1)
|
|
59
70
|
}
|