-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.js
54 lines (47 loc) · 1.73 KB
/
setup.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// This file is not required when running the project locally. Its purpose is to set up the
// AssemblyScript compiler when a new project has been loaded in WebAssembly Studio.
const CURRENT_URL = new URL(window.location.href);
const ASC_COMMMIT = CURRENT_URL.searchParams.get("asc") || "f8c87361ad1ebc92b06aae4386e056ed2e368f0a";
require.config({
paths: {
"binaryen": "https://cdn.jsdelivr.net/gh/AssemblyScript/[email protected]/index",
"assemblyscript": `https://cdn.jsdelivr.net/gh/nearprotocol/assemblyscript@${ASC_COMMMIT}/dist/assemblyscript`,
"near-assemblyscript/dist/asc": `https://cdn.jsdelivr.net/gh/nearprotocol/assemblyscript@${ASC_COMMMIT}/dist/asc`
}
});
logLn("Loading AssemblyScript compiler ...");
window.logLn = logLn;
Object.assign(window.StudioFs, {
readFileSync(path) {
const file = getProject().getFile(path);
return file ? file.data : null;
},
writeFileSync(path, contents) {
path = path.replace(/^\.\//, "");
const type = fileTypeForExtension(path.substring(path.lastIndexOf(".") + 1));
getProject().newFile(path, type, true).setData(contents);
},
existsSync(path) {
return !!getProject().getFile(path);
},
listDirSync(path) {
let dir = getProject().getFile(path);
if (dir == null) {
return dir;
}
assert(dir.type === "directory");
return dir.list();
},
mkdirSync(path) {
getProject().newDirectory(path);
}
});
require(["near-assemblyscript/dist/asc"], asc => {
Object.assign(window.AssemblyScriptCompiler, asc);
if (!window.process) {
window.process = {};
}
monaco.languages.typescript.typescriptDefaults.addExtraLib(asc.definitionFiles.assembly);
logLn("AssemblyScript compiler is ready!");
setupCallback();
});