From 5b1340d228d4e4c412b1a982405bec02fb5a7bf6 Mon Sep 17 00:00:00 2001 From: Badri Narayanan S Date: Fri, 26 Dec 2025 00:17:12 +0530 Subject: [PATCH] feat: add npm package support with CLI entry point --- .github/workflows/publish.yml | 26 ++++++++ .npmignore | 21 +++++++ bin/cli.js | 109 ++++++++++++++++++++++++++++++++++ package.json | 20 ++++++- 4 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/publish.yml create mode 100644 .npmignore create mode 100755 bin/cli.js diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..045c844 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,26 @@ +name: Publish to npm + +on: + release: + types: [published] + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + registry-url: 'https://registry.npmjs.org' + + - name: Install dependencies + run: npm ci + + - name: Publish to npm + run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..7b7da16 --- /dev/null +++ b/.npmignore @@ -0,0 +1,21 @@ +# Exclude tests +tests/ + +# Exclude GitHub workflows +.github/ + +# Exclude documentation (except README) +CLAUDE.md +CHANGELOG.md +CONTRIBUTING.md +docs/ + +# Exclude dev files +.env* +.claude/ +.vscode/ +.idea/ + +# Exclude misc +*.log +.DS_Store diff --git a/bin/cli.js b/bin/cli.js new file mode 100755 index 0000000..8dade5f --- /dev/null +++ b/bin/cli.js @@ -0,0 +1,109 @@ +#!/usr/bin/env node + +import { fileURLToPath } from 'url'; +import { dirname, join } from 'path'; +import { readFileSync } from 'fs'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +// Read package.json for version +const packageJson = JSON.parse( + readFileSync(join(__dirname, '..', 'package.json'), 'utf-8') +); + +const args = process.argv.slice(2); +const command = args[0]; + +function showHelp() { + console.log(` +antigravity-proxy v${packageJson.version} + +Proxy server for using Antigravity's Claude models with Claude Code CLI. + +USAGE: + antigravity-proxy [options] + +COMMANDS: + start Start the proxy server (default port: 8080) + accounts Manage Google accounts (interactive) + accounts add Add a new Google account via OAuth + accounts list List all configured accounts + accounts remove Remove accounts interactively + accounts verify Verify account tokens are valid + accounts clear Remove all accounts + +OPTIONS: + --help, -h Show this help message + --version, -v Show version number + +ENVIRONMENT: + PORT Server port (default: 8080) + +EXAMPLES: + antigravity-proxy start + PORT=3000 antigravity-proxy start + antigravity-proxy accounts add + antigravity-proxy accounts list + +CONFIGURATION: + Claude Code CLI (~/.claude/settings.json): + { + "env": { + "ANTHROPIC_BASE_URL": "http://localhost:8080" + } + } +`); +} + +function showVersion() { + console.log(packageJson.version); +} + +async function main() { + // Handle flags + if (args.includes('--help') || args.includes('-h')) { + showHelp(); + process.exit(0); + } + + if (args.includes('--version') || args.includes('-v')) { + showVersion(); + process.exit(0); + } + + // Handle commands + switch (command) { + case 'start': + case undefined: + // Default to starting the server + await import('../src/index.js'); + break; + + case 'accounts': { + // Pass remaining args to accounts CLI + const subCommand = args[1] || 'add'; + process.argv = ['node', 'accounts-cli.js', subCommand, ...args.slice(2)]; + await import('../src/accounts-cli.js'); + break; + } + + case 'help': + showHelp(); + break; + + case 'version': + showVersion(); + break; + + default: + console.error(`Unknown command: ${command}`); + console.error('Run "antigravity-proxy --help" for usage information.'); + process.exit(1); + } +} + +main().catch((err) => { + console.error('Error:', err.message); + process.exit(1); +}); diff --git a/package.json b/package.json index a9b8417..c577824 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,13 @@ "description": "Proxy server to use Antigravity's Claude models with Claude Code CLI", "main": "src/index.js", "type": "module", + "bin": { + "antigravity-proxy": "bin/cli.js" + }, + "files": [ + "src", + "bin" + ], "scripts": { "start": "node src/index.js", "dev": "node --watch src/index.js", @@ -27,8 +34,19 @@ "proxy", "vertex-ai" ], - "author": "", + "author": "Badri Narayanan", "license": "MIT", + "repository": { + "type": "git", + "url": "git+https://github.com/badri-s2001/antigravity_claude_server.git" + }, + "homepage": "https://github.com/badri-s2001/antigravity_claude_server#readme", + "bugs": { + "url": "https://github.com/badri-s2001/antigravity_claude_server/issues" + }, + "engines": { + "node": ">=18.0.0" + }, "dependencies": { "cors": "^2.8.5", "express": "^4.18.2"