Skip to content

Commit e4306ab

Browse files
committed
feat: code generator
1 parent ebce813 commit e4306ab

57 files changed

Lines changed: 6463 additions & 1588 deletions

Some content is hidden

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

packages/global/package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@
2323
},
2424
"dependencies": {
2525
"@voidzero-dev/vite-plus": "workspace:*",
26-
"create-tsdown": "catalog:",
27-
"create-vite": "catalog:",
2826
"cross-spawn": "catalog:",
2927
"oxlint": "catalog:",
3028
"oxlint-tsgolint": "catalog:",
31-
"rolldown-vite": "workspace:*"
29+
"rolldown-vite": "workspace:*",
30+
"validate-npm-package-name": "catalog:"
3231
},
3332
"devDependencies": {
3433
"@clack/prompts": "catalog:",
34+
"@std/yaml": "catalog:",
3535
"@types/cross-spawn": "catalog:",
36+
"@types/validate-npm-package-name": "catalog:",
3637
"@voidzero-dev/vite-plus-tools": "workspace:",
38+
"glob": "catalog:",
39+
"minimatch": "catalog:",
3740
"mri": "catalog:",
3841
"picocolors": "catalog:",
3942
"rolldown": "workspace:*"

packages/global/rolldown.config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ export default defineConfig({
55
external: [
66
/^node:/,
77
'@voidzero-dev/vite-plus/bin',
8-
'create-vite',
9-
'create-tsdown',
8+
'@voidzero-dev/vite-plus/binding',
109
// FIXME: Calling `require` for "child_process" in an environment that doesn't expose the `require` function
1110
'cross-spawn',
1211
// FIXME: will lost colors if not external
1312
'picocolors',
13+
// FIXME: Calling `require` for "module" in an environment that doesn't expose the `require` function
14+
'validate-npm-package-name',
1415
],
1516
output: {
1617
format: 'esm',
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
> vp gen --help # show help
2+
Usage: vite gen [TEMPLATE] [OPTIONS] [-- TEMPLATE_OPTIONS]
3+
4+
Run any template (builtin, remote, or local) with automatic vite+ integration.
5+
6+
Arguments:
7+
TEMPLATE Template name (optional; you will be prompted if omitted)
8+
- Built-in: vite:monorepo, vite:application, vite:library, vite:generator
9+
- Remote: create-vite, @tanstack/create-start, create-next-app, create-nuxt,
10+
github:user/repo, https://github.com/user/template-repo
11+
- Local: @company/generator-*, ./tools/create-ui-component
12+
13+
Options (before --):
14+
--directory DIR Target directory for the generated project.
15+
Only works for built-in templates; auto-detected for remote templates.
16+
--no-interactive Run in non-interactive mode (skip prompts and use defaults)
17+
--list List all available templates
18+
-h, --help Show this help message
19+
20+
Template options (after --):
21+
All arguments after -- are passed directly through to the template command.
22+
23+
Examples:
24+
# Interactive mode - choose template via prompt
25+
vite gen
26+
27+
# Run any existing template (npx / pnpm dlx / yarn dlx / bunx auto-detected)
28+
vite gen create-vite
29+
vite gen create-next-app
30+
vite gen @tanstack/create-start
31+
32+
# With template-specific options (after --)
33+
vite gen create-vite -- --template react-ts
34+
vite gen create-next-app -- --typescript --app
35+
36+
# Create vite+ monorepo, application, library, or generator scaffolds
37+
vite gen vite:monorepo
38+
vite gen vite:application
39+
vite gen vite:library
40+
vite gen vite:generator
41+
42+
# Monorepo: specify target directory
43+
vite gen vite:application --directory=packages/my-app
44+
45+
# Combine gen command options and template options
46+
vite gen vite:application --directory=apps/my-app -- --template vue-ts
47+
48+
# Run templates from GitHub (via degit)
49+
vite gen github:user/repo
50+
vite gen https://github.com/user/template-repo
51+
52+
Note: Templates are executed via npx / pnpm dlx / yarn dlx / bunx,
53+
based on the detected package manager.
54+
No global installation required - always uses the latest version.
55+
56+
Aliases: g, generate, new
57+
58+
59+
> vp gen --list # list templates
60+
61+
📦 Available Templates
62+
63+
Vite+ Built-in Templates:
64+
• vite:monorepo - Create a new monorepo
65+
• vite:application - Create a new application
66+
• vite:library - Create a new library
67+
• vite:generator - Scaffold a new code generator
68+
69+
Popular Remote Templates:
70+
• create-vite - Official Vite templates
71+
• @tanstack/create-start - TanStack applications
72+
• create-next-app - Next.js application
73+
• create-nuxt - Nuxt application
74+
• create-typescript-app - TypeScript application
75+
• create-react-router - React Router application
76+
• create-vue - Vue application
77+
78+
Run vite gen for interactive mode
79+
Run vite gen <template> to use any template
80+
Run vite gen <template> -- <options> to pass options to the template
81+
82+
✨ Tip: You can use ANY npm template with vite gen!
83+
84+
85+
[1]> vp gen --no-interactive # run in non-interactive mode without template name will show error
86+
87+
Template name is required when running in non-interactive mode
88+
89+
Usage: vite gen [TEMPLATE] [OPTIONS] [-- TEMPLATE_OPTIONS]
90+
91+
Example:
92+
# Create a new application in non-interactive mode with a custom target directory
93+
vite gen vite:application --no-interactive --directory=apps/my-app
94+
95+
Use `vite gen --list` to list all available templates, or run `vite gen --help` for more information.
96+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"commands": [
3+
"vp gen --help # show help",
4+
"vp gen --list # list templates",
5+
"vp gen --no-interactive # run in non-interactive mode without template name will show error"
6+
]
7+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
> vp gen vite:library --no-interactive --directory @my-scope/my-library -- --template default > /dev/null # create vite library with scope name
2+
> ls my-library # check files created
3+
README.md
4+
package.json
5+
src
6+
tests
7+
tsconfig.json
8+
tsdown.config.ts
9+
10+
> cat my-library/package.json # check package.json
11+
{
12+
"name": "@my-scope/my-library",
13+
"version": "0.0.0",
14+
"description": "A starter for creating a TypeScript package.",
15+
"type": "module",
16+
"license": "MIT",
17+
"homepage": "https://github.com/author/library#readme",
18+
"bugs": {
19+
"url": "https://github.com/author/library/issues"
20+
},
21+
"repository": {
22+
"type": "git",
23+
"url": "git+https://github.com/author/library.git"
24+
},
25+
"author": "Author Name <author.name@mail.com>",
26+
"files": [
27+
"dist"
28+
],
29+
"main": "./dist/index.mjs",
30+
"module": "./dist/index.mjs",
31+
"types": "./dist/index.d.mts",
32+
"exports": {
33+
".": "./dist/index.mjs",
34+
"./package.json": "./package.json"
35+
},
36+
"scripts": {
37+
"build": "vite lib",
38+
"dev": "vite lib --watch",
39+
"test": "vite test",
40+
"typecheck": "tsc --noEmit",
41+
"prepublishOnly": "pnpm run build"
42+
},
43+
"devDependencies": {
44+
"@types/node": "^24.10.1",
45+
"bumpp": "^10.3.1",
46+
"typescript": "^5.9.3",
47+
"vite": "npm:@voidzero-dev/vite-plus@latest"
48+
},
49+
"packageManager": "pnpm@<semver>"
50+
}
51+
52+
> cat my-library/.npmrc # check .npmrc
53+
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
54+
@voidzero-dev:registry=https://npm.pkg.github.com/
55+
56+
> cat my-library/tsconfig.json # check TypeScript setup
57+
{
58+
"compilerOptions": {
59+
"target": "esnext",
60+
"lib": ["es2023"],
61+
"moduleDetection": "force",
62+
"module": "preserve",
63+
"moduleResolution": "bundler",
64+
"resolveJsonModule": true,
65+
"types": ["node"],
66+
"strict": true,
67+
"noUnusedLocals": true,
68+
"declaration": true,
69+
"emitDeclarationOnly": true,
70+
"esModuleInterop": true,
71+
"isolatedModules": true,
72+
"verbatimModuleSyntax": true,
73+
"skipLibCheck": true
74+
},
75+
"include": ["src"]
76+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"env": {
3+
"VITE_DISABLE_AUTO_INSTALL": "1"
4+
},
5+
"commands": [
6+
"vp gen vite:library --no-interactive --directory @my-scope/my-library -- --template default > /dev/null # create vite library with scope name",
7+
"ls my-library # check files created",
8+
"cat my-library/package.json # check package.json",
9+
"cat my-library/.npmrc # check .npmrc",
10+
"cat my-library/tsconfig.json # check TypeScript setup"
11+
]
12+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
> vp gen vite:library --no-interactive > /dev/null # create vite library with default values
2+
> ls vite-plus-library # check files created
3+
README.md
4+
package.json
5+
src
6+
tests
7+
tsconfig.json
8+
tsdown.config.ts
9+
10+
> cat vite-plus-library/package.json # check package.json
11+
{
12+
"name": "vite-plus-library",
13+
"version": "0.0.0",
14+
"description": "A starter for creating a TypeScript package.",
15+
"type": "module",
16+
"license": "MIT",
17+
"homepage": "https://github.com/author/library#readme",
18+
"bugs": {
19+
"url": "https://github.com/author/library/issues"
20+
},
21+
"repository": {
22+
"type": "git",
23+
"url": "git+https://github.com/author/library.git"
24+
},
25+
"author": "Author Name <author.name@mail.com>",
26+
"files": [
27+
"dist"
28+
],
29+
"main": "./dist/index.mjs",
30+
"module": "./dist/index.mjs",
31+
"types": "./dist/index.d.mts",
32+
"exports": {
33+
".": "./dist/index.mjs",
34+
"./package.json": "./package.json"
35+
},
36+
"scripts": {
37+
"build": "vite lib",
38+
"dev": "vite lib --watch",
39+
"test": "vite test",
40+
"typecheck": "tsc --noEmit",
41+
"prepublishOnly": "pnpm run build"
42+
},
43+
"devDependencies": {
44+
"@types/node": "^24.10.1",
45+
"bumpp": "^10.3.1",
46+
"typescript": "^5.9.3",
47+
"vite": "npm:@voidzero-dev/vite-plus@latest"
48+
},
49+
"packageManager": "pnpm@<semver>"
50+
}
51+
52+
> cat vite-plus-library/.npmrc # check .npmrc
53+
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
54+
@voidzero-dev:registry=https://npm.pkg.github.com/
55+
56+
> cat vite-plus-library/tsconfig.json # check TypeScript setup
57+
{
58+
"compilerOptions": {
59+
"target": "esnext",
60+
"lib": ["es2023"],
61+
"moduleDetection": "force",
62+
"module": "preserve",
63+
"moduleResolution": "bundler",
64+
"resolveJsonModule": true,
65+
"types": ["node"],
66+
"strict": true,
67+
"noUnusedLocals": true,
68+
"declaration": true,
69+
"emitDeclarationOnly": true,
70+
"esModuleInterop": true,
71+
"isolatedModules": true,
72+
"verbatimModuleSyntax": true,
73+
"skipLibCheck": true
74+
},
75+
"include": ["src"]
76+
}
77+
78+
> vp gen vite:library --no-interactive --directory my-vue -- --template vue > /dev/null # create vite library with custom template
79+
> ls my-vue # check files created
80+
README.md
81+
package.json
82+
playground
83+
src
84+
tests
85+
tsconfig.json
86+
tsdown.config.ts
87+
vite.config.ts
88+
vitest.config.ts
89+
90+
> cat my-vue/package.json # check package.json
91+
{
92+
"name": "my-vue",
93+
"version": "0.0.0",
94+
"description": "A starter for creating a Vue component library.",
95+
"type": "module",
96+
"license": "MIT",
97+
"homepage": "https://github.com/author/library#readme",
98+
"bugs": {
99+
"url": "https://github.com/author/library/issues"
100+
},
101+
"repository": {
102+
"type": "git",
103+
"url": "git+https://github.com/author/library.git"
104+
},
105+
"author": "Author Name <author.name@mail.com>",
106+
"files": [
107+
"dist"
108+
],
109+
"main": "./dist/index.js",
110+
"module": "./dist/index.js",
111+
"types": "./dist/index.d.ts",
112+
"exports": {
113+
".": "./dist/index.js",
114+
"./package.json": "./package.json"
115+
},
116+
"publishConfig": {
117+
"access": "public"
118+
},
119+
"scripts": {
120+
"build": "vite lib",
121+
"dev": "vite lib --watch",
122+
"play": "vite",
123+
"test": "vite test",
124+
"typecheck": "vue-tsc --noEmit",
125+
"release": "bumpp && pnpm publish",
126+
"prepublishOnly": "pnpm run build"
127+
},
128+
"peerDependencies": {
129+
"vue": "^3.0.0"
130+
},
131+
"devDependencies": {
132+
"@types/node": "^24.10.1",
133+
"@vitejs/plugin-vue": "^6.0.1",
134+
"@vue/test-utils": "^2.4.6",
135+
"bumpp": "^10.3.1",
136+
"happy-dom": "^20.0.10",
137+
"typescript": "^5.9.3",
138+
"vue": "^3.5.24",
139+
"vue-tsc": "^3.1.4",
140+
"vite": "npm:@voidzero-dev/vite-plus@latest"
141+
},
142+
"packageManager": "pnpm@<semver>"
143+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"env": {
3+
"VITE_DISABLE_AUTO_INSTALL": "1"
4+
},
5+
"commands": [
6+
"vp gen vite:library --no-interactive > /dev/null # create vite library with default values",
7+
"ls vite-plus-library # check files created",
8+
"cat vite-plus-library/package.json # check package.json",
9+
"cat vite-plus-library/.npmrc # check .npmrc",
10+
"cat vite-plus-library/tsconfig.json # check TypeScript setup",
11+
"vp gen vite:library --no-interactive --directory my-vue -- --template vue > /dev/null # create vite library with custom template",
12+
"ls my-vue # check files created",
13+
"cat my-vue/package.json # check package.json"
14+
]
15+
}

0 commit comments

Comments
 (0)