-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.js
69 lines (60 loc) · 1.7 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const { execSync } = require("child_process")
const fs = require("fs")
const path = require("path")
const { finished } = require("stream/promises")
const { Readable } = require("stream")
const getAllFiles = function (dirPath, arrayOfFiles) {
files = fs.readdirSync(dirPath)
arrayOfFiles = arrayOfFiles || []
files.forEach(function (file) {
if (fs.statSync(dirPath + "/" + file).isDirectory()) {
arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles)
} else {
arrayOfFiles.push(path.join(__dirname, dirPath, "/", file))
}
})
return arrayOfFiles
}
let tests = []
for (let path of getAllFiles("../test/tests/nattlua/analyzer/")) {
if (path.endsWith(".nlua")) {
tests.push(fs.readFileSync(path).toString())
} else {
let data = fs.readFileSync(path).toString()
let matches = data.matchAll(/analyze\s*\[\[(.*?)\]\]/gms)
for (let match of matches) {
tests.push(match[1])
}
}
}
fs.writeFileSync("src/random.json", JSON.stringify(tests))
;(async () => {
const res = await fetch("https://unpkg.com/[email protected]/dist/glue.wasm")
fs.unlink("public/glue.wasm", (err) => {
if (err) {
console.error(err)
}
})
const fileStream = fs.createWriteStream("public/glue.wasm", { flags: "wx" })
await finished(Readable.fromWeb(res.body).pipe(fileStream))
})()
execSync("cd ../ && luajit nattlua.lua build fast")
require("esbuild")
.build({
format: "iife",
platform: "node",
entryPoints: {
app: "src/index.ts",
"editor.worker": "monaco-editor/esm/vs/editor/editor.worker.js",
},
entryNames: "[name].bundle",
loader: "expose-loader",
bundle: true,
outdir: "public/",
loader: {
".ttf": "dataurl",
".lua": "text",
".nlua": "text",
},
})
.catch(() => process.exit(1))