Skip to content

Commit 6099011

Browse files
committed
feat: update npm install script to handle Windows binary extraction and renaming
1 parent 667ff70 commit 6099011

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

npm/install.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const PLATFORMS = {
1515
"darwin-x64": "ccg-darwin-amd64",
1616
"linux-x64": "ccg-linux-amd64",
1717
"linux-arm64": "ccg-linux-arm64",
18-
"win32-x64": "ccg-windows-amd64",
18+
"win32-x64": "ccg-windows-amd64", // This is the zip name, the file inside is .exe
1919
};
2020

2121
function getPlatformKey() {
@@ -82,22 +82,30 @@ async function install() {
8282

8383
try {
8484
const data = await download(url);
85-
fs.mkdirSync(binDir, { recursive: true });
85+
if (!fs.existsSync(binDir)) {
86+
fs.mkdirSync(binDir, { recursive: true });
87+
}
8688

8789
if (isWindows) {
8890
// Write zip and extract
8991
const zipPath = path.join(binDir, "ccg.zip");
9092
fs.writeFileSync(zipPath, data);
9193
execSync(`powershell -Command "Expand-Archive -Path '${zipPath}' -DestinationPath '${binDir}' -Force"`, { stdio: "ignore" });
9294
fs.unlinkSync(zipPath);
95+
96+
// In Windows, the file inside ccg-windows-amd64.zip is ccg-windows-amd64.exe
97+
const extracted = path.join(binDir, `${binaryName}.exe`);
98+
if (fs.existsSync(extracted) && extracted !== binPath) {
99+
fs.renameSync(extracted, binPath);
100+
}
93101
} else {
94102
// Write tar.gz and extract
95103
const tarPath = path.join(binDir, "ccg.tar.gz");
96104
fs.writeFileSync(tarPath, data);
97105
execSync(`tar xzf "${tarPath}" -C "${binDir}"`, { stdio: "ignore" });
98106
fs.unlinkSync(tarPath);
99107

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

0 commit comments

Comments
 (0)