UNPKG

trtc-electron-sdk

Version:

trtc electron sdk

46 lines (40 loc) 1.57 kB
const { exec } = require('child_process'); const path = require('path'); const fs = require('fs'); const { arch, platform } = process; let retryCount = 0; const retryInterval = 5000; // ms const maxRetryCount = 60; function rsync() { if (platform === 'darwin') { const sourcePath = path.join(__dirname, `../../trtc-electron-sdk/build/mac-framework/${arch}/`); const targetPath = path.join(__dirname, '../../electron/dist/Electron.app/Contents/Frameworks'); if (targetPath.indexOf("node_modules") === -1) { // SDK 本身安装,不用同步动态库,直接退出 console.warn(`trtc-electron-sdk self install do not need 'rsync'`); return; } retryCount++; if (fs.existsSync(targetPath)) { const command = `rsync -a ${sourcePath} ${targetPath}`; console.log(command); exec(command); } else { if (retryCount <= maxRetryCount) { setTimeout(rsync, retryInterval); } else { const errorMessage = ` 'trtc-electron-sdk' 安装失败,请先确认 'Electron' 已安装,再执行 'npm install trtc-electron-sdk' 命令重新安装一次。 Failed to install trtc-electron-sdk correctly, please make sure that 'Electron' has been installed, then run 'npm install trtc-electron-sdk' command to try again. more detail: trtc-electron-sdk postinstall cwd: ${process.cwd()} __dirname: ${__dirname} sourcePath: ${sourcePath} targetPath: ${targetPath} `; console.error(errorMessage); } } } } rsync();