-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
278 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"create-tauri-app": patch | ||
--- | ||
|
||
Add initial `vite` support starting with `vue` and `vue-ts` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { Recipe } from ".."; | ||
import { join } from "path"; | ||
import { readdirSync } from "fs"; | ||
//@ts-ignore | ||
import scaffe from "scaffe"; | ||
import { shell } from "../shell"; | ||
import inquirer from "inquirer"; | ||
|
||
const afterViteCA = async ( | ||
cwd: string, | ||
appName: string, | ||
version: string, | ||
template: string | ||
) => { | ||
const templateDir = join(__dirname, `../src/templates/vite/${template}`); | ||
const variables = { | ||
name: appName, | ||
tauri_version: version, | ||
}; | ||
|
||
try { | ||
await scaffe.generate(templateDir, join(cwd, appName), { | ||
overwrite: true, | ||
variables, | ||
}); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
}; | ||
|
||
const vite: Recipe = { | ||
descriptiveName: "Vite backed recipe", | ||
shortName: "vite", | ||
configUpdate: ({ cfg, packageManager }) => ({ | ||
...cfg, | ||
distDir: `../dist`, | ||
devPath: "http://localhost:3000", | ||
beforeDevCommand: `${packageManager === "yarn" ? "yarn" : "npm run"} start`, | ||
beforeBuildCommand: `${ | ||
packageManager === "yarn" ? "yarn" : "npm run" | ||
} build`, | ||
}), | ||
extraNpmDevDependencies: [], | ||
extraNpmDependencies: [], | ||
preInit: async ({ cwd, cfg, packageManager }) => { | ||
try { | ||
const { template } = await inquirer.prompt([ | ||
{ | ||
type: "list", | ||
name: "template", | ||
message: "Which vite template would you like to use?", | ||
choices: readdirSync(join(__dirname, "../src/templates/vite")), | ||
default: "vue", | ||
}, | ||
]); | ||
|
||
// Vite creates the folder for you | ||
if (packageManager === "yarn") { | ||
await shell( | ||
"yarn", | ||
[ | ||
"create", | ||
"@vitejs/app", | ||
`${cfg.appName}`, | ||
"--template", | ||
`${template}`, | ||
], | ||
{ | ||
cwd, | ||
} | ||
); | ||
} else { | ||
await shell( | ||
"npm", | ||
[ | ||
"init", | ||
"@vitejs/app", | ||
`${cfg.appName}`, | ||
"--", | ||
"--template", | ||
`${template}`, | ||
], | ||
{ | ||
cwd, | ||
} | ||
); | ||
} | ||
|
||
const version = await shell("npm", ["view", "tauri", "version"], { | ||
stdio: "pipe", | ||
}); | ||
const versionNumber = version.stdout.trim(); | ||
await afterViteCA(cwd, cfg.appName, versionNumber, template); | ||
} catch (error) { | ||
if (error.isTtyError) { | ||
// Prompt couldn't be rendered in the current environment | ||
console.log( | ||
"It appears your terminal does not support interactive prompts. Using default values." | ||
); | ||
} else { | ||
// Something else went wrong | ||
console.error("An unknown error occurred:", error); | ||
} | ||
} | ||
}, | ||
postInit: async ({ packageManager }) => { | ||
console.log(` | ||
Your installation completed. | ||
To start, run ${packageManager === "yarn" ? "yarn" : "npm run"} tauri ${ | ||
packageManager === "npm" ? "--" : "" | ||
} dev | ||
`); | ||
}, | ||
}; | ||
|
||
export { vite }; |
36 changes: 36 additions & 0 deletions
36
tooling/create-tauri-app/src/templates/vite/vue-ts/src/App.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<template> | ||
<div> | ||
<img alt="Vue logo" src="./assets/logo.png" /> | ||
<img alt="Tauri logo" height="200" src="./assets/tauri.svg" /> | ||
</div> | ||
<HelloWorld msg="Hello Vue 3 + TypeScript + Vite + Tauri" /> | ||
<a | ||
style="color: #42b983;" | ||
href="https://tauri.studio" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
>Learn Tauri</a> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent } from 'vue' | ||
import HelloWorld from './components/HelloWorld.vue' | ||
export default defineComponent({ | ||
name: 'App', | ||
components: { | ||
HelloWorld | ||
} | ||
}) | ||
</script> | ||
|
||
<style> | ||
#app { | ||
font-family: Avenir, Helvetica, Arial, sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
text-align: center; | ||
color: #2c3e50; | ||
margin-top: 60px; | ||
} | ||
</style> |
21 changes: 21 additions & 0 deletions
21
tooling/create-tauri-app/src/templates/vite/vue-ts/src/assets/tauri.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions
16
tooling/create-tauri-app/src/templates/vite/vue-ts/src/assets/wordmark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.