-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.js
More file actions
67 lines (54 loc) · 1.7 KB
/
install.js
File metadata and controls
67 lines (54 loc) · 1.7 KB
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
const { spawnSync } = require("child_process");
const fs = require("fs");
const path = require("path");
const os = require("os");
console.log("Falling back to manual build process...");
// Platform detection
const platform = os.platform();
const arch = os.arch();
console.log(`Building for ${platform}-${arch}`);
// Install libfido2 dependencies
console.log("Installing libfido2 dependencies...");
try {
require("./scripts/install-libfido2");
} catch (error) {
console.error("Failed to install libfido2:", error);
process.exit(1);
}
// Make sure binding directory exists
const bindingDir = path.join(__dirname, "binding", `${platform}-${arch}`);
if (!fs.existsSync(bindingDir)) {
fs.mkdirSync(bindingDir, { recursive: true });
}
// Build with node-gyp
console.log("Building native module...");
const buildResult = spawnSync("node-gyp", ["rebuild"], {
stdio: "inherit",
shell: true,
});
if (buildResult.status !== 0) {
console.error("Failed to build native module");
process.exit(1);
}
// Copy the built module to the right location
const buildDir = path.join(__dirname, "build", "Release");
const targetFile = path.join(bindingDir, "fido2.node");
try {
const sourceFile = path.join(buildDir, "fido2.node");
fs.copyFileSync(sourceFile, targetFile);
console.log(`Successfully copied binary to ${targetFile}`);
} catch (error) {
console.error("Failed to copy binary:", error);
process.exit(1);
}
// Build TypeScript code
console.log("Building TypeScript code...");
const tscResult = spawnSync("npx", ["tsc"], {
stdio: "inherit",
shell: true,
});
if (tscResult.status !== 0) {
console.error("Failed to build TypeScript code");
process.exit(1);
}
console.log("Installation completed successfully");