Skip to content

Commit 3412f51

Browse files
feat: add download parser scripts
1 parent 6e36626 commit 3412f51

20 files changed

+25
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"dev": "vitepress dev website",
88
"dev-force": "vitepress dev website --force",
99
"build": "vue-tsc --noEmit && NODE_OPTIONS=--max_old_space_size=4096 vitepress build website",
10+
"download-parsers": "node --experimental-strip-types website/public/parsers/downloadParsers.mjs",
1011
"serve": "vitepress serve website"
1112
},
1213
"dependencies": {

website/_data/parsers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const parserPaths = {
2323
yaml: 'tree-sitter-yaml.wasm',
2424
}
2525

26-
export const repos = {
26+
export const repos: Record<string, string> = {
2727
bash: 'https://unpkg.com/tree-sitter-bash',
2828
c: 'https://unpkg.com/tree-sitter-c',
2929
cpp: 'https://unpkg.com/tree-sitter-cpp',
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { parserPaths, repos, versions } from '../../_data/parsers.ts'
2+
import fs from 'node:fs'
3+
4+
async function main() {
5+
const dirname = import.meta.dirname
6+
for (const [lang, path] of Object.entries(parserPaths)) {
7+
const repo = repos[lang]
8+
const version = versions[lang]
9+
if (!repo || !version) {
10+
console.error(`Missing repo or version for ${lang}`)
11+
continue
12+
}
13+
const url = `${repo}@v${version}/${path}`
14+
console.log(`Downloading ${lang} parser from ${url}`)
15+
const res = await fetch(url)
16+
const buffer = await res.arrayBuffer()
17+
const wasm = new Uint8Array(buffer)
18+
console.log(`Writing ${lang} parser to ${path}`)
19+
fs.writeFileSync(`${dirname}/${path}`, wasm)
20+
}
21+
}
22+
23+
main()
195 KB
Binary file not shown.
-67.1 KB
Binary file not shown.
295 KB
Binary file not shown.
236 KB
Binary file not shown.
14.6 KB
Binary file not shown.
-28.8 KB
Binary file not shown.
539 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)