Skip to content

Commit 8a4f493

Browse files
fengmk2claude
andcommitted
feat(global): add scaffolding command 'vite new' for project creation
- Add interactive 'vite new' command for creating Vite+ projects - Support both MonoRepo and SingleRepo project types - MonoRepo is the default option (can press Enter to select) - Allow skipping prompts with CLI arguments: 'vite new <name> <type>' - Support flags: --monorepo/-m, --singlerepo/-s for project type - Add --app and --lib flags for adding packages to existing monorepos - Implement Ctrl+C handling for graceful exit during prompts - Copy templates without node_modules directory - Auto-detect monorepo root via pnpm-workspace.yaml or package.json workspaces - Update package.json with actual project/package names Usage examples: vite new # Interactive mode vite new my-project # Prompt for type only vite new my-project monorepo # No prompts vite new my-project --singlerepo # Using flags vite new --app apps/my-app # Add app to monorepo vite new --lib packages/my-lib # Add lib to monorepo 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0d34ece commit 8a4f493

89 files changed

Lines changed: 1457 additions & 937 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ jobs:
145145
run: |
146146
pnpm run --filter=@voidzero-dev/vite-plus --filter=@voidzero-dev/global snap-test
147147
git diff --exit-code
148+
env:
149+
# For `@voidzero-dev/global#snap-test`, need to install @voidzero-dev/vite-plus
150+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
148151

149152
install-e2e-test:
150153
name: vite install E2E test

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/binding/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ edition = "2024"
77
clap = { workspace = true }
88
napi = { workspace = true }
99
napi-derive = { workspace = true }
10+
tracing = { workspace = true }
1011
vite_error = { workspace = true }
11-
vite_task = { workspace = true }
1212
vite_path = { workspace = true }
13+
vite_task = { workspace = true }
1314

1415
[build-dependencies]
1516
napi-build = { workspace = true }

packages/cli/binding/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ pub async fn run(options: CliOptions) -> Result<()> {
158158
.await
159159
{
160160
// Convert Rust errors to NAPI errors for JavaScript
161+
tracing::error!("Rust error: {:?}", e);
161162
return Err(anyhow::Error::from(e).into());
162163
}
163164
Ok(())

packages/global/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ Use 1Password CLI:
2828
GITHUB_TOKEN=$(op read "op://YOUR_GITHUB_TOKEN_PATH") npm install -g @voidzero-dev/global
2929
```
3030

31+
## Get Started
32+
33+
### Scaffolding your first Vite+ project
34+
35+
Use the `vite new` command to start, it will ask you a few questions to help you scaffold your project, supports both `MonoRepo` and `SingleRepo`.
36+
37+
```bash
38+
vite new
39+
```
40+
41+
If you select `Monorepo`, you can add new `app` or `lib` to your project.
42+
43+
```bash
44+
vite new --app apps/website
45+
vite new --lib packages/utils
46+
```
47+
3148
## Overview
3249

3350
```bash

packages/global/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
"url": "https://github.com/voidzero-dev/vite-plus.git"
88
},
99
"bin": {
10-
"vite": "./bin/vp",
11-
"vite-plus": "./bin/vp",
12-
"vp": "./bin/vp",
13-
"vite-plus-dev": "./bin/vp-dev"
10+
"vite": "./bin/vite",
11+
"vite-plus": "./bin/vite",
12+
"vp": "./bin/vite",
13+
"vite-plus-dev": "./bin/vite-dev"
1414
},
1515
"files": [
1616
"bin",
17-
"dist"
17+
"dist",
18+
"templates"
1819
],
1920
"scripts": {
2021
"dev": "tsdown --watch",

packages/global/snap-tests/new-monorepo/snap.txt

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
> vite new -h # show help
2+
3+
vite new - Create a new Vite+ project
4+
5+
Usage:
6+
vite new [project-name] [project-type] [options]
7+
vite new --app <path> Add an app to existing monorepo
8+
vite new --lib <path> Add a library to existing monorepo
9+
10+
Arguments:
11+
project-name Name of the project to create
12+
project-type Type of project: monorepo, mono, singlerepo, single
13+
14+
Options:
15+
--monorepo, -m Create a monorepo project
16+
--singlerepo, -s Create a singlerepo project
17+
--app <path> Add an app package to existing monorepo
18+
--lib <path> Add a library package to existing monorepo
19+
--help, -h Show this help message
20+
21+
Examples:
22+
vite new Interactive mode (prompts for all options)
23+
vite new my-project Create project with prompts for type
24+
vite new my-project monorepo Create monorepo without prompts
25+
vite new my-project -s Create singlerepo using flag
26+
vite new --app apps/my-app Add app to current monorepo
27+
vite new --lib packages/utils Add library to current monorepo
28+
29+
Notes:
30+
- MonoRepo is the default when prompted (press Enter to select)
31+
- Press Ctrl+C to exit during prompts
32+
33+
34+
> vite new my-project monorepo # create monorepo
35+
36+
Creating monorepo project: my-project...
37+
✅ Successfully created monorepo project: my-project
38+
39+
Next steps:
40+
cd my-project
41+
vite run ready
42+
vite dev
43+
44+
To add new packages to your monorepo:
45+
vite new --app apps/my-app
46+
vite new --lib packages/my-lib
47+
48+
> cd my-project && git init # avoid oxlint https://github.com/oxc-project/oxc/issues/13793
49+
Initialized empty Git repository in /private<cwd>/my-project/.git/
50+
51+
> cd my-project && vite run ready # run ready task
52+
Cache not found
53+
Scope: all <variable> workspace projects
54+
Progress: resolved 1, reused 0, downloaded 0, added 0
55+
Progress: resolved 27, reused 26, downloaded 0, added 0
56+
 WARN  Skip adding vite to the default catalog because it already exists as npm:@voidzero-dev/vite-plus. Please use `pnpm update` to update the catalogs.
57+
 WARN  Skip adding @voidzero-dev/vite-plus to the default catalog because it already exists as latest. Please use `pnpm update` to update the catalogs.
58+
 WARN  Skip adding vitest to the default catalog because it already exists as beta. Please use `pnpm update` to update the catalogs.
59+
 WARN  Skip adding vite to the default catalog because it already exists as npm:@voidzero-dev/vite-plus. Please use `pnpm update` to update the catalogs.
60+
Progress: resolved 172, reused 85, downloaded 0, added 0
61+
Packages: +<variable>
62+
+<repeat>
63+
Progress: resolved <variable>, reused <variable>, downloaded <variable>, added <variable>, done
64+
65+
devDependencies:
66+
+ @voidzero-dev/vite-plus <semver>
67+
+ vitest <semver>
68+
69+
╭ Warning ─────────────────────────────────────────────────────────────────────╮
70+
│ │
71+
│ Ignored build scripts: esbuild. │
72+
│ Run "pnpm approve-builds" to pick which dependencies should be allowed │
73+
│ to run scripts. │
74+
│ │
75+
╰──────────────────────────────────────────────────────────────────────────────╯
76+
77+
Done in <variable>ms using pnpm v<semver>
78+
Cache not found
79+
Cache not found
80+
Cache not found
81+
Cache not found
82+
Cache not found
83+
Cache not found
84+
Cache not found
85+
Cache not found
86+
Cache not found
87+
rolldown-vite v<semver> building for production...
88+
transforming...✓ 7 modules transformed.
89+
rendering chunks...
90+
computing gzip size...
91+
dist/index.html 0.45 kB │ gzip: 0.29 kB
92+
dist/assets/index-BAKMvvYC.css 1.37 kB │ gzip: 0.65 kB
93+
dist/assets/index-vM1AmoRk.js 3.04 kB │ gzip: 1.64 kB
94+
✓ built in <variable>ms
95+
96+
> cd my-project && vite new --app apps/my-app # add app
97+
Creating new app at apps/my-app...
98+
✅ Successfully created app at apps/my-app
99+
100+
Next steps:
101+
cd apps/my-app
102+
vite run ready
103+
vite dev
104+
105+
> cd my-project && vite new --lib packages/my-lib # add lib
106+
Creating new library at packages/my-lib...
107+
✅ Successfully created library at packages/my-lib
108+
109+
Next steps:
110+
cd packages/my-lib
111+
vite run ready
112+
113+
> cd my-project && vite run ready # run ready task after add app and lib
114+
Cache miss: apps content changed
115+
Scope: all <variable> workspace projects
116+
Progress: resolved 1, reused 0, downloaded 0, added 0
117+
Progress: resolved 157, reused 71, downloaded 0, added 0
118+
Progress: resolved 171, reused 85, downloaded 0, added 0
119+
 WARN  Skip adding typescript to the default catalog because it already exists as ^5.9.2. Please use `pnpm update` to update the catalogs.
120+
 WARN  Skip adding vite to the default catalog because it already exists as npm:@voidzero-dev/vite-plus. Please use `pnpm update` to update the catalogs.
121+
 WARN  Skip adding typescript to the default catalog because it already exists as ^5.9.2. Please use `pnpm update` to update the catalogs.
122+
 WARN  Skip adding vite to the default catalog because it already exists as npm:@voidzero-dev/vite-plus. Please use `pnpm update` to update the catalogs.
123+
 WARN  Skip adding @voidzero-dev/vite-plus to the default catalog because it already exists as latest. Please use `pnpm update` to update the catalogs.
124+
 WARN  Skip adding vitest to the default catalog because it already exists as beta. Please use `pnpm update` to update the catalogs.
125+
 WARN  Skip adding vite to the default catalog because it already exists as npm:@voidzero-dev/vite-plus. Please use `pnpm update` to update the catalogs.
126+
Already up to date
127+
Progress: resolved <variable>, reused <variable>, downloaded <variable>, added <variable>, done
128+
129+
Done in <variable>ms using pnpm v<semver>
130+
Cache not found
131+
Cache not found
132+
Cache not found
133+
Cache not found
134+
Cache not found
135+
Cache not found
136+
Cache not found
137+
Cache not found
138+
Cache hit, replaying
139+
rolldown-vite v<semver> building for production...
140+
transforming...✓ 7 modules transformed.
141+
rendering chunks...
142+
computing gzip size...
143+
dist/index.html 0.45 kB │ gzip: 0.29 kB
144+
dist/assets/index-BAKMvvYC.css 1.37 kB │ gzip: 0.65 kB
145+
dist/assets/index-vM1AmoRk.js 3.04 kB │ gzip: 1.64 kB
146+
✓ built in <variable>ms
147+
Cache not found
148+
Cache not found
149+
rolldown-vite v<semver> building for production...
150+
transforming...✓ 7 modules transformed.
151+
rendering chunks...
152+
computing gzip size...
153+
dist/index.html 0.45 kB │ gzip: 0.29 kB
154+
dist/assets/index-BAKMvvYC.css 1.37 kB │ gzip: 0.65 kB
155+
dist/assets/index-vM1AmoRk.js 3.04 kB │ gzip: 1.64 kB
156+
✓ built in <variable>ms
157+
158+
> cd my-project && vite new --lib tools/my-tool # add lib new not exists tools directory
159+
Creating new library at tools/my-tool...
160+
✅ Successfully created library at tools/my-tool
161+
162+
Next steps:
163+
cd tools/my-tool
164+
vite run ready
165+
166+
> cd my-project && vite run ready # run ready task after add lib
167+
Cache miss: content changed
168+
Scope: all <variable> workspace projects
169+
Lockfile is up to date, resolution step is skipped
170+
Already up to date
171+
172+
Done in <variable>ms using pnpm v<semver>
173+
Cache not found
174+
Cache not found
175+
Cache not found
176+
Cache not found
177+
Cache not found
178+
Cache not found
179+
Cache not found
180+
Cache not found
181+
Cache hit, replaying
182+
rolldown-vite v<semver> building for production...
183+
transforming...✓ 7 modules transformed.
184+
rendering chunks...
185+
computing gzip size...
186+
dist/index.html 0.45 kB │ gzip: 0.29 kB
187+
dist/assets/index-BAKMvvYC.css 1.37 kB │ gzip: 0.65 kB
188+
dist/assets/index-vM1AmoRk.js 3.04 kB │ gzip: 1.64 kB
189+
✓ built in <variable>ms
190+
Cache not found
191+
Cache hit, replaying
192+
rolldown-vite v<semver> building for production...
193+
transforming...✓ 7 modules transformed.
194+
rendering chunks...
195+
computing gzip size...
196+
dist/index.html 0.45 kB │ gzip: 0.29 kB
197+
dist/assets/index-BAKMvvYC.css 1.37 kB │ gzip: 0.65 kB
198+
dist/assets/index-vM1AmoRk.js 3.04 kB │ gzip: 1.64 kB
199+
✓ built in <variable>ms
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"commands": [
3+
"vite new -h # show help",
4+
"vite new my-project monorepo # create monorepo",
5+
"cd my-project && git init # avoid oxlint https://github.com/oxc-project/oxc/issues/13793",
6+
"cd my-project && vite run ready # run ready task",
7+
"cd my-project && vite new --app apps/my-app # add app",
8+
"cd my-project && vite new --lib packages/my-lib # add lib",
9+
"cd my-project && vite run ready # run ready task after add app and lib",
10+
"cd my-project && vite new --lib tools/my-tool # add lib new not exists tools directory",
11+
"cd my-project && vite run ready # run ready task after add lib"
12+
]
13+
}

0 commit comments

Comments
 (0)