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 = {
"jquery.min.js":
"https://code.jquery.com/jquery-3.7.1.min.js",
"base/js/utils.js":
"https://raw.githubusercontent.com/jupyter/nbclassic/master/nbclassic/static/base/js/utils.js",
"base/js/namespace.js":
"https://raw.githubusercontent.com/jupyter/nbclassic/master/nbclassic/static/base/js/namespace.js",
"base/js/events.js":
"https://raw.githubusercontent.com/jupyter/nbclassic/master/nbclassic/static/base/js/events.js",
"services/kernels/kernel.js":
"https://raw.githubusercontent.com/jupyter/nbclassic/master/nbclassic/static/services/kernels/kernel.js",
"services/kernels/comm.js":
"https://raw.githubusercontent.com/jupyter/nbclassic/master/nbclassic/static/services/kernels/comm.js",
"services/kernels/serialize.js":
"https://raw.githubusercontent.com/jupyter/nbclassic/master/nbclassic/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}`);
});
}
fs.mkdirSync(TARGET_DIR, { recursive: true });
for (const [fileName, url] of Object.entries(URLS)) {
fetchFile(fileName, url);
}