-
-
Notifications
You must be signed in to change notification settings - Fork 129
feat: add Node.js CLI for CodeGPT with npm support and installation script #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,5 +17,6 @@ coverage.txt | |
| dist | ||
| **/.DS_Store | ||
| bin | ||
| !cli/nodejs/bin/ | ||
| release | ||
| .codegpt.yaml | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| *.xz | ||
| *.tar.gz | ||
| *.zip | ||
| node_modules/ | ||
| .DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| const path = require('path'); | ||
| const { spawn } = require('child_process'); | ||
|
|
||
| const binaryPath = path.join(__dirname, 'codegpt-bin'); | ||
|
|
||
| const child = spawn(binaryPath, process.argv.slice(2), { | ||
| stdio: 'inherit', | ||
| windowsHide: true, | ||
| }); | ||
|
|
||
| child.on('exit', (code, signal) => { | ||
| if (signal) { | ||
| process.kill(process.pid, signal); | ||
| } else { | ||
| process.exit(code); | ||
| } | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const { execSync } = require('child_process'); | ||
|
|
||
| function getPlatform() { | ||
| const platform = process.platform; | ||
| const arch = process.arch; | ||
|
|
||
| let platformName; | ||
| let archName; | ||
| let armVersion = ''; | ||
|
|
||
| // Map platform | ||
| switch (platform) { | ||
| case 'darwin': | ||
| platformName = 'darwin'; | ||
| break; | ||
| case 'linux': | ||
| platformName = 'linux'; | ||
| break; | ||
| case 'win32': | ||
| platformName = 'windows'; | ||
| break; | ||
| case 'freebsd': | ||
| platformName = 'freebsd'; | ||
| break; | ||
| default: | ||
| throw new Error(`Unsupported platform: ${platform}`); | ||
| } | ||
|
|
||
| // Map architecture | ||
| switch (arch) { | ||
| case 'x64': | ||
| archName = 'amd64'; | ||
| break; | ||
| case 'arm': | ||
| archName = 'arm'; | ||
| // Try to detect ARM version | ||
| try { | ||
| if (platform === 'linux') { | ||
| const cpuinfo = fs.readFileSync('/proc/cpuinfo', 'utf8'); | ||
| if (cpuinfo.includes('ARMv7')) { | ||
| armVersion = '-7'; | ||
| } else if (cpuinfo.includes('ARMv6')) { | ||
| armVersion = '-6'; | ||
| } else { | ||
| armVersion = '-5'; | ||
| } | ||
| } | ||
| } catch (e) { | ||
| armVersion = '-7'; // Default to ARMv7 | ||
| } | ||
| break; | ||
| case 'arm64': | ||
| archName = 'arm64'; | ||
| break; | ||
| default: | ||
| throw new Error(`Unsupported architecture: ${arch}`); | ||
| } | ||
|
|
||
| return { platformName, archName, armVersion }; | ||
| } | ||
|
|
||
| function getVersion() { | ||
| const packageJson = require('./package.json'); | ||
| return packageJson.version; | ||
| } | ||
|
|
||
| function getBinaryName() { | ||
| const { platformName, archName, armVersion } = getPlatform(); | ||
| const version = getVersion(); | ||
| const ext = platformName === 'windows' ? '.exe' : ''; | ||
|
|
||
| return `CodeGPT-${version}-${platformName}-${archName}${armVersion}${ext}`; | ||
| } | ||
|
|
||
| function install() { | ||
| try { | ||
| const binaryName = getBinaryName(); | ||
| const binaryPath = path.join(__dirname, 'binaries', binaryName); | ||
| const targetPath = path.join(__dirname, 'bin', 'codegpt-bin'); | ||
|
|
||
| if (!fs.existsSync(binaryPath)) { | ||
| console.error(`Error: Binary not found for your platform: ${binaryName}`); | ||
| console.error('Supported platforms:'); | ||
| console.error(' - darwin (macOS): x64, arm64'); | ||
| console.error(' - linux: x64, arm, arm64'); | ||
| console.error(' - windows: x64'); | ||
| console.error(' - freebsd: x64'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| // Copy binary to bin directory | ||
| fs.copyFileSync(binaryPath, targetPath); | ||
|
|
||
| // Make it executable on Unix-like systems | ||
| if (process.platform !== 'win32') { | ||
| fs.chmodSync(targetPath, 0o755); | ||
| } | ||
|
|
||
| console.log(`✓ CodeGPT installed successfully for ${process.platform}-${process.arch}`); | ||
| } catch (error) { | ||
| console.error('Installation failed:', error.message); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| if (require.main === module) { | ||
| install(); | ||
| } | ||
|
|
||
| module.exports = { install }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.