UNPKG

node-mac-recorder

Version:

Native macOS screen recording package for Node.js applications

136 lines (112 loc) โ€ข 4.09 kB
const { spawn } = require("child_process"); const fs = require("fs"); const path = require("path"); console.log("๐Ÿ”จ Building Electron-safe 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"); buildElectronSafeModule(); }); function buildElectronSafeModule() { console.log("\n๐Ÿ—๏ธ Building Electron-safe native module..."); console.log("๐Ÿ“ Using binding file: electron-safe-binding.gyp"); // Run node-gyp configure and build with electron-safe binding const nodeGyp = spawn( "node-gyp", ["configure", "build", "--binding_gyp_path=electron-safe-binding.gyp"], { stdio: "inherit", env: { ...process.env, npm_config_build_from_source: "true", ELECTRON_SAFE_BUILD: "1", }, } ); nodeGyp.on("close", (code) => { if (code === 0) { console.log("\nโœ… Electron-safe native module built successfully!"); console.log("๐ŸŽ‰ electron-safe mac-recorder is ready to use"); // Check if build output exists const buildPath = path.join( __dirname, "build", "Release", "mac_recorder_electron.node" ); if (fs.existsSync(buildPath)) { console.log("๐Ÿ“ Native module location:", buildPath); // Create a test file createElectronSafeTest(); } else { console.log("โš ๏ธ Native module file not found at expected location"); } } 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:electron-safe"); console.log( "4. Check that all Electron-safe source files exist in src/electron_safe/" ); 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); }); } function createElectronSafeTest() { const testContent = `const ElectronSafeMacRecorder = require('./electron-safe-index'); console.log('๐Ÿงช Testing Electron-safe Mac Recorder'); async function testElectronSafe() { try { const recorder = new ElectronSafeMacRecorder(); console.log('๐Ÿ“‹ Module info:', recorder.getModuleInfo()); // Test permissions const permissions = await recorder.checkPermissions(); console.log('๐Ÿ” Permissions:', permissions); // Test displays const displays = await recorder.getDisplays(); console.log('๐Ÿ“บ Displays:', displays.length); // Test windows const windows = await recorder.getWindows(); console.log('๐ŸชŸ Windows:', windows.length); // Test cursor position try { const cursor = recorder.getCursorPosition(); console.log('๐Ÿ–ฑ๏ธ Cursor:', cursor); } catch (e) { console.log('โš ๏ธ Cursor position error (normal in some environments):', e.message); } console.log('โœ… All basic tests passed - Electron-safe module is working!'); } catch (error) { console.error('โŒ Test failed:', error.message); process.exit(1); } } testElectronSafe(); `; fs.writeFileSync(path.join(__dirname, "test-electron-safe.js"), testContent); console.log("๐Ÿ“ Created test file: test-electron-safe.js"); console.log("๐ŸŽฏ Run: node test-electron-safe.js"); }