Skip to content

Commit 3d5c79a

Browse files
committed
Make PLAN.md
1 parent 9435821 commit 3d5c79a

1 file changed

Lines changed: 128 additions & 0 deletions

File tree

packages/create-vite-app/PLAN.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Implementation Plan: @fastify/create-vite-app CLI
2+
3+
## Overview
4+
Build a CLI scaffolding tool that copies the `examples/react-vanilla-spa/` template and resolves pnpm catalog versions at build time.
5+
6+
## Requirements Summary
7+
- **Template source**: `examples/react-vanilla-spa/` (no dedicated templates folder)
8+
- **Prompts**: Project name only (using @clack/prompts)
9+
- **Versions**: Baked in at build time from `pnpm-workspace.yaml`
10+
- **Post-scaffold**: Auto-detect package manager and install dependencies
11+
- **Skip**: test files, node_modules, dist folders
12+
13+
---
14+
15+
## Implementation Steps
16+
17+
### Step 1: Add dependencies
18+
**File**: `packages/create-vite-app/package.json`
19+
20+
Add:
21+
- `@clack/prompts` - interactive CLI prompts
22+
- `yaml` (devDependency) - parse pnpm-workspace.yaml at build time
23+
24+
### Step 2: Create build script to generate versions
25+
**New file**: `packages/create-vite-app/scripts/generate-versions.ts`
26+
27+
This script will:
28+
1. Read `../../pnpm-workspace.yaml` for catalog versions
29+
2. Read `../fastify-vite/package.json` for @fastify/vite version (workspace:^ reference)
30+
3. Parse catalog and catalogs sections
31+
4. Write `src/versions.ts` with resolved versions:
32+
```ts
33+
export const versions = {
34+
'@fastify/vite': '^8.2.3',
35+
'fastify': '^5.6.2',
36+
'vite': '^7.3.0',
37+
'react': '^19.2.3',
38+
'react-dom': '^19.2.3',
39+
'@vitejs/plugin-react': '^5.1.2',
40+
}
41+
```
42+
43+
### Step 3: Update build script in package.json
44+
**File**: `packages/create-vite-app/package.json`
45+
46+
Change build to:
47+
```json
48+
"build": "node scripts/generate-versions.ts && tsc"
49+
```
50+
51+
(Uses Node 22.18+ native TypeScript support - no tsx needed)
52+
53+
### Step 4: Rewrite src/index.ts
54+
**File**: `packages/create-vite-app/src/index.ts`
55+
56+
Structure:
57+
```ts
58+
#!/usr/bin/env node
59+
import * as p from '@clack/prompts'
60+
import { versions } from './versions.js'
61+
// ... fs utilities
62+
63+
async function main() {
64+
p.intro('Create Fastify + Vite App')
65+
66+
// 1. Get project name (with CLI arg fallback)
67+
const projectName = await p.text({...})
68+
69+
// 2. Copy template files from examples/react-vanilla-spa
70+
// - Skip: node_modules, dist, *.test.js
71+
// - Transform package.json with resolved versions
72+
73+
// 3. Detect package manager (npm/pnpm/yarn/bun)
74+
// 4. Run install with spinner
75+
76+
p.outro('Done! Run: cd <project> && npm run dev')
77+
}
78+
```
79+
80+
### Step 5: Add template copying logic
81+
**File**: `packages/create-vite-app/src/index.ts`
82+
83+
Key functions:
84+
- `copyTemplate(source, dest)` - recursively copy, skip ignored files
85+
- `transformPackageJson(content, projectName, versions)` - replace workspace:/catalog: refs
86+
- `detectPackageManager()` - check lockfiles or npm_config_user_agent
87+
- `installDependencies(pm, cwd)` - spawn install process
88+
89+
---
90+
91+
## Files to Modify/Create
92+
93+
| File | Action |
94+
|------|--------|
95+
| `packages/create-vite-app/package.json` | Modify - add deps, update build script |
96+
| `packages/create-vite-app/scripts/generate-versions.ts` | Create |
97+
| `packages/create-vite-app/src/versions.ts` | Generated (gitignored) |
98+
| `packages/create-vite-app/src/index.ts` | Rewrite |
99+
| `packages/create-vite-app/.gitignore` | Create - ignore src/versions.ts |
100+
101+
---
102+
103+
## Template Files Copied (from examples/react-vanilla-spa/)
104+
105+
```
106+
project-name/
107+
├── client/
108+
│ ├── base.css
109+
│ ├── base.jsx
110+
│ ├── index.html
111+
│ └── mount.js
112+
├── package.json (transformed)
113+
├── server.js
114+
└── vite.config.js
115+
```
116+
117+
---
118+
119+
## Version Mapping
120+
121+
| Source Reference | Package | Resolved |
122+
|-----------------|---------|----------|
123+
| `workspace:^` | @fastify/vite | ^8.2.3 |
124+
| `catalog:` | fastify | ^5.6.2 |
125+
| `catalog:` | vite | ^7.3.0 |
126+
| `catalog:react` | react | ^19.2.3 |
127+
| `catalog:react` | react-dom | ^19.2.3 |
128+
| `catalog:react` | @vitejs/plugin-react | ^5.1.2 |

0 commit comments

Comments
 (0)