forked from thoth-tech/SplashkitOnline
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.js
More file actions
98 lines (77 loc) · 3.32 KB
/
setup.js
File metadata and controls
98 lines (77 loc) · 3.32 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
NOTE: MAINTAIN PARITY WITH /Browser_IDE/setup.py
*/
const request = require('request');
const fs = require('fs');
const extract = require('extract-zip');
const path = require('path');
class RequiredFile {
constructor(repoPath, src, dst, onDownload = async () => {}){
this.repoPath = repoPath;
this.src = src;
this.dst = dst;
this.onDownload = onDownload;
}
async download(){
console.log("Downloading " + this.src + "...");
const dstFilePath = this.dst + "/" + path.basename(this.src);
let file = fs.createWriteStream(dstFilePath);
let requestPromise = new Promise((resolve, reject) => {
let req = request(this.repoPath + this.src);
req.pipe(file);
file.on('finish', () => {
resolve();
});
file.on('error', () => {
reject();
});
});
await requestPromise;
await this.onDownload();
let closePromise = new Promise((resolve, reject) => {
file.close((err) => {
if(err != null) reject();
resolve();
});
});
await closePromise;
}
}
const thothTechRepoPath = "http://github.com/thoth-tech/SplashkitOnline/raw/"
const WhyPenguinsRepoPath = "http://github.com/WhyPenguins/SplashkitOnline/raw/"
const jsRuntimeDir = "runtimes/javascript/bin"
const cxxCompilerDir = "compilers/cxx/bin"
const cxxRuntimeDir = "runtimes/cxx/bin"
const requiredFiles = [
// Language-agnostic files
new RequiredFile(thothTechRepoPath, "binaries/Browser_IDE/splashkit/splashkit_autocomplete.json", "splashkit"),
// JS files
new RequiredFile(thothTechRepoPath, "binaries/Browser_IDE/splashkit/SplashKitBackendWASM.js", jsRuntimeDir),
new RequiredFile(thothTechRepoPath, "binaries/Browser_IDE/splashkit/SplashKitBackendWASM.wasm", jsRuntimeDir),
// C++ files
new RequiredFile(WhyPenguinsRepoPath, "cxx-audio-support-binaries/Browser_IDE/compilers/cxx/bin/compiler.zip", cxxCompilerDir, async () => {
// Unpack and delete compiler.zip
console.log("Extracting " + cxxCompilerDir + "/compiler.zip" + "...");
await extract(cxxCompilerDir + "/compiler.zip", {dir: path.resolve(cxxCompilerDir)});
fs.unlinkSync(cxxCompilerDir + "/compiler.zip");
console.log("Extracted " + cxxCompilerDir + "/compiler.zip");
}),
new RequiredFile(WhyPenguinsRepoPath, "cxx-audio-support-binaries/Browser_IDE/compilers/cxx/bin/wasi-sysroot.zip", cxxCompilerDir),
new RequiredFile(WhyPenguinsRepoPath, "cxx-audio-support-binaries/Browser_IDE/runtimes/cxx/bin/SplashKitBackendWASMCPP.js", cxxRuntimeDir),
new RequiredFile(WhyPenguinsRepoPath, "cxx-audio-support-binaries/Browser_IDE/runtimes/cxx/bin/SplashKitBackendWASMCPP.worker.js", cxxRuntimeDir)
];
exports.run = async function(){
let alreadyExists = requiredFiles.filter((reqFile) => {
return fs.existsSync(reqFile.dst + "/" + path.basename(reqFile.src));
});
if(alreadyExists.length > 0){
return;
}
console.log("Setting up SplashKit Online pre-built dependencies...");
await Promise.all(requiredFiles.map((reqFile) => {
return (async () => {
await reqFile.download();
})();
}));
console.log("SplashKit Online setup complete!");
}