Add svelte recipe to create-tauri-app (#2276) (#2279)

This commit is contained in:
Kris Scott
2021-07-22 14:26:57 -05:00
committed by GitHub
parent 74a278fcfc
commit 151c3157be
3 changed files with 76 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"create-tauri-app": patch
---
Add Svelte recipe using the official template.

View File

@@ -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'
@@ -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)

View File

@@ -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 }