-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (26 loc) · 1.04 KB
/
index.js
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
// @ts-check
import fetch from "node-fetch";
import fs from "node:fs";
/** @type {any} */
const meta = await fetch("https://api.github.com/repos/tree-sitter/tree-sitter/releases/latest").then(it => it.json());
const assets = meta?.assets;
if (Array.isArray(assets)) {
const js = assets.find(it => it.name === "tree-sitter.js");
const wasm = assets.find(it => it.name === "tree-sitter.wasm");
if (!js) {
throw new Error("tree-sitter.js not found");
}
if (!wasm) {
throw new Error("tree-sitter.wasm not found");
}
try { fs.mkdirSync("./main"); } catch {/* NOOP */};
let jsURL = js.browser_download_url;
const jsPromise = fetch(jsURL).then(it => it.arrayBuffer()).then(it => {
fs.writeFileSync("./main/treesitter.js", Buffer.from(it));
});
const wasmURL = wasm.browser_download_url;
const wasmPromise = fetch(wasmURL).then(it => it.arrayBuffer()).then(it => {
fs.writeFileSync("./main/treesitter.wasm", Buffer.from(it));
});
await Promise.all([jsPromise, wasmPromise]);
}