-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
40 lines (32 loc) · 1.2 KB
/
build.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
35
36
37
38
39
40
import { default as decompress } from 'decompress';
import * as fs from "node:fs";
const dataPath = new URL('data/', import.meta.url);
await fs.promises.mkdir(dataPath, { recursive: true });
async function buildDependency(url, name, stripLevel = null ) {
let response = await fetch(url);
let content = await response.arrayBuffer();
let entries = await decompress(Buffer.from(content), { strip: stripLevel });
let result = {};
for (let entry of entries) {
if (entry.type !== 'file') {
continue;
}
insertFile(result, entry.path, entry.data.toString('base64'));
}
await fs.promises.writeFile(new URL(`${name}.js`, dataPath), `export const ${name} = ${JSON.stringify(result)};`);
}
function insertFile(object, path, content) {
let parts = path.split('/');
let current = object;
for (let part of parts.slice(0, -1)) {
if (part === '') {
continue;
}
if (!current[part]) {
current[part] = {};
}
current = current[part];
}
current[parts.pop()] = content;
}
await buildDependency('https://codeload.github.com/SpyglassMC/vanilla-mcdoc/legacy.tar.gz/refs/heads/main', 'vanillaMcdoc', 1);