UNPKG

node-mac-recorder

Version:

Native macOS screen recording package for Node.js applications

89 lines (77 loc) • 2.4 kB
const { spawn } = require("child_process"); const fs = require("fs"); const path = require("path"); console.log("šŸ”Ø Installing node-mac-recorder...\n"); // Check if we're on macOS if (process.platform !== "darwin") { console.error("āŒ This package only works on macOS"); process.exit(1); } // Prefer prebuilds on supported platforms const prebuildPath = path.join( __dirname, "prebuilds", `darwin-${process.arch}`, "node.napi.node" ); if ( process.platform === "darwin" && process.arch === "arm64" && fs.existsSync(prebuildPath) ) { console.log("āœ… Using prebuilt binary:", prebuildPath); console.log("šŸŽ‰ node-mac-recorder is ready to use (no compilation needed)"); process.exit(0); } // Fallback to building from source console.log("šŸ” Checking Xcode Command Line Tools..."); const xcodebuild = spawn("xcode-select", ["--print-path"], { stdio: "pipe" }); xcodebuild.on("close", (code) => { if (code !== 0) { console.error("āŒ Xcode Command Line Tools not found!"); console.log("šŸ“¦ Please install with: xcode-select --install"); process.exit(1); } console.log("āœ… Xcode Command Line Tools found"); buildNativeModule(); }); function buildNativeModule() { console.log("\nšŸ—ļø Building native module..."); // Run node-gyp rebuild const nodeGyp = spawn("node-gyp", ["rebuild"], { stdio: "inherit", env: { ...process.env, npm_config_build_from_source: "true" }, }); nodeGyp.on("close", (code) => { if (code === 0) { console.log("\nāœ… Native module built successfully!"); console.log("šŸŽ‰ node-mac-recorder is ready to use"); // Check if build output exists const buildPath = path.join( __dirname, "build", "Release", "mac_recorder.node" ); if (fs.existsSync(buildPath)) { console.log("šŸ“ Native module location:", buildPath); } } else { console.error("\nāŒ Build failed with code:", code); console.log("\nšŸ”§ Troubleshooting:"); console.log( "1. Make sure Xcode Command Line Tools are installed: xcode-select --install" ); console.log("2. Check Node.js version (requires 14.0.0+)"); console.log("3. Try: npm run clean && npm run build"); process.exit(1); } }); nodeGyp.on("error", (error) => { console.error("\nāŒ Build error:", error.message); console.log( "\nšŸ“¦ Make sure node-gyp is installed: npm install -g node-gyp" ); process.exit(1); }); }