servcraft 0.2.0 → 0.4.2
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/.github/workflows/ci.yml +9 -4
- package/README.md +70 -2
- package/ROADMAP.md +124 -47
- package/dist/cli/index.cjs +1331 -407
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +1298 -389
- package/dist/cli/index.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/commands/completion.ts +146 -0
- package/src/cli/commands/doctor.ts +116 -1
- package/src/cli/commands/generate.ts +52 -7
- package/src/cli/commands/list.ts +1 -1
- package/src/cli/commands/scaffold.ts +211 -0
- package/src/cli/commands/templates.ts +147 -0
- package/src/cli/commands/update.ts +221 -0
- package/src/cli/index.ts +16 -0
- package/src/cli/templates/controller-test.ts +110 -0
- package/src/cli/templates/integration-test.ts +139 -0
- package/src/cli/templates/service-test.ts +100 -0
- package/src/cli/utils/template-loader.ts +80 -0
- package/tests/cli/add.test.ts +32 -0
- package/tests/cli/completion.test.ts +35 -0
- package/tests/cli/doctor.test.ts +23 -0
- package/tests/cli/dry-run.test.ts +39 -0
- package/tests/cli/errors.test.ts +29 -0
- package/tests/cli/generate.test.ts +39 -0
- package/tests/cli/init.test.ts +63 -0
- package/tests/cli/list.test.ts +25 -0
- package/tests/cli/remove.test.ts +28 -0
- package/tests/cli/update.test.ts +34 -0
package/.github/workflows/ci.yml
CHANGED
|
@@ -82,10 +82,15 @@ jobs:
|
|
|
82
82
|
retention-days: 7
|
|
83
83
|
|
|
84
84
|
test:
|
|
85
|
-
name: Tests
|
|
85
|
+
name: Tests (Node ${{ matrix.node-version }})
|
|
86
86
|
runs-on: ubuntu-latest
|
|
87
87
|
needs: [lint, typecheck]
|
|
88
88
|
|
|
89
|
+
strategy:
|
|
90
|
+
matrix:
|
|
91
|
+
node-version: [18, 20, 22]
|
|
92
|
+
fail-fast: false
|
|
93
|
+
|
|
89
94
|
services:
|
|
90
95
|
postgres:
|
|
91
96
|
image: postgres:16-alpine
|
|
@@ -124,7 +129,7 @@ jobs:
|
|
|
124
129
|
- name: Setup Node.js
|
|
125
130
|
uses: actions/setup-node@v4
|
|
126
131
|
with:
|
|
127
|
-
node-version: ${{
|
|
132
|
+
node-version: ${{ matrix.node-version }}
|
|
128
133
|
cache: 'npm'
|
|
129
134
|
|
|
130
135
|
- name: Install dependencies
|
|
@@ -145,9 +150,9 @@ jobs:
|
|
|
145
150
|
|
|
146
151
|
- name: Upload coverage report
|
|
147
152
|
uses: actions/upload-artifact@v4
|
|
148
|
-
if: github.event_name == 'pull_request'
|
|
153
|
+
if: github.event_name == 'pull_request' && matrix.node-version == 20
|
|
149
154
|
with:
|
|
150
|
-
name: coverage
|
|
155
|
+
name: coverage-node-${{ matrix.node-version }}
|
|
151
156
|
path: coverage/
|
|
152
157
|
retention-days: 7
|
|
153
158
|
|
package/README.md
CHANGED
|
@@ -277,10 +277,15 @@ servcraft init my-app --dry-run -y # Preview without creating
|
|
|
277
277
|
### Generate resources
|
|
278
278
|
|
|
279
279
|
```bash
|
|
280
|
+
# Scaffold complete CRUD resource (recommended)
|
|
281
|
+
servcraft scaffold product --fields "name:string price:number category:string?"
|
|
282
|
+
servcraft scaffold user --fields "name:string email:email age:number?" --validator zod
|
|
283
|
+
|
|
280
284
|
# Generate complete module
|
|
281
285
|
servcraft generate module product
|
|
282
|
-
servcraft g m product --prisma
|
|
283
|
-
servcraft g m product --
|
|
286
|
+
servcraft g m product --prisma # Include Prisma model
|
|
287
|
+
servcraft g m product --with-tests # Include test files (__tests__ directory)
|
|
288
|
+
servcraft g m product --dry-run # Preview files
|
|
284
289
|
|
|
285
290
|
# Generate individual files
|
|
286
291
|
servcraft generate controller user
|
|
@@ -312,6 +317,69 @@ servcraft list --json # Output as JSON
|
|
|
312
317
|
servcraft ls # Same as list
|
|
313
318
|
```
|
|
314
319
|
|
|
320
|
+
### Module Management
|
|
321
|
+
|
|
322
|
+
```bash
|
|
323
|
+
# Update modules
|
|
324
|
+
servcraft update # Update all installed modules
|
|
325
|
+
servcraft update auth # Update specific module
|
|
326
|
+
servcraft update --check # Check for updates without applying
|
|
327
|
+
servcraft update auth --yes # Skip confirmation
|
|
328
|
+
|
|
329
|
+
# Remove a module
|
|
330
|
+
servcraft remove auth # Interactive confirmation
|
|
331
|
+
servcraft rm auth --yes # Skip confirmation
|
|
332
|
+
servcraft remove auth --keep-env # Keep environment variables
|
|
333
|
+
|
|
334
|
+
# Diagnose project
|
|
335
|
+
servcraft doctor # Check configuration and dependencies
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### Custom Templates
|
|
339
|
+
|
|
340
|
+
Customize code generation templates for your project:
|
|
341
|
+
|
|
342
|
+
```bash
|
|
343
|
+
# Initialize custom templates directory
|
|
344
|
+
servcraft templates init # Creates .servcraft/templates/
|
|
345
|
+
|
|
346
|
+
# List available templates
|
|
347
|
+
servcraft templates list # Shows project, user, and built-in templates
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
**Template locations (priority order):**
|
|
351
|
+
1. Project: `.servcraft/templates/` - Project-specific templates
|
|
352
|
+
2. User: `~/.servcraft/templates/` - User-wide templates
|
|
353
|
+
3. Built-in: Default ServCraft templates
|
|
354
|
+
|
|
355
|
+
**Available template types:**
|
|
356
|
+
- controller.ts, service.ts, repository.ts
|
|
357
|
+
- types.ts, schemas.ts, routes.ts, module-index.ts
|
|
358
|
+
- controller-test.ts, service-test.ts, integration-test.ts
|
|
359
|
+
|
|
360
|
+
### Shell Auto-completion
|
|
361
|
+
|
|
362
|
+
Enable tab completion for servcraft commands in your shell:
|
|
363
|
+
|
|
364
|
+
```bash
|
|
365
|
+
# Bash - Add to ~/.bashrc or ~/.bash_profile
|
|
366
|
+
servcraft completion bash >> ~/.bashrc
|
|
367
|
+
source ~/.bashrc
|
|
368
|
+
|
|
369
|
+
# Zsh - Add to ~/.zshrc
|
|
370
|
+
servcraft completion zsh >> ~/.zshrc
|
|
371
|
+
source ~/.zshrc
|
|
372
|
+
|
|
373
|
+
# Or save to completion directory (Zsh)
|
|
374
|
+
servcraft completion zsh > ~/.zsh/completion/_servcraft
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
After enabling, you can use tab to autocomplete:
|
|
378
|
+
- Commands: `servcraft <TAB>`
|
|
379
|
+
- Subcommands: `servcraft generate <TAB>`
|
|
380
|
+
- Module names: `servcraft add <TAB>`
|
|
381
|
+
- Options and flags
|
|
382
|
+
|
|
315
383
|
### Add pre-built modules
|
|
316
384
|
|
|
317
385
|
```bash
|
package/ROADMAP.md
CHANGED
|
@@ -4,7 +4,12 @@ This document outlines the planned features and improvements for Servcraft.
|
|
|
4
4
|
|
|
5
5
|
## Version History
|
|
6
6
|
|
|
7
|
-
- **v0.2
|
|
7
|
+
- **v0.4.2** (Current) - Custom template loading in generate/scaffold - Phase 3 in progress 🚧
|
|
8
|
+
- **v0.4.1** - Custom templates management (init/list)
|
|
9
|
+
- **v0.4.0** - Scaffold command for complete CRUD generation
|
|
10
|
+
- **v0.3.1** - Test templates with --with-tests flag - Phase 2 complete ✅
|
|
11
|
+
- **v0.3.0** - Shell auto-completion, update command, comprehensive CLI tests (30 tests), CI/CD on Node.js 18/20/22
|
|
12
|
+
- **v0.2.0** - Better errors, remove, doctor, update (stub) - Phase 1 complete ✅
|
|
8
13
|
- **v0.1.9** - Added `--dry-run` option for all commands (init, add, generate)
|
|
9
14
|
- **v0.1.8** - Added `servcraft list` command
|
|
10
15
|
- **v0.1.7** - ESM/CommonJS module system choice
|
|
@@ -15,7 +20,17 @@ This document outlines the planned features and improvements for Servcraft.
|
|
|
15
20
|
|
|
16
21
|
---
|
|
17
22
|
|
|
18
|
-
## Phase 1: Core CLI Improvements (v0.2.x)
|
|
23
|
+
## Phase 1: Core CLI Improvements (v0.2.x) ✅ COMPLETE
|
|
24
|
+
|
|
25
|
+
**Achievements:**
|
|
26
|
+
- ✅ `servcraft list` - List available and installed modules
|
|
27
|
+
- ✅ `--dry-run` - Preview changes for init, add, generate commands
|
|
28
|
+
- ✅ Better error messages - Suggestions, colored output, docs links
|
|
29
|
+
- ✅ `servcraft remove` - Remove modules with confirmation
|
|
30
|
+
- ✅ `servcraft doctor` - Diagnose project configuration
|
|
31
|
+
- ⏳ `servcraft update` - Stub created for v0.2.1
|
|
32
|
+
|
|
33
|
+
---
|
|
19
34
|
|
|
20
35
|
### v0.2.0 - CLI Enhancements
|
|
21
36
|
|
|
@@ -49,89 +64,108 @@ servcraft generate service users --dry-run # ✅ Implemented
|
|
|
49
64
|
|
|
50
65
|
### v0.2.1 - Module Management
|
|
51
66
|
|
|
52
|
-
#### `servcraft remove <module>`
|
|
67
|
+
#### `servcraft remove <module>` ✅ Completed in v0.2.0
|
|
53
68
|
Remove an installed module.
|
|
54
69
|
```bash
|
|
55
70
|
servcraft remove auth
|
|
56
|
-
servcraft remove auth --
|
|
71
|
+
servcraft remove auth --yes # Skip confirmation
|
|
72
|
+
servcraft remove auth --keep-env # Keep environment variables
|
|
57
73
|
```
|
|
58
74
|
|
|
59
75
|
Features:
|
|
60
|
-
- Remove module files from `src/modules/`
|
|
61
|
-
-
|
|
62
|
-
-
|
|
63
|
-
-
|
|
76
|
+
- ✅ Remove module files from `src/modules/`
|
|
77
|
+
- ✅ Interactive confirmation
|
|
78
|
+
- ✅ Show cleanup instructions
|
|
79
|
+
- ✅ Alias: rm
|
|
64
80
|
|
|
65
|
-
#### `servcraft update [module]`
|
|
81
|
+
#### `servcraft update [module]` ✅ Completed in v0.3.0
|
|
66
82
|
Update modules to latest version.
|
|
67
83
|
```bash
|
|
68
84
|
servcraft update # Update all modules
|
|
69
85
|
servcraft update auth # Update specific module
|
|
70
86
|
servcraft update --check # Check for updates without applying
|
|
87
|
+
servcraft update --yes # Skip confirmation
|
|
71
88
|
```
|
|
72
89
|
|
|
90
|
+
Features:
|
|
91
|
+
- ✅ Update specific module or all installed modules
|
|
92
|
+
- ✅ Interactive confirmation before updating
|
|
93
|
+
- ✅ Check mode to see what would be updated
|
|
94
|
+
- ✅ Overwrites existing files with latest version
|
|
95
|
+
- ✅ Error handling and validation
|
|
96
|
+
|
|
97
|
+
Note: Version tracking will be added in a future release. Currently always installs latest version.
|
|
98
|
+
|
|
73
99
|
**Estimated complexity:** Medium
|
|
74
100
|
|
|
75
101
|
---
|
|
76
102
|
|
|
77
103
|
### v0.2.2 - Developer Experience
|
|
78
104
|
|
|
79
|
-
#### `servcraft doctor`
|
|
105
|
+
#### `servcraft doctor` ✅ Completed in v0.2.0
|
|
80
106
|
Diagnose project configuration issues.
|
|
81
107
|
```bash
|
|
82
108
|
servcraft doctor
|
|
83
109
|
```
|
|
84
110
|
|
|
85
111
|
Checks:
|
|
86
|
-
- Node.js version compatibility
|
|
87
|
-
-
|
|
88
|
-
-
|
|
89
|
-
-
|
|
90
|
-
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
#### Shell Auto-completion
|
|
112
|
+
- ✅ Node.js version compatibility
|
|
113
|
+
- ✅ package.json and Fastify
|
|
114
|
+
- ✅ Project directories (src, node_modules)
|
|
115
|
+
- ✅ Git repository
|
|
116
|
+
- ✅ .env file
|
|
117
|
+
|
|
118
|
+
#### Shell Auto-completion ✅ Completed in v0.3.0
|
|
94
119
|
```bash
|
|
95
120
|
servcraft completion bash >> ~/.bashrc
|
|
96
121
|
servcraft completion zsh >> ~/.zshrc
|
|
97
122
|
```
|
|
98
123
|
|
|
124
|
+
Features:
|
|
125
|
+
- ✅ Bash completion script with command and module suggestions
|
|
126
|
+
- ✅ Zsh completion script with descriptions
|
|
127
|
+
- ✅ Autocomplete for all commands, subcommands, and modules
|
|
128
|
+
- ✅ Support for aliases (g, m, c, s, etc.)
|
|
129
|
+
|
|
99
130
|
**Estimated complexity:** Medium
|
|
100
131
|
|
|
101
132
|
---
|
|
102
133
|
|
|
103
|
-
## Phase 2: Testing & Quality (v0.3.x)
|
|
134
|
+
## Phase 2: Testing & Quality (v0.3.x) 🚧 In Progress
|
|
104
135
|
|
|
105
136
|
### v0.3.0 - CLI Tests
|
|
106
137
|
|
|
107
138
|
#### Unit Tests for CLI Commands
|
|
108
|
-
- Test `
|
|
109
|
-
- Test `
|
|
110
|
-
- Test `
|
|
111
|
-
- Test `
|
|
112
|
-
- Test `
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
-
|
|
116
|
-
-
|
|
117
|
-
-
|
|
139
|
+
- ✅ Test `list` command (3 tests passing)
|
|
140
|
+
- ✅ Test `doctor` command (3 tests passing)
|
|
141
|
+
- ✅ Test `--dry-run` option (2 tests passing)
|
|
142
|
+
- ✅ Test `init` command with various options (4 tests: --js, --cjs, --esm, --dry-run)
|
|
143
|
+
- ✅ Test `generate` command variants (3 tests: controller, service, module)
|
|
144
|
+
- ✅ Test error handling (2 tests: invalid module, documentation links)
|
|
145
|
+
- ✅ Test `add` command for modules (3 tests: validation, error handling, help)
|
|
146
|
+
- ✅ Test `remove` command (3 tests: validation, help, alias)
|
|
147
|
+
- ✅ Test `update` command (3 tests: validation, check flag, help)
|
|
148
|
+
- ✅ Test `completion` command (4 tests: bash, zsh, error, help)
|
|
118
149
|
|
|
119
150
|
#### CI/CD Pipeline
|
|
120
|
-
- GitHub Actions
|
|
121
|
-
-
|
|
122
|
-
-
|
|
151
|
+
- ✅ GitHub Actions configured
|
|
152
|
+
- ✅ Tests run on Node.js 18, 20, 22 (matrix strategy)
|
|
153
|
+
- ✅ Coverage reporting configured
|
|
154
|
+
- ✅ PostgreSQL and Redis services for integration tests
|
|
155
|
+
- ✅ Lint, typecheck, build, test, security audit jobs
|
|
156
|
+
|
|
157
|
+
**Status:** 30 CLI tests added and passing ✅ (111 total tests including integration tests)
|
|
123
158
|
|
|
124
159
|
**Estimated complexity:** High
|
|
125
160
|
|
|
126
161
|
---
|
|
127
162
|
|
|
128
|
-
### v0.3.1 - Generated Project Tests
|
|
163
|
+
### v0.3.1 - Generated Project Tests ✅ Completed
|
|
129
164
|
|
|
130
165
|
#### Test Templates
|
|
131
166
|
Generate test files alongside modules:
|
|
132
167
|
```bash
|
|
133
168
|
servcraft generate module users --with-tests
|
|
134
|
-
servcraft add auth # Includes test files
|
|
135
169
|
```
|
|
136
170
|
|
|
137
171
|
Generated test structure:
|
|
@@ -146,34 +180,52 @@ src/modules/users/
|
|
|
146
180
|
│ └── users.integration.test.ts
|
|
147
181
|
```
|
|
148
182
|
|
|
183
|
+
Features:
|
|
184
|
+
- ✅ Controller test templates with Fastify injection
|
|
185
|
+
- ✅ Service test templates with unit test structure
|
|
186
|
+
- ✅ Integration test templates with full CRUD workflow
|
|
187
|
+
- ✅ --with-tests flag for generate module command
|
|
188
|
+
- ✅ Vitest test structure and assertions
|
|
189
|
+
- ✅ TODO comments for customization
|
|
190
|
+
|
|
149
191
|
**Estimated complexity:** Medium
|
|
150
192
|
|
|
151
193
|
---
|
|
152
194
|
|
|
153
195
|
## Phase 3: Advanced Features (v0.4.x)
|
|
154
196
|
|
|
155
|
-
### v0.4.0 - Scaffolding
|
|
197
|
+
### v0.4.0 - Scaffolding ✅ Completed
|
|
156
198
|
|
|
157
199
|
#### `servcraft scaffold <resource>`
|
|
158
200
|
Generate complete CRUD with single command.
|
|
159
201
|
```bash
|
|
160
|
-
servcraft scaffold product --fields "name:string price:number category:
|
|
202
|
+
servcraft scaffold product --fields "name:string price:number category:string?"
|
|
203
|
+
servcraft scaffold user --fields "name:string email:email age:number?" --validator zod
|
|
161
204
|
```
|
|
162
205
|
|
|
163
206
|
Generates:
|
|
164
|
-
- Prisma model
|
|
165
|
-
- Controller with CRUD endpoints
|
|
166
|
-
- Service with business logic
|
|
167
|
-
- Repository with data access
|
|
168
|
-
- Routes with validation
|
|
169
|
-
- Types/DTOs
|
|
170
|
-
-
|
|
207
|
+
- ✅ Prisma model (with proper types and indexes)
|
|
208
|
+
- ✅ Controller with CRUD endpoints
|
|
209
|
+
- ✅ Service with business logic
|
|
210
|
+
- ✅ Repository with data access
|
|
211
|
+
- ✅ Routes with validation
|
|
212
|
+
- ✅ Types/DTOs (interface, Create, Update, Filters)
|
|
213
|
+
- ✅ Schemas (Zod/Joi/Yup validators)
|
|
214
|
+
- ✅ Test files (controller, service, integration)
|
|
215
|
+
|
|
216
|
+
Features:
|
|
217
|
+
- Parses field definitions with types and modifiers
|
|
218
|
+
- Supports optional fields (?)
|
|
219
|
+
- Generates complete Prisma model ready to copy
|
|
220
|
+
- Includes all CRUD operations
|
|
221
|
+
- Automatically generates tests with --with-tests behavior
|
|
222
|
+
- Supports all validators (zod, joi, yup)
|
|
171
223
|
|
|
172
224
|
**Estimated complexity:** High
|
|
173
225
|
|
|
174
226
|
---
|
|
175
227
|
|
|
176
|
-
### v0.4.1 - Custom Templates
|
|
228
|
+
### v0.4.1 - Custom Templates ✅ Completed
|
|
177
229
|
|
|
178
230
|
#### Template System
|
|
179
231
|
Allow users to customize generated code.
|
|
@@ -181,10 +233,18 @@ Allow users to customize generated code.
|
|
|
181
233
|
```bash
|
|
182
234
|
servcraft templates init # Create .servcraft/templates/
|
|
183
235
|
servcraft templates list # List available templates
|
|
184
|
-
servcraft generate module --template custom-module
|
|
185
236
|
```
|
|
186
237
|
|
|
187
|
-
|
|
238
|
+
Features:
|
|
239
|
+
- ✅ `servcraft templates init` - Initialize custom template directory
|
|
240
|
+
- ✅ `servcraft templates list` - List project/user/built-in templates
|
|
241
|
+
- ✅ Project templates in `.servcraft/templates/`
|
|
242
|
+
- ✅ User templates in `~/.servcraft/templates/`
|
|
243
|
+
- ✅ Built-in template fallback
|
|
244
|
+
- ✅ Example template file created on init
|
|
245
|
+
- ✅ Support for all 10 template types
|
|
246
|
+
|
|
247
|
+
Template locations (priority order):
|
|
188
248
|
1. Project `.servcraft/templates/`
|
|
189
249
|
2. User `~/.servcraft/templates/`
|
|
190
250
|
3. Built-in defaults
|
|
@@ -193,7 +253,24 @@ Template locations:
|
|
|
193
253
|
|
|
194
254
|
---
|
|
195
255
|
|
|
196
|
-
### v0.4.2 -
|
|
256
|
+
### v0.4.2 - Template Loading ✅ Completed
|
|
257
|
+
|
|
258
|
+
#### Custom Template Loading
|
|
259
|
+
Automatically use custom templates in generate/scaffold commands.
|
|
260
|
+
|
|
261
|
+
Features:
|
|
262
|
+
- ✅ Template loader utility with priority-based loading
|
|
263
|
+
- ✅ `generate` command uses custom templates automatically
|
|
264
|
+
- ✅ `scaffold` command uses custom templates automatically
|
|
265
|
+
- ✅ Falls back to built-in templates when custom not found
|
|
266
|
+
- ✅ Supports all 10 template types seamlessly
|
|
267
|
+
- ✅ No additional flags needed - works out of the box
|
|
268
|
+
|
|
269
|
+
**Estimated complexity:** Medium
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
### v0.4.3 - Plugin System
|
|
197
274
|
|
|
198
275
|
#### Third-party Plugins
|
|
199
276
|
```bash
|