You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CLAUDE.md
+26Lines changed: 26 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,6 +70,32 @@ cli.ts (collects prompts)
70
70
-**New generator**: add `src/generators/node/<feature>.ts` + `.test.ts`, call from `nodeGenerator`
71
71
-**Modify generated scaffold**: edit template strings in the corresponding generator file
72
72
73
+
## Builder Pattern
74
+
75
+
The scaffold generator uses `NodeProjectBuilder` + `BuildStep` (`src/generators/node/projectBuilder.ts`) to compose features without scattering conditional logic across generators.
- Each feature is a private class implementing `BuildStep` (e.g. `OAuthStep`, `DatabaseStep`)
80
+
-`NodeProjectBuilder` queues steps and runs them in order via `.build()`
81
+
- Named methods like `.addOAuth()`, `.addDatabase()` push steps unconditionally
82
+
-`when(condition, fn)` adds steps conditionally at the call site in `index.ts` — never inside `execute()`
83
+
84
+
**Adding a new feature:**
85
+
1. Create a private `BuildStep` class in `projectBuilder.ts`
86
+
2. Add a named method to `NodeProjectBuilder`: `addMyFeature(): this { return this.addStep(new MyFeatureStep()); }`
87
+
3. Call it in `index.ts`, via `when()` if conditional:
88
+
```ts
89
+
.when(options.webhooks, b=>b.addWebhooks())
90
+
```
91
+
92
+
**Rule: never put conditional logic inside `execute()`** — use `when()` at the call site. Steps must be unconditional internally; the builder chain controls what runs.
93
+
94
+
**File content helpers:**
95
+
- Use `SourceFileBuilder` (`src/utils/sourceFileBuilder.ts`) for TypeScript files with conditional imports or blocks — handles deduplication and formatting automatically
96
+
- Use `RouterMountBuilder` (`src/utils/templates.ts`) to accumulate `app.use()` calls conditionally
97
+
- Use plain `dedent` for static content (YAML, JSON, `.env`, SQL)
0 commit comments