Skip to content

Commit

Permalink
Add svelte recipe to create-tauri-app (#2276) (#2279)
Browse files Browse the repository at this point in the history
  • Loading branch information
krscott authored Jul 22, 2021
1 parent 74a278f commit 151c315
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/cta-svelte-recipe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-tauri-app": patch
---

Add Svelte recipe using the official template.
3 changes: 2 additions & 1 deletion tooling/create-tauri-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { vuecli } from './recipes/vue-cli'
import { vanillajs } from './recipes/vanilla'
import { vite } from './recipes/vite'
import { ngcli } from './recipes/ng-cli'
import { svelte } from './recipes/svelte'
import { install, checkPackageManager } from './dependency-manager'
import { shell } from './shell'
import { addTauriScript } from './helpers/add-tauri-script'
Expand Down Expand Up @@ -114,7 +115,7 @@ interface Responses {
recipeName: string
}

const allRecipes: Recipe[] = [vanillajs, cra, vite, vuecli, ngcli]
const allRecipes: Recipe[] = [vanillajs, cra, vite, vuecli, ngcli, svelte]

const recipeByShortName = (name: string): Recipe | undefined =>
allRecipes.find((r) => r.shortName === name)
Expand Down
69 changes: 69 additions & 0 deletions tooling/create-tauri-app/src/recipes/svelte.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

import { join } from 'path'
import { shell } from '../shell'
import { Recipe } from '../types/recipe'

const svelte: Recipe = {
descriptiveName: {
name: 'Svelte (https://github.com/sveltejs/template)',
value: 'svelte'
},
shortName: 'svelte',
extraNpmDevDependencies: [],
extraNpmDependencies: [],
extraQuestions: () => {
return [
{
type: 'confirm',
name: 'typescript',
message: 'Enable Typescript?',
default: true,
loop: false
}
]
},
configUpdate: ({ cfg, packageManager }) => ({
...cfg,
distDir: `../public`,
devPath: 'http://localhost:5000',
beforeDevCommand: `${packageManager === 'yarn' ? 'yarn' : 'npm run'} dev`,
beforeBuildCommand: `${
packageManager === 'yarn' ? 'yarn' : 'npm run'
} build`
}),
preInit: async ({ cwd, cfg, answers }) => {
let typescript = false
if (answers) {
typescript = !!answers.typescript
}

await shell('npx', ['degit', 'sveltejs/template', `${cfg.appName}`], {
cwd
})

// Add Typescript
if (typescript) {
await shell('node', ['scripts/setupTypeScript.js'], {
cwd: join(cwd, cfg.appName)
})
}
},
postInit: async ({ cfg, packageManager }) => {
console.log(`
Your installation completed.
To start, run the dev script:
$ cd ${cfg.appName}
$ ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri ${
packageManager === 'npm' ? '-- ' : ''
}dev
`)

return await Promise.resolve()
}
}

export { svelte }

0 comments on commit 151c315

Please sign in to comment.