|
1 | | -const { spawnSync } = require('child_process'); |
2 | | -const { platform } = require('os'); |
3 | | -const fs = require('fs'); |
| 1 | +const { spawnSync } = require("child_process"); |
| 2 | +const { platform } = require("os"); |
| 3 | +const fs = require("fs"); |
4 | 4 |
|
5 | 5 | function runCommand(command, args, options = {}) { |
6 | | - const result = spawnSync(command, args, { |
7 | | - stdio: 'inherit', |
8 | | - shell: true, |
9 | | - ...options |
10 | | - }); |
| 6 | + const result = spawnSync(command, args, { |
| 7 | + stdio: "inherit", |
| 8 | + shell: true, |
| 9 | + ...options, |
| 10 | + }); |
11 | 11 |
|
12 | | - if (result.status !== 0) { |
13 | | - console.error(`Command failed: ${command} ${args.join(' ')}`); |
14 | | - process.exit(1); |
15 | | - } |
| 12 | + if (result.status !== 0) { |
| 13 | + console.error(`Command failed: ${command} ${args.join(" ")}`); |
| 14 | + process.exit(1); |
| 15 | + } |
16 | 16 |
|
17 | | - return result; |
| 17 | + return result; |
18 | 18 | } |
19 | 19 |
|
20 | 20 | function installLibvirtMac() { |
21 | | - console.log('Installing libvirt via Homebrew...'); |
22 | | - return runCommand('brew', ['install', 'libvirt']); |
| 21 | + console.log("Installing libvirt via Homebrew..."); |
| 22 | + return runCommand("brew", ["install", "libvirt"]); |
23 | 23 | } |
24 | 24 |
|
25 | 25 | function checkLibvirt() { |
26 | | - if (platform() === 'darwin') { |
27 | | - // Check if libvirt is installed on macOS |
28 | | - const result = spawnSync('brew', ['list', 'libvirt'], { stdio: 'pipe' }); |
29 | | - if (result.status !== 0) { |
30 | | - return installLibvirtMac(); |
31 | | - } |
| 26 | + if (platform() === "darwin") { |
| 27 | + // Check if libvirt is installed on macOS |
| 28 | + const result = spawnSync("brew", ["list", "libvirt"], { stdio: "pipe" }); |
| 29 | + if (result.status !== 0) { |
| 30 | + return installLibvirtMac(); |
| 31 | + } |
32 | 32 |
|
33 | | - return true; |
34 | | - } |
| 33 | + return true; |
| 34 | + } |
35 | 35 |
|
36 | | - if (platform() === 'linux') { |
37 | | - return true; |
38 | | - } |
| 36 | + if (platform() === "linux") { |
| 37 | + return true; |
| 38 | + } |
39 | 39 |
|
40 | | - // Add other platform checks as needed |
41 | | - return false; |
| 40 | + // Add other platform checks as needed |
| 41 | + return false; |
42 | 42 | } |
43 | 43 |
|
44 | 44 | async function build() { |
45 | | - try { |
46 | | - if (checkLibvirt()) { |
47 | | - console.log('Building native bindings...'); |
48 | | - // On macOS, we need to specify the libvirt include and lib paths from Homebrew |
49 | | - if (platform() === 'darwin') { |
50 | | - process.env.LIBVIRT_INCLUDE_DIR = '/opt/homebrew/include'; |
51 | | - process.env.LIBVIRT_LIB_DIR = '/opt/homebrew/lib'; |
52 | | - } |
| 45 | + try { |
| 46 | + if (checkLibvirt()) { |
| 47 | + console.log("Building native bindings..."); |
| 48 | + runCommand("pnpm", ["run", "build/native"]); |
53 | 49 |
|
54 | | - runCommand('npm', ['run', 'build/native'], { |
55 | | - env: { ...process.env } |
56 | | - }); |
| 50 | + console.log("Building TypeScript..."); |
| 51 | + runCommand("pnpm", ["run", "build/ts"]); |
| 52 | + } else { |
| 53 | + console.log( |
| 54 | + "Failed to install/find libvirt, building stub implementation..." |
| 55 | + ); |
| 56 | + runCommand("pnpm", ["run", "build/stub"]); |
57 | 57 |
|
58 | | - console.log('Building TypeScript...'); |
59 | | - runCommand('npm', ['run', 'build/ts']); |
60 | | - } else { |
61 | | - console.log('Failed to install/find libvirt, building stub implementation...'); |
62 | | - runCommand('npm', ['run', 'build/stub']); |
63 | | - |
64 | | - if (fs.existsSync('dist/stub.d.ts')) { |
65 | | - fs.copyFileSync('dist/stub.d.ts', 'dist/index.d.ts'); |
66 | | - fs.copyFileSync('dist/stub.js', 'dist/index.js'); |
67 | | - } else { |
68 | | - console.error('Stub build failed to generate files'); |
69 | | - process.exit(1); |
70 | | - } |
71 | | - } |
72 | | - } catch (error) { |
73 | | - console.error('Build failed:', error); |
74 | | - process.exit(1); |
75 | | - } |
| 58 | + if (fs.existsSync("dist/stub.d.ts")) { |
| 59 | + fs.copyFileSync("dist/stub.d.ts", "dist/index.d.ts"); |
| 60 | + fs.copyFileSync("dist/stub.js", "dist/index.js"); |
| 61 | + } else { |
| 62 | + console.error("Stub build failed to generate files"); |
| 63 | + process.exit(1); |
| 64 | + } |
| 65 | + } |
| 66 | + } catch (error) { |
| 67 | + console.error("Build failed:", error); |
| 68 | + process.exit(1); |
| 69 | + } |
76 | 70 | } |
77 | 71 |
|
78 | | -build().catch(error => { |
79 | | - console.error('Unhandled error:', error); |
80 | | - process.exit(1); |
| 72 | +build().catch((error) => { |
| 73 | + console.error("Unhandled error:", error); |
| 74 | + process.exit(1); |
81 | 75 | }); |
0 commit comments