Skip to content

Commit 248e0d8

Browse files
committed
refactor(cli): use create-vite to impl vite new
1 parent fa6449e commit 248e0d8

55 files changed

Lines changed: 1081 additions & 1167 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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,19 @@
2323
},
2424
"dependencies": {
2525
"@voidzero-dev/vite-plus": "workspace:*",
26+
"create-vite": "catalog:",
27+
"cross-spawn": "catalog:",
2628
"oxlint": "catalog:",
2729
"rolldown-vite": "catalog:",
2830
"vitest": "catalog:"
2931
},
3032
"devDependencies": {
33+
"@clack/prompts": "catalog:",
34+
"@types/cross-spawn": "catalog:",
3135
"@voidzero-dev/vite-plus-tools": "workspace:",
32-
"rolldown": "catalog:"
36+
"rolldown": "catalog:",
37+
"picocolors": "catalog:",
38+
"mri": "catalog:"
3339
},
3440
"engines": {
3541
"node": ">=20.11.0"

packages/global/rolldown.config.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@ import { defineConfig } from 'rolldown';
22

33
export default defineConfig({
44
input: './src/index.ts',
5-
external: [/^node:/, 'oxfmt', 'oxlint', /rolldown-vite/],
5+
external: [
6+
/^node:/,
7+
'oxfmt',
8+
'oxlint',
9+
/rolldown-vite/,
10+
'create-vite',
11+
// FIXME: Calling `require` for "child_process" in an environment that doesn't expose the `require` function
12+
'cross-spawn',
13+
// FIXME: will lost colors if not external
14+
'picocolors',
15+
],
616
output: {
717
format: 'esm',
818
dir: './dist',
Lines changed: 65 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,91 @@
11
> vp new -h # show help
2+
Usage: vite new [OPTION]... [DIRECTORY]
23

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
4+
Create a new Vite+ project in TypeScript.
5+
With no arguments, start the CLI in interactive mode.
136

147
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-
> vp 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-
git init
8+
--monorepo create a monorepo project
9+
--app add an app to existing monorepo, e.g.: view new --app apps/website
10+
--lib add a library to existing monorepo, e.g.: view new --lib packages/utils
11+
-t, --template NAME use a specific template
12+
--pm NAME use a specific package manager, e.g.: view new --pm pnpm
13+
--git init git repository
14+
--overwrite overwrite existing files
15+
16+
Available templates:
17+
vanilla-ts
18+
vue-ts
19+
react-ts
20+
preact-ts (WIP)
21+
lit-ts (WIP)
22+
svelte-ts (WIP)
23+
solid-ts (WIP)
24+
qwik-ts (WIP)
25+
26+
> vp new --template vanilla-ts --monorepo --pm pnpm --git false --overwrite hello-vite-plus # create monorepo
27+
28+
◇ Scaffolding project in hello-vite-plus/apps/website...
29+
30+
└ Done. Now run:
31+
32+
cd hello-vite-plus
4233
vite run ready
4334
vite run dev
4435

45-
To add new packages to your monorepo:
36+
To add new packages to your monorepo:
37+
4638
vite new --app apps/my-app
4739
vite new --lib packages/my-lib
4840

49-
> cd my-project && vp new --app apps/my-app # add app
50-
Creating new app at apps/my-app...
51-
✅ Successfully created app at apps/my-app
5241

53-
Next steps:
42+
> cd hello-vite-plus && ls # check files
43+
README.md
44+
apps
45+
package.json
46+
pnpm-workspace.yaml
47+
tsconfig.json
48+
vite.config.ts
49+
50+
> cd hello-vite-plus && vp new --app --template vanilla-ts apps/my-app # add app
51+
52+
◇ Scaffolding project in apps/my-app...
53+
54+
└ Done. Now run:
55+
5456
cd apps/my-app
57+
vite run ready
5558
vite run dev
5659

57-
> cd my-project && ls apps
60+
61+
> cd hello-vite-plus && ls apps
5862
my-app
5963
website
6064

61-
> cd my-project && vp new --lib packages/my-lib # add lib
62-
Creating new library at packages/my-lib...
63-
✅ Successfully created library at packages/my-lib
65+
> cd hello-vite-plus && vp new --lib packages/my-lib # add lib
66+
67+
◇ Scaffolding project in packages/my-lib...
68+
69+
└ Done. Now run:
6470

65-
Next steps:
71+
cd packages/my-lib
6672
vite run ready
73+
vite run dev
74+
6775

68-
> cd my-project && ls packages
76+
> cd hello-vite-plus && ls packages
6977
my-lib
7078

71-
> cd my-project && vp new --lib tools/my-tool # add lib new not exists tools directory
72-
Creating new library at tools/my-tool...
73-
✅ Successfully created library at tools/my-tool
79+
> cd hello-vite-plus && vp new --lib tools/my-tool # add lib new not exists tools directory
80+
81+
◇ Scaffolding project in tools/my-tool...
82+
83+
└ Done. Now run:
7484

75-
Next steps:
85+
cd tools/my-tool
7686
vite run ready
87+
vite run dev
88+
7789

78-
> cd my-project && ls tools
90+
> cd hello-vite-plus && ls tools
7991
my-tool
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"commands": [
33
"vp new -h # show help",
4-
"vp new my-project monorepo # create monorepo",
5-
"cd my-project && vp new --app apps/my-app # add app",
6-
"cd my-project && ls apps",
7-
"cd my-project && vp new --lib packages/my-lib # add lib",
8-
"cd my-project && ls packages",
9-
"cd my-project && vp new --lib tools/my-tool # add lib new not exists tools directory",
10-
"cd my-project && ls tools"
4+
"vp new --template vanilla-ts --monorepo --pm pnpm --git false --overwrite hello-vite-plus # create monorepo",
5+
"cd hello-vite-plus && ls # check files",
6+
"cd hello-vite-plus && vp new --app --template vanilla-ts apps/my-app # add app",
7+
"cd hello-vite-plus && ls apps",
8+
"cd hello-vite-plus && vp new --lib packages/my-lib # add lib",
9+
"cd hello-vite-plus && ls packages",
10+
"cd hello-vite-plus && vp new --lib tools/my-tool # add lib new not exists tools directory",
11+
"cd hello-vite-plus && ls tools"
1112
]
1213
}
Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
> vp new my-project singlerepo # create singlerepo
1+
> vp new --template vanilla-ts --monorepo false --pm pnpm --git false --overwrite hello-vite-plus # create singlerepo
2+
3+
◇ Scaffolding project in hello-vite-plus...
4+
5+
└ Done. Now run:
26

3-
Creating singlerepo project: my-project...
4-
✅ Successfully created singlerepo project: my-project
5-
6-
Next steps:
7-
cd my-project
8-
git init
7+
cd hello-vite-plus
98
vite run ready
109
vite run dev
10+
11+
To add new packages to your monorepo:
12+
13+
vite new --app apps/my-app
14+
vite new --lib packages/my-lib
15+
16+
17+
> cd hello-vite-plus && ls # check files
18+
index.html
19+
package.json
20+
public
21+
src
22+
tsconfig.json
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"commands": [
3-
"vp new my-project singlerepo # create singlerepo"
3+
"vp new --template vanilla-ts --monorepo false --pm pnpm --git false --overwrite hello-vite-plus # create singlerepo",
4+
"cd hello-vite-plus && ls # check files"
45
]
56
}

packages/global/src/index.ts

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,8 @@
1-
import { scaffold, type ScaffoldOptions } from './scaffold.js';
2-
31
// Parse command line arguments to intercept 'new' command
42
const args = process.argv.slice(2);
53

64
if (args[0] === 'new') {
7-
// Handle the 'new' command
8-
const options: ScaffoldOptions = {};
9-
const positionalArgs: string[] = [];
10-
11-
// Parse flags and collect positional arguments
12-
for (let i = 1; i < args.length; i++) {
13-
if (args[i] === '--help' || args[i] === '-h') {
14-
options.help = true;
15-
break;
16-
} else if (args[i] === '--app' && args[i + 1]) {
17-
options.app = args[i + 1];
18-
i++;
19-
} else if (args[i] === '--lib' && args[i + 1]) {
20-
options.lib = args[i + 1];
21-
i++;
22-
} else if (args[i] === '--monorepo' || args[i] === '-m') {
23-
options.projectType = 'monorepo';
24-
} else if (args[i] === '--singlerepo' || args[i] === '-s') {
25-
options.projectType = 'singlerepo';
26-
} else if (!args[i].startsWith('-')) {
27-
positionalArgs.push(args[i]);
28-
}
29-
}
30-
31-
// Handle positional arguments: first is project name, second is project type
32-
// Skip if help is requested
33-
if (!options.help) {
34-
if (positionalArgs.length > 0) {
35-
options.projectName = positionalArgs[0];
36-
}
37-
if (positionalArgs.length > 1) {
38-
const type = positionalArgs[1].toLowerCase();
39-
if (type === 'monorepo' || type === 'mono') {
40-
options.projectType = 'monorepo';
41-
} else if (type === 'singlerepo' || type === 'single') {
42-
options.projectType = 'singlerepo';
43-
}
44-
}
45-
}
46-
47-
// Run scaffolding
48-
scaffold(options).catch((err) => {
49-
// Handle SIGINT (Ctrl+C)
50-
if (err.name === 'AbortError') {
51-
process.exit(0);
52-
}
53-
console.error('[vite+] %s', err);
54-
process.exit(1);
55-
});
5+
import('./new.ts');
566
} else {
577
// Delegate all other commands to vite-plus CLI
588
// @ts-ignore no types for vite-plus/bin

0 commit comments

Comments
 (0)