Skip to content

Commit d9b9577

Browse files
authored
feat: cli for generating projects and migrating schema (#12)
1 parent 4b63c82 commit d9b9577

36 files changed

+9162
-6
lines changed

.github/workflows/cli-build.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: CLI Build
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths: ["cli/**"]
7+
pull_request:
8+
paths: ["cli/**"]
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: "22"
22+
23+
- name: Setup Bun
24+
uses: oven-sh/setup-bun@v2
25+
with:
26+
bun-version: latest
27+
28+
- name: Install dependencies
29+
working-directory: ./cli
30+
run: bun install
31+
32+
- name: Type check
33+
working-directory: ./cli
34+
run: bun run typecheck
35+
36+
- name: Build CLI
37+
working-directory: ./cli
38+
run: bun run build
39+
40+
- name: Check build artifacts
41+
working-directory: ./cli
42+
run: |
43+
ls -la dist/
44+
test -f dist/index.js

.github/workflows/cli-test.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: CLI Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths: ["cli/**"]
7+
pull_request:
8+
paths: ["cli/**"]
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: "22"
22+
23+
- name: Setup Bun
24+
uses: oven-sh/setup-bun@v2
25+
with:
26+
bun-version: latest
27+
28+
- name: Install dependencies
29+
working-directory: ./cli
30+
run: bun install
31+
32+
- name: Run tests
33+
working-directory: ./cli
34+
run: bun test
35+
36+
- name: Type check
37+
working-directory: ./cli
38+
run: bun run typecheck

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
.env.local
44
node_modules
55
dist
6-
pnpm-lock.yaml
6+
pnpm-lock.yaml
7+
bun.lock
8+
*.log

README.md

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Seamlessly integrate [Better Auth](https://github.com/better-auth/better-auth) w
88

99
**LIVE DEMOS**:
1010

11-
- **OpenNextJS**: [https://better-auth-cloudflare.zpg6.workers.dev/](https://better-auth-cloudflare.zpg6.workers.dev/)
12-
- **Hono**: [https://better-auth-cloudflare-hono.zpg6.workers.dev/](https://better-auth-cloudflare-hono.zpg6.workers.dev/)
11+
- **OpenNextJS**: [https://better-auth-cloudflare.zpg6.workers.dev](https://better-auth-cloudflare.zpg6.workers.dev/)
12+
- **Hono**: [https://better-auth-cloudflare-hono.zpg6.workers.dev](https://better-auth-cloudflare-hono.zpg6.workers.dev/)
1313

1414
Demo implementations are available in the [`examples/`](./examples/) directory for **OpenNextJS ◆** and **Hono 🔥**, along with recommended scripts for generating database schema, migrating, and more. The library is compatible with any framework that runs on Cloudflare Workers.
1515

@@ -22,6 +22,7 @@ Demo implementations are available in the [`examples/`](./examples/) directory f
2222
- 📍 **Automatic Geolocation Tracking**: Enrich user sessions with location data derived from Cloudflare.
2323
- 🌐 **Cloudflare IP Detection**: Utilize Cloudflare's IP detection headers out-of-the-box.
2424
- 🔍 **Rich Client-Side Context**: Access timezone, city, country, region, and more via the client plugin.
25+
- 📦 **CLI**: Tools for getting started quickly with Hono or Next.js, managing database schema, and more.
2526

2627
## Roadmap
2728

@@ -34,6 +35,15 @@ Demo implementations are available in the [`examples/`](./examples/) directory f
3435
- [ ] Cloudflare Images
3536
- [ ] Durable Objects
3637

38+
**CLI:**
39+
40+
- [x] `generate` - Create new projects from Hono/Next.js templates with automatic Cloudflare resource setup
41+
- [ ] `integrate` - Add `better-auth-cloudflare` to existing projects, creating/updating auth and schema files
42+
- [x] `migrate` - Update auth schema and run database migrations when configuration changes
43+
- [ ] `plugin` - Generate empty Better Auth plugin for quickly adding typesafe endpoints and schema fields
44+
- [x] `version` - Check the version of the CLI
45+
- [x] `help` - Show all commands and their usage
46+
3747
**Examples:**
3848

3949
- [x] Hono
@@ -43,9 +53,10 @@ Demo implementations are available in the [`examples/`](./examples/) directory f
4353

4454
## Table of Contents
4555

46-
- [Installation](#installation)
56+
- [Quick Start with CLI](#quick-start-with-cli)
4757
- [Configuration Options](#configuration-options)
48-
- [Setup](#setup)
58+
- [Manual Installation](#manual-installation)
59+
- [Manual Setup](#manual-setup)
4960
- [1. Define Your Database Schema (`src/db/schema.ts`)](#1-define-your-database-schema-srcdbschemats)
5061
- [2. Initialize Drizzle ORM (`src/db/index.ts`)](#2-initialize-drizzle-orm-srcdbindexts)
5162
- [3. Configure Better Auth (`src/auth/index.ts`)](#3-configure-better-auth-srcauthindexts)
@@ -59,7 +70,39 @@ Demo implementations are available in the [`examples/`](./examples/) directory f
5970
- [License](#license)
6071
- [Contributing](#contributing)
6172

62-
## Installation
73+
## Quick Start with CLI
74+
75+
⚡️ For the fastest setup, use the CLI to generate a complete project (including the resources on Cloudflare):
76+
77+
**Interactive mode** (asks questions and provides helpful defaults):
78+
79+
```bash
80+
npx @better-auth-cloudflare/cli generate
81+
```
82+
83+
**Non-interactive mode** (use arguments):
84+
85+
```bash
86+
# Simple D1 app with KV (ready to run)
87+
npx @better-auth-cloudflare/cli generate \
88+
--app-name=my-auth-app \
89+
--template=hono \
90+
--database=d1 \
91+
--kv=true \
92+
--r2=false \
93+
--apply-migrations=dev
94+
```
95+
96+
**Migration workflow**:
97+
98+
```bash
99+
npx @better-auth-cloudflare/cli migrate # Interactive
100+
npx @better-auth-cloudflare/cli migrate --migrate-target=dev # Non-interactive
101+
```
102+
103+
The CLI creates projects from Hono or Next.js templates and can automatically set up D1, KV, R2, and Hyperdrive resources. See [CLI Documentation](./cli/README.md) for full documentation and all available arguments.
104+
105+
## Manual Installation
63106

64107
```bash
65108
npm install better-auth-cloudflare

cli/.npmignore

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Source files
2+
src/
3+
tests/
4+
*.test.ts
5+
*.test.js
6+
7+
# TypeScript config
8+
tsconfig.json
9+
tsconfig.*.json
10+
11+
# Build artifacts
12+
*.tsbuildinfo
13+
14+
# Development dependencies
15+
node_modules/
16+
17+
# Lock files
18+
package-lock.json
19+
yarn.lock
20+
bun.lockb
21+
bun.lock
22+
23+
# IDE and editor files
24+
.vscode/
25+
.idea/
26+
*.swp
27+
*.swo
28+
*~
29+
30+
# OS generated files
31+
.DS_Store
32+
.DS_Store?
33+
._*
34+
.Spotlight-V100
35+
.Trashes
36+
ehthumbs.db
37+
Thumbs.db
38+
39+
# Logs
40+
*.log
41+
npm-debug.log*
42+
yarn-debug.log*
43+
yarn-error.log*
44+
45+
# Runtime data
46+
pids
47+
*.pid
48+
*.seed
49+
*.pid.lock
50+
51+
# Coverage directory used by tools like istanbul
52+
coverage/
53+
54+
# nyc test coverage
55+
.nyc_output
56+
57+
# Dependency directories
58+
jspm_packages/
59+
60+
# Optional npm cache directory
61+
.npm
62+
63+
# Optional REPL history
64+
.node_repl_history
65+
66+
# Output of 'npm pack'
67+
*.tgz
68+
69+
# Yarn Integrity file
70+
.yarn-integrity
71+
72+
# dotenv environment variables file
73+
.env
74+
.env.test
75+
.env.production
76+
.env.local
77+
78+
# Temporary folders
79+
tmp/
80+
temp/
81+
82+
# Documentation that shouldn't be published
83+
docs/
84+
*.md
85+
!README.md

0 commit comments

Comments
 (0)