@spfn/cli 0.0.9 → 0.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +283 -0
- package/bin/spfn.js +10 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +829 -0
- package/dist/templates/.guide/api-routes.md +388 -0
- package/dist/templates/server/entities/README.md +131 -0
- package/dist/templates/server/routes/examples/contract.ts +101 -0
- package/dist/templates/server/routes/examples/index.ts +112 -0
- package/dist/templates/server/routes/health/contract.ts +13 -0
- package/dist/templates/server/routes/health/index.ts +23 -0
- package/dist/templates/server/routes/index/contract.ts +13 -0
- package/dist/templates/server/routes/index/index.ts +28 -0
- package/package.json +67 -47
- package/lib/index.js +0 -19
- package/lib/login.js +0 -206
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 INFLIKE Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
@@ -0,0 +1,283 @@
|
|
1
|
+
# @spfn/cli
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
```bash
|
6
|
+
npm install -g @spfn/cli
|
7
|
+
# or
|
8
|
+
pnpm add -g @spfn/cli
|
9
|
+
# or
|
10
|
+
yarn global add @spfn/cli
|
11
|
+
```
|
12
|
+
|
13
|
+
## Quick Start
|
14
|
+
|
15
|
+
```bash
|
16
|
+
# 1. Initialize SPFN in your Next.js project
|
17
|
+
cd your-nextjs-project
|
18
|
+
spfn init
|
19
|
+
|
20
|
+
# 2. Start development server
|
21
|
+
npm run spfn:dev
|
22
|
+
# or: spfn dev
|
23
|
+
```
|
24
|
+
|
25
|
+
Visit:
|
26
|
+
- Next.js app: http://localhost:3790
|
27
|
+
- API health: http://localhost:8790/health
|
28
|
+
- API examples: http://localhost:8790/examples
|
29
|
+
|
30
|
+
---
|
31
|
+
|
32
|
+
## Commands
|
33
|
+
|
34
|
+
### `spfn init`
|
35
|
+
|
36
|
+
Initialize SPFN in an existing Next.js project.
|
37
|
+
|
38
|
+
```bash
|
39
|
+
spfn init
|
40
|
+
```
|
41
|
+
|
42
|
+
**What it does:**
|
43
|
+
|
44
|
+
1. ✅ Installs dependencies (@spfn/core, hono, drizzle-orm, etc.)
|
45
|
+
2. ✅ Creates `src/server/` directory structure with:
|
46
|
+
- `routes/` - API routes with co-located contracts (contract.ts + index.ts)
|
47
|
+
- `entities/` - Drizzle ORM schemas
|
48
|
+
- `middlewares/` - Custom middleware functions
|
49
|
+
3. ✅ Adds SPFN-specific scripts to package.json (preserves your existing scripts)
|
50
|
+
4. ✅ Creates .env.local.example with default ports (3790/8790)
|
51
|
+
5. ✅ Copies .guide/ directory for Claude Code documentation
|
52
|
+
|
53
|
+
**Options:**
|
54
|
+
- `-y, --yes` - Skip all prompts
|
55
|
+
|
56
|
+
---
|
57
|
+
|
58
|
+
### `spfn dev`
|
59
|
+
|
60
|
+
Start development server (Next.js + SPFN automatically).
|
61
|
+
|
62
|
+
```bash
|
63
|
+
# Using npm script (recommended)
|
64
|
+
npm run spfn:dev
|
65
|
+
|
66
|
+
# Or use CLI directly
|
67
|
+
spfn dev
|
68
|
+
```
|
69
|
+
|
70
|
+
**Features:**
|
71
|
+
- 🔍 Auto-detects Next.js
|
72
|
+
- 🚀 Runs both Next.js (3790) + Hono (8790) servers
|
73
|
+
- 🔥 Hot reload for backend routes
|
74
|
+
- 📊 Colored output with process names
|
75
|
+
|
76
|
+
**Options:**
|
77
|
+
- `-p, --port <port>` - Server port (default: 8790)
|
78
|
+
- `-h, --host <host>` - Server host (default: localhost)
|
79
|
+
- `--server-only` - Run only Hono server (skip Next.js)
|
80
|
+
|
81
|
+
**Examples:**
|
82
|
+
```bash
|
83
|
+
npm run spfn:dev # Next.js (3790) + Hono (8790)
|
84
|
+
npm run spfn:server # Hono only (8790)
|
85
|
+
npm run spfn:next # Next.js only (3790)
|
86
|
+
|
87
|
+
spfn dev # Next.js (3790) + Hono (8790)
|
88
|
+
spfn dev --server-only # Hono only (8790)
|
89
|
+
spfn dev -p 5000 # Hono only with custom port
|
90
|
+
```
|
91
|
+
|
92
|
+
**Custom Ports:**
|
93
|
+
To customize ports, edit the generated scripts in `package.json`:
|
94
|
+
```json
|
95
|
+
{
|
96
|
+
"scripts": {
|
97
|
+
"spfn:dev": "spfn dev -p 9000", // Change Hono port
|
98
|
+
"spfn:next": "next dev --turbo --port 4000" // Change Next.js port
|
99
|
+
}
|
100
|
+
}
|
101
|
+
```
|
102
|
+
|
103
|
+
---
|
104
|
+
|
105
|
+
### `spfn generate` (alias: `spfn g`)
|
106
|
+
|
107
|
+
Generate CRUD routes and repository from a Drizzle entity.
|
108
|
+
|
109
|
+
```bash
|
110
|
+
# Generate from entity name
|
111
|
+
spfn generate users
|
112
|
+
|
113
|
+
# Generate from entity file path
|
114
|
+
spfn generate src/server/entities/users.ts
|
115
|
+
```
|
116
|
+
|
117
|
+
**What it generates:**
|
118
|
+
|
119
|
+
1. ✅ Repository (`src/server/repositories/users.repository.ts`)
|
120
|
+
- Extends BaseRepository with findById, create, update, delete, findPage
|
121
|
+
- Singleton instance pattern
|
122
|
+
- Includes documentation for inherited methods
|
123
|
+
|
124
|
+
2. ✅ Contract definitions (`src/server/routes/users/contract.ts`)
|
125
|
+
- Auto-generated TypeBox schemas from Drizzle entity using drizzle-typebox
|
126
|
+
- 5 contracts: list (GET /), create (POST /), get (GET /:id), update (PUT /:id), delete (DELETE /:id)
|
127
|
+
- Full type safety for params, query, body, and response
|
128
|
+
|
129
|
+
3. ✅ Collection routes (`src/server/routes/users/index.ts`)
|
130
|
+
- GET /users - List with pagination
|
131
|
+
- POST /users - Create new item
|
132
|
+
|
133
|
+
4. ✅ Item routes (`src/server/routes/users/[id]/index.ts`)
|
134
|
+
- GET /users/:id - Get by ID
|
135
|
+
- PUT /users/:id - Update item
|
136
|
+
- DELETE /users/:id - Delete item
|
137
|
+
|
138
|
+
**Options:**
|
139
|
+
|
140
|
+
- `-f, --force` - Overwrite existing files without confirmation
|
141
|
+
- `-i, --interactive` - Prompt before overwriting each file
|
142
|
+
- `--only <files>` - Only generate specific files (comma-separated: `contract`, `repository`, `routes`)
|
143
|
+
- `--dry-run` - Show what would be generated without creating files
|
144
|
+
|
145
|
+
**Examples:**
|
146
|
+
|
147
|
+
```bash
|
148
|
+
# Basic usage
|
149
|
+
spfn generate users
|
150
|
+
|
151
|
+
# Generate from entity file
|
152
|
+
spfn generate src/server/entities/products.ts
|
153
|
+
|
154
|
+
# Only generate repository and contract
|
155
|
+
spfn generate users --only repository,contract
|
156
|
+
|
157
|
+
# Preview without creating files
|
158
|
+
spfn generate users --dry-run
|
159
|
+
|
160
|
+
# Force overwrite existing files
|
161
|
+
spfn generate users --force
|
162
|
+
|
163
|
+
# Interactive mode - prompt for each file
|
164
|
+
spfn generate users --interactive
|
165
|
+
```
|
166
|
+
|
167
|
+
**Safety:**
|
168
|
+
|
169
|
+
By default, `spfn generate` will **refuse to overwrite existing files** to prevent accidental code loss. Use `--force` to overwrite or `--interactive` to review each file.
|
170
|
+
|
171
|
+
---
|
172
|
+
|
173
|
+
### `spfn start`
|
174
|
+
|
175
|
+
Start production Hono server.
|
176
|
+
|
177
|
+
```bash
|
178
|
+
# Using npm script (recommended)
|
179
|
+
npm run spfn:start
|
180
|
+
|
181
|
+
# Or use CLI directly
|
182
|
+
spfn start
|
183
|
+
```
|
184
|
+
|
185
|
+
**Options:**
|
186
|
+
- `-p, --port <port>` - Server port (default: 8790)
|
187
|
+
- `-h, --host <host>` - Server host (default: 0.0.0.0)
|
188
|
+
|
189
|
+
---
|
190
|
+
|
191
|
+
### Database Commands
|
192
|
+
|
193
|
+
SPFN provides convenient wrappers around Drizzle Kit for database management.
|
194
|
+
|
195
|
+
#### `spfn db generate` (alias: `spfn db g`)
|
196
|
+
|
197
|
+
Generate database migrations from schema changes.
|
198
|
+
|
199
|
+
```bash
|
200
|
+
spfn db generate
|
201
|
+
```
|
202
|
+
|
203
|
+
This analyzes your Drizzle entities and creates migration SQL files in `src/server/migrations/`.
|
204
|
+
|
205
|
+
#### `spfn db push`
|
206
|
+
|
207
|
+
Push schema changes directly to the database without creating migration files (useful for development).
|
208
|
+
|
209
|
+
```bash
|
210
|
+
spfn db push
|
211
|
+
```
|
212
|
+
|
213
|
+
⚠️ **Warning:** This modifies your database schema directly. Use migrations for production.
|
214
|
+
|
215
|
+
#### `spfn db migrate` (alias: `spfn db m`)
|
216
|
+
|
217
|
+
Run pending migrations against your database.
|
218
|
+
|
219
|
+
```bash
|
220
|
+
spfn db migrate
|
221
|
+
```
|
222
|
+
|
223
|
+
#### `spfn db studio`
|
224
|
+
|
225
|
+
Open Drizzle Studio - a visual database GUI for browsing and editing data.
|
226
|
+
|
227
|
+
```bash
|
228
|
+
spfn db studio
|
229
|
+
# Or with custom port
|
230
|
+
spfn db studio --port 5000
|
231
|
+
```
|
232
|
+
|
233
|
+
Default port: 4983
|
234
|
+
|
235
|
+
#### `spfn db check`
|
236
|
+
|
237
|
+
Check database connection and display connection info.
|
238
|
+
|
239
|
+
```bash
|
240
|
+
spfn db check
|
241
|
+
```
|
242
|
+
|
243
|
+
#### `spfn db drop`
|
244
|
+
|
245
|
+
Drop all database tables. ⚠️ **Dangerous!** This will delete all data.
|
246
|
+
|
247
|
+
```bash
|
248
|
+
spfn db drop
|
249
|
+
```
|
250
|
+
|
251
|
+
---
|
252
|
+
|
253
|
+
## Generated Scripts
|
254
|
+
|
255
|
+
After `spfn init`, these scripts are **added** to your package.json (existing scripts are preserved):
|
256
|
+
|
257
|
+
```json
|
258
|
+
{
|
259
|
+
"scripts": {
|
260
|
+
"spfn:dev": "spfn dev", // Next.js + Hono
|
261
|
+
"spfn:server": "spfn dev --server-only", // Hono only (8790)
|
262
|
+
"spfn:next": "next dev --turbo --port 3790", // Next.js only (3790)
|
263
|
+
"spfn:start": "spfn start" // Production Hono
|
264
|
+
}
|
265
|
+
}
|
266
|
+
```
|
267
|
+
|
268
|
+
**Note:** Your existing scripts like `dev`, `build`, `start` are **not modified**.
|
269
|
+
|
270
|
+
---
|
271
|
+
|
272
|
+
## Requirements
|
273
|
+
|
274
|
+
- Node.js >= 18
|
275
|
+
- Next.js 15+ with App Router
|
276
|
+
- src/ directory structure
|
277
|
+
- Turbopack recommended
|
278
|
+
|
279
|
+
---
|
280
|
+
|
281
|
+
## License
|
282
|
+
|
283
|
+
MIT
|
package/bin/spfn.js
ADDED
package/dist/index.d.ts
ADDED