Skip to content

Commit 151c315

Browse files
authored
Add svelte recipe to create-tauri-app (#2276) (#2279)
1 parent 74a278f commit 151c315

3 files changed

Lines changed: 76 additions & 1 deletion

File tree

.changes/cta-svelte-recipe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-tauri-app": patch
3+
---
4+
5+
Add Svelte recipe using the official template.

tooling/create-tauri-app/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { vuecli } from './recipes/vue-cli'
1212
import { vanillajs } from './recipes/vanilla'
1313
import { vite } from './recipes/vite'
1414
import { ngcli } from './recipes/ng-cli'
15+
import { svelte } from './recipes/svelte'
1516
import { install, checkPackageManager } from './dependency-manager'
1617
import { shell } from './shell'
1718
import { addTauriScript } from './helpers/add-tauri-script'
@@ -114,7 +115,7 @@ interface Responses {
114115
recipeName: string
115116
}
116117

117-
const allRecipes: Recipe[] = [vanillajs, cra, vite, vuecli, ngcli]
118+
const allRecipes: Recipe[] = [vanillajs, cra, vite, vuecli, ngcli, svelte]
118119

119120
const recipeByShortName = (name: string): Recipe | undefined =>
120121
allRecipes.find((r) => r.shortName === name)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
2+
// SPDX-License-Identifier: Apache-2.0
3+
// SPDX-License-Identifier: MIT
4+
5+
import { join } from 'path'
6+
import { shell } from '../shell'
7+
import { Recipe } from '../types/recipe'
8+
9+
const svelte: Recipe = {
10+
descriptiveName: {
11+
name: 'Svelte (https://github.com/sveltejs/template)',
12+
value: 'svelte'
13+
},
14+
shortName: 'svelte',
15+
extraNpmDevDependencies: [],
16+
extraNpmDependencies: [],
17+
extraQuestions: () => {
18+
return [
19+
{
20+
type: 'confirm',
21+
name: 'typescript',
22+
message: 'Enable Typescript?',
23+
default: true,
24+
loop: false
25+
}
26+
]
27+
},
28+
configUpdate: ({ cfg, packageManager }) => ({
29+
...cfg,
30+
distDir: `../public`,
31+
devPath: 'http://localhost:5000',
32+
beforeDevCommand: `${packageManager === 'yarn' ? 'yarn' : 'npm run'} dev`,
33+
beforeBuildCommand: `${
34+
packageManager === 'yarn' ? 'yarn' : 'npm run'
35+
} build`
36+
}),
37+
preInit: async ({ cwd, cfg, answers }) => {
38+
let typescript = false
39+
if (answers) {
40+
typescript = !!answers.typescript
41+
}
42+
43+
await shell('npx', ['degit', 'sveltejs/template', `${cfg.appName}`], {
44+
cwd
45+
})
46+
47+
// Add Typescript
48+
if (typescript) {
49+
await shell('node', ['scripts/setupTypeScript.js'], {
50+
cwd: join(cwd, cfg.appName)
51+
})
52+
}
53+
},
54+
postInit: async ({ cfg, packageManager }) => {
55+
console.log(`
56+
Your installation completed.
57+
To start, run the dev script:
58+
59+
$ cd ${cfg.appName}
60+
$ ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri ${
61+
packageManager === 'npm' ? '-- ' : ''
62+
}dev
63+
`)
64+
65+
return await Promise.resolve()
66+
}
67+
}
68+
69+
export { svelte }

0 commit comments

Comments
 (0)