Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagecell
Path: blob/master/fetch_vendor_js.mjs
447 views
1
/**
2
* Script to download all required vendor javascript files.
3
*/
4
5
import fs from "fs";
6
import path from "path";
7
import fetch from "node-fetch";
8
import { fileURLToPath } from "url";
9
10
const __dirname = path.dirname(fileURLToPath(import.meta.url));
11
12
const TARGET_DIR = path.resolve(__dirname, "build/vendor");
13
14
const URLS = {
15
"jquery.min.js":
16
"https://code.jquery.com/jquery-3.7.1.min.js",
17
"base/js/utils.js":
18
"https://raw.githubusercontent.com/jupyter/nbclassic/master/nbclassic/static/base/js/utils.js",
19
"base/js/namespace.js":
20
"https://raw.githubusercontent.com/jupyter/nbclassic/master/nbclassic/static/base/js/namespace.js",
21
"base/js/events.js":
22
"https://raw.githubusercontent.com/jupyter/nbclassic/master/nbclassic/static/base/js/events.js",
23
"services/kernels/kernel.js":
24
"https://raw.githubusercontent.com/jupyter/nbclassic/master/nbclassic/static/services/kernels/kernel.js",
25
"services/kernels/comm.js":
26
"https://raw.githubusercontent.com/jupyter/nbclassic/master/nbclassic/static/services/kernels/comm.js",
27
"services/kernels/serialize.js":
28
"https://raw.githubusercontent.com/jupyter/nbclassic/master/nbclassic/static/services/kernels/serialize.js",
29
"mpl.js":
30
"https://raw.githubusercontent.com/matplotlib/matplotlib/main/lib/matplotlib/backends/web_backend/js/mpl.js",
31
};
32
33
async function fetchFile(fileName, url) {
34
const resp = await fetch(url);
35
const body = await resp.text();
36
37
const fullPath = `${TARGET_DIR}/${fileName}`;
38
const base = path.dirname(fullPath);
39
fs.mkdirSync(base, { recursive: true });
40
41
const stream = fs.createWriteStream(fullPath);
42
stream.once("open", function (fd) {
43
stream.write(body);
44
stream.end();
45
console.log(`Downloaded ${fileName}`);
46
});
47
}
48
49
// Ensure the target directory has been created
50
fs.mkdirSync(TARGET_DIR, { recursive: true });
51
52
for (const [fileName, url] of Object.entries(URLS)) {
53
fetchFile(fileName, url);
54
}
55
56