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