Skip to content

Commit 2683757

Browse files
committed
chore: add npm package
1 parent a137f04 commit 2683757

File tree

4 files changed

+89
-3
lines changed

4 files changed

+89
-3
lines changed

.github/workflows/npm-publish.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Publish to npm
2+
3+
on:
4+
push:
5+
branches:
6+
- main # Run when a push is made to the main branch
7+
8+
jobs:
9+
build-and-publish:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v4
17+
with:
18+
node-version: '22'
19+
registry-url: 'https://registry.npmjs.org/'
20+
scope: '@bytebase'
21+
22+
- name: Install pnpm
23+
uses: pnpm/action-setup@v3
24+
with:
25+
version: latest
26+
27+
- name: Install dependencies
28+
run: pnpm install
29+
30+
- name: Build
31+
run: pnpm run build
32+
33+
- name: Update package.json for npm publishing
34+
run: |
35+
# Get the current version from package.json
36+
CURRENT_VERSION=$(jq -r '.version' package.json)
37+
38+
# Generate a version with date and commit hash suffix
39+
COMMIT_HASH=$(git rev-parse --short HEAD)
40+
DATE_VERSION=$(date +'%Y%m%d')
41+
VERSION="${CURRENT_VERSION}-${DATE_VERSION}.${COMMIT_HASH}"
42+
43+
# Update package.json to use @bytebase scope and set version
44+
jq --arg version "$VERSION" '.name = "@bytebase/dbhub" | .version = $version' package.json > package.json.tmp
45+
mv package.json.tmp package.json
46+
47+
# Set files to include in the package
48+
jq '.files = ["dist/**/*", "LICENSE", "README.md"]' package.json > package.json.tmp
49+
mv package.json.tmp package.json
50+
51+
# Add bin entry for CLI usage
52+
jq '.bin = {"dbhub": "dist/index.js"}' package.json > package.json.tmp
53+
mv package.json.tmp package.json
54+
55+
- name: Publish to npm
56+
run: pnpm publish --no-git-checks --access public --tag dev
57+
env:
58+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ DBHub is a universal database gateway implementing the Model Context Protocol (M
3333
- Run read-only SQL queries against the database
3434
- Safety checks to prevent dangerous queries
3535

36-
## Usage
36+
## Installation
3737

3838
### Docker
3939

@@ -47,9 +47,27 @@ docker run --rm --init \
4747
--dsn "postgres://user:password@localhost:5432/dbname?sslmode=disable"
4848
```
4949

50+
### NPM
51+
52+
```bash
53+
# Install latest stable version globally
54+
npm install -g @bytebase/dbhub
55+
56+
# Or install development version
57+
npm install -g @bytebase/dbhub@dev
58+
59+
# Run from anywhere
60+
dbhub --dsn="postgres://user:password@localhost:5432/dbname"
61+
62+
# Run via npx
63+
npx @bytebase/dbhub --dsn="postgres://user:password@localhost:5432/dbname"
64+
```
65+
66+
## Usage
67+
5068
### Configure your database connection
5169

52-
DBHub requires a Database Source Name (DSN) to connect to your database. You can provide this in several ways:
70+
Database Source Name (DSN) is required to connect to your database. You can provide this in several ways:
5371

5472
- **Command line argument** (highest priority):
5573

@@ -87,7 +105,7 @@ DBHub requires a Database Source Name (DSN) to connect to your database. You can
87105
### Command line options
88106

89107
| Option | Description | Default |
90-
| --------- | --------------------------------------------------------------- | ----------------------------------- |
108+
| :-------- | :-------------------------------------------------------------- | :---------------------------------- |
91109
| dsn | Database connection string | Required if not set via environment |
92110
| transport | Transport mode: `stdio` or `sse` | `stdio` |
93111
| port | HTTP server port (only applicable when using `--transport=sse`) | `8080` |

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
"description": "Universal Database MCP Server",
55
"main": "dist/index.js",
66
"type": "module",
7+
"bin": {
8+
"dbhub": "dist/index.js"
9+
},
10+
"files": [
11+
"dist/**/*",
12+
"LICENSE",
13+
"README.md"
14+
],
715
"scripts": {
816
"build": "tsc",
917
"start": "node dist/index.js",

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env node
2+
13
// Import connector modules to register them
24
import './connectors/postgres/index.js'; // Register PostgreSQL connector
35
// import './connectors/sqlite/index.js'; // Uncomment to enable SQLite

0 commit comments

Comments
 (0)