-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathfetch_vendor_js.mjs
52 lines (43 loc) · 1.88 KB
/
fetch_vendor_js.mjs
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
/**
* Script to download all required vendor javascript files.
*/
import fs from "fs";
import path from "path";
import fetch from "node-fetch";
import { fileURLToPath } from "url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const TARGET_DIR = path.resolve(__dirname, "build/vendor");
const URLS = {
"base/js/utils.js":
"https://raw.githubusercontent.com/jupyter/notebook/master/notebook/static/base/js/utils.js",
"base/js/namespace.js":
"https://raw.githubusercontent.com/jupyter/notebook/master/notebook/static/base/js/namespace.js",
"base/js/events.js":
"https://raw.githubusercontent.com/jupyter/notebook/master/notebook/static/base/js/events.js",
"services/kernels/kernel.js":
"https://raw.githubusercontent.com/jupyter/notebook/master/notebook/static/services/kernels/kernel.js",
"services/kernels/comm.js":
"https://raw.githubusercontent.com/jupyter/notebook/master/notebook/static/services/kernels/comm.js",
"services/kernels/serialize.js":
"https://raw.githubusercontent.com/jupyter/notebook/master/notebook/static/services/kernels/serialize.js",
"mpl.js":
"https://raw.githubusercontent.com/matplotlib/matplotlib/main/lib/matplotlib/backends/web_backend/js/mpl.js",
};
async function fetchFile(fileName, url) {
const resp = await fetch(url);
const body = await resp.text();
const fullPath = `${TARGET_DIR}/${fileName}`;
const base = path.dirname(fullPath);
fs.mkdirSync(base, { recursive: true });
const stream = fs.createWriteStream(fullPath);
stream.once("open", function (fd) {
stream.write(body);
stream.end();
console.log(`Downloaded ${fileName}`);
});
}
// Ensure the target directory has been created
fs.mkdirSync(TARGET_DIR, { recursive: true });
for (const [fileName, url] of Object.entries(URLS)) {
fetchFile(fileName, url);
}