-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
37 lines (35 loc) · 1.33 KB
/
main.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
// 1. config requirejs
const packages = __VAR_JSON__.dependencies
const oldLoad = requirejs.load
requirejs.load = function (context, id, url) {
if (id in packages) {
url = packages[id]
}
return oldLoad.call(requirejs, context, id, url)
}
// 2. declarations config
// please remove it before sandbox exports.
// api docs:https://github.com/Saber2pr/editor/blob/master/docs/script.md
if (top !== self) {
if (!top._finished) {
top.LOADING.init()
const typescriptVersion = top.monaco.languages.typescript.typescriptVersion
console.log(`[<span style="color:blue;">Typescript Version:${typescriptVersion}</span>]`)
console.log('--- wait for types fetching... ---')
const info = m => `<span style="background:lightskyblue">${m}</span>`
const types = __VAR_JSON__.types
const names = Object.keys(types)
const count = names.length
let index = 0
Promise.all(names.map(name => top.api_addModuleDeclaration(types[name], name.startsWith('global:') ? null : name)
.then(() =>
console.log(`type(${++index}/${count}): ${info(`[${name}]`)} fetched`))))
.then(() => {
console.log(`--- types fetching finished. ---`)
top.LOADING.destroy()
})
top._finished = true
}
}
// 3. enjoy it!
console.log(__VAR_JSON__.name, new Date().toLocaleString())