-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
62 lines (50 loc) · 1.68 KB
/
index.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
import execa from 'execa'
import fs from 'fs'
import fse from 'fs-extra'
import { dirname, join } from 'path'
import { getTSConfig, setTSConfig } from '../../../shared/ts-config'
import { AppBuilder } from '../../app-builder'
import { assetsStack } from '../../consts'
export class SvelteBuilder implements AppBuilder {
public name = 'Svelte'
public versions = [3, 4]
public foundation = 'svelte' as const
public async create(name: string, version: number) {
await execa('npm', [
'create', `svelte-with-args@3`, '-y',
'--',
'--name', name,
'--template', 'default',
'--types', 'typescript',
'--no-prettier', '--no-eslint', '--no-playwright', '--no-vitest'
], { stdio: 'inherit' })
await execa('npm', ['i'], { cwd: join(process.cwd(), name), stdio: 'inherit' })
const tsConfig = await getTSConfig(name)
tsConfig.compilerOptions.preserveValueImports = false
tsConfig.compilerOptions.importsNotUsedAsValues = 'preserve'
await setTSConfig(name, tsConfig)
await execa('npm', [
'--prefix', name, 'i',
`svelte@${version}`,
`@sveltejs/kit@latest`
], { stdio: 'inherit' })
}
async putAssets(name: string, version: number) {
name
version
const modules = join(assetsStack, 'svelte', 'modules')
const src = join(name, 'src')
await fse.copy(modules, src, {
recursive: true,
overwrite: 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 'build'
}
}