forked from tempoxyz/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
77 lines (65 loc) · 2.2 KB
/
vite.config.ts
File metadata and controls
77 lines (65 loc) · 2.2 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import * as fs from 'node:fs/promises'
import * as path from 'node:path'
import react from '@vitejs/plugin-react'
import { Instance } from 'prool'
import { defineConfig, type Plugin } from 'vite'
import { vocs } from 'vocs/vite'
// https://vite.dev/config/
export default defineConfig({
plugins: [syncTips(), vocs(), react(), tempoNode()],
})
function tempoNode(): Plugin {
return {
name: 'tempo-node',
async configureServer(_server) {
if (!('VITE_TEMPO_ENV' in process.env) || process.env.VITE_TEMPO_ENV !== 'localnet') return
const instance = Instance.tempo({
dev: { blockTime: '500ms' },
port: 8545,
})
console.log('→ starting tempo node...')
await instance.start()
console.log('√ tempo node started on port 8545')
},
}
}
function syncTips(): Plugin {
const repo = 'tempoxyz/tempo'
const outputDir = 'src/pages/protocol/tips'
let synced = false
async function sync() {
if (synced) return
synced = true
console.log('→ syncing TIPs from GitHub...')
const res = await fetch(`https://api.github.com/repos/${repo}/contents/tips`)
if (!res.ok) {
console.error('✗ failed to fetch TIPs directory:', res.statusText)
return
}
const files = (await res.json()) as Array<{ name: string; download_url: string; type: string }>
const tipFiles = files.filter((f) => f.type === 'file' && /^tip-\d+\.md$/.test(f.name))
await fs.mkdir(outputDir, { recursive: true })
await Promise.all(
tipFiles.map(async (file) => {
let content = await fetch(file.download_url).then((r) => r.text())
// Fix dead links in TIPs that reference local paths instead of GitHub URLs
content = content.replace(
/\(tips\/ref-impls\/src\/interfaces\/(\w+\.sol)\)/g,
'(https://github.com/tempoxyz/tempo-std/blob/master/src/interfaces/$1)',
)
const outputPath = path.join(outputDir, file.name.replace('.md', '.mdx'))
await fs.writeFile(outputPath, content)
}),
)
console.log(`√ synced ${tipFiles.length} TIPs`)
}
return {
name: 'sync-tips',
async buildStart() {
await sync()
},
async configureServer() {
await sync()
},
}
}