node-mac-recorder
Version:
Native macOS screen recording package for Node.js applications
72 lines (61 loc) ⢠2.01 kB
JavaScript
const { spawn } = require("child_process");
const fs = require("fs");
const path = require("path");
console.log("šØ Building native macOS recorder module...\n");
// Check if we're on macOS
if (process.platform !== "darwin") {
console.error("ā This package only works on macOS");
process.exit(1);
}
// Check if Xcode Command Line Tools are installed
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);
});
}