Skip to content

Commit dc466f6

Browse files
committed
feat: add node wrapper script to execute platform-specific ccg binary
1 parent 6099011 commit dc466f6

3 files changed

Lines changed: 32 additions & 4 deletions

File tree

npm/bin/ccg.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env node
2+
3+
const { spawn } = require("child_process");
4+
const path = require("path");
5+
const fs = require("fs");
6+
7+
const isWindows = process.platform === "win32";
8+
const binName = isWindows ? "ccg-binary.exe" : "ccg-binary";
9+
const binPath = path.join(__dirname, binName);
10+
11+
if (!fs.existsSync(binPath)) {
12+
console.error("Error: ccg binary not found. Please try re-installing the package.");
13+
process.exit(1);
14+
}
15+
16+
const child = spawn(binPath, process.argv.slice(2), {
17+
stdio: "inherit",
18+
shell: false,
19+
});
20+
21+
child.on("error", (err) => {
22+
console.error(`Failed to start ccg binary: ${err.message}`);
23+
process.exit(1);
24+
});
25+
26+
child.on("exit", (code) => {
27+
process.exit(code || 0);
28+
});

npm/install.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ async function install() {
6969
const url = getDownloadUrl(binaryName);
7070
const binDir = path.join(__dirname, "bin");
7171
const isWindows = process.platform === "win32";
72-
const binPath = path.join(binDir, isWindows ? "ccg.exe" : "ccg");
72+
const binPath = path.join(binDir, isWindows ? "ccg-binary.exe" : "ccg-binary");
7373

7474
// Skip if binary already exists
7575
if (fs.existsSync(binPath)) {
76-
console.log(`ccg already installed at ${binPath}`);
76+
console.log(`ccg binary already installed at ${binPath}`);
7777
return;
7878
}
7979

@@ -105,7 +105,7 @@ async function install() {
105105
execSync(`tar xzf "${tarPath}" -C "${binDir}"`, { stdio: "ignore" });
106106
fs.unlinkSync(tarPath);
107107

108-
// Rename platform-specific binary to 'ccg' (e.g., ccg-darwin-arm64 -> ccg)
108+
// Rename platform-specific binary to 'ccg-binary'
109109
const extracted = path.join(binDir, binaryName);
110110
if (fs.existsSync(extracted) && extracted !== binPath) {
111111
fs.renameSync(extracted, binPath);

npm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"license": "MIT",
1919
"bin": {
20-
"ccg": "bin/ccg"
20+
"ccg": "bin/ccg.js"
2121
},
2222
"scripts": {
2323
"postinstall": "node install.js"

0 commit comments

Comments
 (0)