-
Notifications
You must be signed in to change notification settings - Fork 21
/
vite.config.ts
65 lines (53 loc) · 1.67 KB
/
vite.config.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
import yaml from '@rollup/plugin-yaml'
import { sveltekit } from '@sveltejs/kit/vite'
import fs from 'fs'
import yamljs from 'js-yaml'
import { loadEnv, type UserConfig } from 'vite'
async function fetch_github_data(gh_token: string) {
const auth = { headers: { Authorization: `token ${gh_token}` } }
const cv = yamljs.load(fs.readFileSync(`src/lib/oss.yml`, `utf8`))
for (const project of cv.projects) {
const handle = project.repo.replace(`https://github.com/`, ``)
const repo = await (
await fetch(`https://api.github.com/repos/${handle}`, auth)
).json()
project.stars = repo.stargazers_count
// fetch number of commits by contributor.login using repo contribs API
const contributors = await (
await fetch(`https://api.github.com/repos/${handle}/contributors`, auth)
).json()
const me = contributors.find(
(contributor: Record<string, unknown>) => contributor.login === `janosh`,
)
if (me) {
project.commits = me.contributions
}
const languages = await (
await fetch(`https://api.github.com/repos/${handle}/languages`, auth)
).json()
project.languages = Object.keys(languages)
}
fs.writeFileSync(`src/lib/oss.yml`, yamljs.dump(cv, { lineWidth: -1 }))
}
process.env = { ...process.env, ...loadEnv(``, process.cwd(), ``) }
const { gh_token } = process.env
if (gh_token) {
fetch_github_data(gh_token)
} else {
console.error(`No GitHub token found, skipping GitHub API calls`)
}
export default {
plugins: [sveltekit(), yaml()],
server: {
port: 3000,
fs: {
allow: [`..`],
},
},
preview: {
port: 3000,
},
ssr: {
noExternal: [`three`],
},
} satisfies UserConfig