-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathvite.ts
More file actions
57 lines (48 loc) · 1.5 KB
/
vite.ts
File metadata and controls
57 lines (48 loc) · 1.5 KB
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
import execa from 'execa'
import fs from 'fs'
import fse from 'fs-extra'
import { dirname, join } from 'path'
import { AppBuilder } from '../../app-builder'
import { assetsCommon, assetsStack } from '../../consts'
export class ReactViteBuilder implements AppBuilder {
public name = 'React.js Vite'
public versions = [16, 17, 18, 19]
public foundation = 'react' as const
public async create(name: string, version: number) {
await execa('npm', ['create', 'vite@7', name, '--', '--template', 'react-ts'], { stdio: 'inherit' })
await execa('npm', [
'i',
`react@${version}`,
`react-dom@${version}`,
`@types/react@${version}`,
`@types/react-dom@${version}`
], { stdio: 'inherit', cwd: name })
}
async putAssets(name: string, version: number) {
const modules = join(assetsStack, 'react', 'modules', 'vite')
const src = join(name, 'src')
await fse.copy(assetsCommon, src, {
recursive: true,
overwrite: true
})
await fse.copy(modules, src, {
recursive: true,
overwrite: true,
filter(source) {
if (source.endsWith('main.tsx')) return version < 18
return true
}
})
}
async putScript(name: string, path: string, code: string) {
const scriptPath = join(name, 'src', 'rete', path)
await fs.promises.mkdir(dirname(scriptPath), { recursive: true })
await fs.promises.writeFile(scriptPath, code)
}
getStaticPath() {
return 'dist'
}
getBuildCommand(): string {
return 'build'
}
}