-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathbuild.js
50 lines (41 loc) · 1.2 KB
/
build.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
const fs = require("fs");
const path = require("path");
const { exec } = require("child_process");
const glob = require("glob");
const rimraf = require("rimraf");
async function main() {
const files = glob.sync("src/*.js");
rimraf.sync("docs");
fs.mkdirSync("docs");
let iframes = "";
promises = [];
for (const file of files) {
if (file.includes("commands.js") || file.includes("demo.js")) {
continue;
}
const target = path.basename(file).replace(".js", ".min.js");
console.log(`${file}...`);
promises.push(execPromise(`browserify ${file} -o docs/${target}`));
iframes += `<br>${path.basename(file).replace(".js", "")}<br>
<iframe
style="width: 700px; height: 300px; border: none"
srcdoc="<html><head><script src='${target}' defer></script></head><body></body></html>"
></iframe>`;
}
await Promise.all(promises);
const html = `
<html>
<body style="text-align: center">
${iframes}
</body>
</html>
`;
fs.writeFileSync("docs/index.html", html);
console.log("done");
}
main();
function execPromise(command) {
return new Promise(resolve => {
exec(command, resolve);
});
}