-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
109 lines (96 loc) · 2.37 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
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
99
100
101
102
103
104
105
106
107
108
109
import fs from "fs"
import path from "path"
import ts from "typescript"
import * as odin from "./odin_build.js"
import * as sdk from "./sdk.js"
const filename = new URL(import.meta.url).pathname
const dirname = path.dirname(filename)
const sdk_js_path = path.join(dirname, "sdk.js")
const sdk_dts_path = path.join(dirname, "sdk.d.ts")
const sdk_map_path = path.join(dirname, "sdk.d.ts.map")
/** @type {ts.CompilerOptions} */
const ts_options = {
allowJs : true,
checkJs : true,
skipLibCheck : false,
maxNodeModuleJsDepth: 1,
emitDeclarationOnly : true,
noEmit : false,
noEmitOnError : false,
declaration : true,
declarationMap : true,
}
/** @type {odin.Options} */
const vet_options = {
vet: ["unused", "shadowing", "style", "semicolon"]
}
/** @type {odin.Options} */
const release_options = {
...vet_options,
o: "aggressive",
no_thread_local: true,
no_bounds_check: true,
disable_assert: true,
obfuscate_source_code_locations: true
}
const buildType = process.argv[2]
let code = 0
switch (buildType) {
case "cli": {
code = await odin.build("src", {
...vet_options,
out: "graphstate",
})
break
}
case "wasm": {
code = await odin.build("src", {
...vet_options,
out: "graphstate.wasm",
target: "freestanding_wasm32"
})
break
}
default:
case "release": {
const binary_build = odin.build("src", {
...release_options,
out: "graphstate",
microarch: "native"
})
const wasm_build = odin.build("src", {
...release_options,
out: "graphstate.wasm",
target: "freestanding_wasm32"
})
/* DTS */
// Remove old .d.ts files
if (fs.existsSync(sdk_dts_path)) fs.unlinkSync(sdk_dts_path)
if (fs.existsSync(sdk_map_path)) fs.unlinkSync(sdk_map_path)
// Emit d.ts files
const ts_program = ts.createProgram([sdk_js_path], ts_options)
ts_program.emit()
const [binary_code, wasm_code] = await Promise.all([binary_build, wasm_build])
code = binary_code || wasm_code
break
}
case "debug": {
code = await odin.build("src", {
...vet_options,
out: "graphstate",
debug: true
})
break
}
case "client": {
const schema_test = fs.readFileSync("schema_test.graphql", "utf8")
const queries = sdk.cli_generate_queries(schema_test)
if (queries instanceof Error) {
console.log(queries.message)
process.exit(1)
}
fs.writeFileSync('_client.js', queries)
break
}
}
process.exit(code)