-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
vite.ts
127 lines (121 loc) · 3.2 KB
/
vite.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
/// import { join } from 'path'
/// import scaffe from 'scaffe'
import { shell } from '../shell'
import { Recipe } from '../types/recipe'
const afterViteCA = async (
cwd: string,
appName: string,
template: string
): Promise<void> => {
// template dir temp removed, will eventually add it back for APIs
// leaving this here until then
// const templateDir = join(__dirname, `../src/templates/vite/${template}`)
// try {
// await scaffe.generate(templateDir, join(cwd, appName), {
// overwrite: true
// })
// } catch (err) {
// console.log(err)
// }
}
const vite: Recipe = {
descriptiveName: {
name: '@vitejs/create-app (https://vitejs.dev/guide/#scaffolding-your-first-vite-project)',
value: 'vite-create-app'
},
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: [],
extraQuestions: ({ ci }) => {
return [
{
type: 'list',
name: 'template',
message: 'Which vite template would you like to use?',
choices: [
'vanilla',
'vanilla-ts',
'vue',
'vue-ts',
'react',
'react-ts',
'preact',
'preact-ts',
'lit-element',
'lit-element-ts',
'svelte',
'svelte-ts'
],
default: 'vue',
loop: false,
when: !ci
}
]
},
preInit: async ({ cwd, cfg, packageManager, answers }) => {
let template = 'vue'
if (answers) {
template = answers.template ? (answers.template as string) : 'vue'
}
// Vite creates the folder for you
if (packageManager === 'yarn') {
await shell(
'yarn',
[
'create',
'@vitejs/app',
`${cfg.appName}`,
'--template',
`${template}`
],
{
cwd
}
)
} else {
await shell(
'npx',
[
'@vitejs/create-app@latest',
`${cfg.appName}`,
'--template',
`${template}`
],
{
cwd
}
)
}
await afterViteCA(cwd, cfg.appName, template)
},
postInit: async ({ cwd, packageManager }) => {
// we don't have a consistent way to rebuild and
// esbuild has hit all the bugs and struggles to install on the postinstall
await shell('node', ['./node_modules/esbuild/install.js'], { cwd })
if (packageManager === 'yarn') {
await shell('yarn', ['build'], { cwd })
} else {
await shell('npm', ['run', 'build'], { cwd })
}
console.log(`
Your installation completed. Change directories to \`${cwd}\`.
To start, run ${packageManager === 'yarn' ? 'yarn' : 'npm run'} tauri ${
packageManager === 'npm' ? '--' : ''
} dev
`)
return await Promise.resolve()
}
}
export { vite }