-
-
Notifications
You must be signed in to change notification settings - Fork 218
/
Copy pathinstall.js
59 lines (53 loc) · 1.26 KB
/
install.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
function cmakeTs() {
const cp = require("child_process")
// Run the build script to generate the addon.node file
console.log(
"Building addon node via cmake-ts (requires cmake, ninja, and the vcpkg dependencies)",
)
let cmakeTsPath = tryRequireResolve("cmake-ts/build/main.js")
if (cmakeTsPath === undefined) {
cmakeTsPath = tryRequireResolve("cmake-ts/build/main")
}
if (cmakeTsPath === undefined) {
throw new Error(
"Failed to find cmake-ts in cmake-ts/build/main.js or cmake-ts/build/main.js",
)
}
cp.execFileSync(process.execPath, [cmakeTsPath, "build"], {
stdio: "inherit",
})
}
/**
* Try to require resolve a path.
* @param {string} path
* @returns {string | undefined}
*/
function tryRequireResolve(path) {
try {
return require.resolve(path)
} catch (error) {
return undefined
}
}
/**
* Log a warning if the environment is not production.
* @param {string} message
*/
function devWarn(message) {
if (process.env.NODE_ENV !== "production") {
console.warn(message)
}
}
function main() {
if (process.env.npm_config_build_from_source === "true") {
cmakeTs()
} else {
try {
require("../lib/load-addon.js")
} catch (error) {
devWarn(error)
cmakeTs()
}
}
}
main()