Skip to content

Commit 1c7139e

Browse files
mudiageofengmk2
andauthored
feat(cli): add svelte template support via sv cli (#982)
## Description This PR adds support for Svelte projects using the official `sv` CLI. Previously, `vp create svelte` would attempt to use the discontinued`create-svelte` package. Closes #857 ### Changes: - **Mapping:** Updated [discovery.ts](cci:7://file:///c:/Users/Admin/vite-plus/packages/cli/src/create/discovery.ts:0:0-0:0) to map the `svelte` shorthand template name to the `sv` package. - **Command Handling:** Updated [remote.ts](cci:7://file:///c:/Users/Admin/vite-plus/packages/cli/src/create/templates/remote.ts:0:0-0:0) to automatically prepend the `create` subcommand if omitted and add necessary flags: - `--no-install`: To let Vite+ handle dependency installation. - **Documentation:** Added `svelte` to the CLI help examples and the `vp create --list` popular templates section. ## Type of Change - [x] New feature (non-breaking change which adds functionality) --------- Co-authored-by: MK (fengmk2) <fengmk2@gmail.com>
1 parent 31a3ad3 commit 1c7139e

File tree

7 files changed

+21
-1
lines changed

7 files changed

+21
-1
lines changed

docs/guide/create.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Vite+ ships with these built-in templates:
3333

3434
`vp create` is not limited to the built-in templates.
3535

36-
- Use shorthand templates like `vite`, `@tanstack/start`, `next-app`, `nuxt`, `react-router`, and `vue`
36+
- Use shorthand templates like `vite`, `@tanstack/start`, `svelte`, `next-app`, `nuxt`, `react-router`, and `vue`
3737
- Use full package names like `create-vite` or `create-next-app`
3838
- Use local templates such as `./tools/create-ui-component` or `@acme/generator-*`
3939
- Use remote templates such as `github:user/repo` or `https://github.com/user/template-repo`
@@ -76,6 +76,7 @@ vp create vite:generator
7676
# Use shorthand community templates
7777
vp create vite
7878
vp create @tanstack/start
79+
vp create svelte
7980

8081
# Use full package names
8182
vp create create-vite

packages/cli/snap-tests-global/command-create-help/snap.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Examples:
3333
# Use existing templates (shorthand expands to create-* packages)
3434
vp create vite
3535
vp create @tanstack/start
36+
vp create svelte
3637
vp create vite -- --template react-ts
3738

3839
# Full package names also work
@@ -87,6 +88,7 @@ Examples:
8788
# Use existing templates (shorthand expands to create-* packages)
8889
vp create vite
8990
vp create @tanstack/start
91+
vp create svelte
9092
vp create vite -- --template react-ts
9193

9294
# Full package names also work
@@ -141,6 +143,7 @@ Examples:
141143
# Use existing templates (shorthand expands to create-* packages)
142144
vp create vite
143145
vp create @tanstack/start
146+
vp create svelte
144147
vp create vite -- --template react-ts
145148

146149
# Full package names also work

packages/cli/snap-tests-global/new-check/snap.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Examples:
3333
# Use existing templates (shorthand expands to create-* packages)
3434
vp create vite
3535
vp create @tanstack/start
36+
vp create svelte
3637
vp create vite -- --template react-ts
3738

3839
# Full package names also work
@@ -71,6 +72,7 @@ Popular Templates (shorthand):
7172
next-app Next.js application (create-next-app)
7273
nuxt Nuxt application (create-nuxt)
7374
react-router React Router application (create-react-router)
75+
svelte Svelte application (sv create)
7476
vue Vue application (create-vue)
7577

7678
Examples:

packages/cli/src/create/__tests__/discovery.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ describe('expandCreateShorthand', () => {
6767
it('should handle special cases where default convention does not apply', () => {
6868
expect(expandCreateShorthand('nitro')).toBe('create-nitro-app');
6969
expect(expandCreateShorthand('nitro@latest')).toBe('create-nitro-app@latest');
70+
expect(expandCreateShorthand('svelte')).toBe('sv');
71+
expect(expandCreateShorthand('svelte@latest')).toBe('sv@latest');
7072
});
7173
});
7274

packages/cli/src/create/bin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ const helpMessage = renderCliDoc({
111111
` ${muted('# Use existing templates (shorthand expands to create-* packages)')}`,
112112
` ${accent('vp create vite')}`,
113113
` ${accent('vp create @tanstack/start')}`,
114+
` ${accent('vp create svelte')}`,
114115
` ${accent('vp create vite -- --template react-ts')}`,
115116
'',
116117
` ${muted('# Full package names also work')}`,
@@ -156,6 +157,7 @@ const listTemplatesMessage = renderCliDoc({
156157
{ label: 'next-app', description: 'Next.js application (create-next-app)' },
157158
{ label: 'nuxt', description: 'Nuxt application (create-nuxt)' },
158159
{ label: 'react-router', description: 'React Router application (create-react-router)' },
160+
{ label: 'svelte', description: 'Svelte application (sv create)' },
159161
{ label: 'vue', description: 'Vue application (create-vue)' },
160162
],
161163
},

packages/cli/src/create/discovery.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ export function expandCreateShorthand(templateName: string): string {
198198
if (name === 'nitro') {
199199
return `create-nitro-app${version}`;
200200
}
201+
if (name === 'svelte') {
202+
return `sv${version}`;
203+
}
201204

202205
return `create-${name}${version}`;
203206
}

packages/cli/src/create/templates/remote.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ function autoFixRemoteTemplateCommand(templateInfo: TemplateInfo, workspaceInfo:
110110
templateInfo.args.push('--no-install');
111111
// don't setup toolchain automatically
112112
templateInfo.args.push('--no-toolchain');
113+
} else if (packageName === 'sv') {
114+
// ensure create command is used
115+
if (templateInfo.args[0] !== 'create') {
116+
templateInfo.args.unshift('create');
117+
}
118+
// don't run npm install after project creation
119+
templateInfo.args.push('--no-install');
113120
}
114121

115122
if (workspaceInfo.isMonorepo) {

0 commit comments

Comments
 (0)