electron_video_sdk_buildNode.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const fs = require('fs')
  2. const { execSync } = require('child_process')
  3. const { platform, arch } = process
  4. const pkgPath = './package.json'
  5. const pkg = fs.readFileSync(pkgPath)
  6. let pkgObject = JSON.parse(pkg)
  7. let electronPackage
  8. let electronVersion
  9. execSync('node scripts/utils/check_node_modules_installed.js', {stdio: [0, 1, 2]})
  10. try {
  11. execSync(`${platform == 'win32' ? 'python' : 'python3'} --version`, {stdio: [0, 1, 2]})
  12. } catch (error) {
  13. console.log('you have not installed python')
  14. }
  15. try {
  16. console.log('checking electron version...')
  17. electronPackage = execSync('npm ls electron').toString()
  18. } catch (error) {
  19. console.log('you have not installed electron')
  20. }
  21. if (electronPackage) {
  22. var packageList = electronPackage.split('@')
  23. electronVersion = packageList[packageList.length - 1].trim()
  24. console.log('electron version is', electronVersion)
  25. try {
  26. if (platform == 'darwin') {
  27. execSync(`node-gyp rebuild --target=${electronVersion} --arch=${arch} --dist-url=https://electronjs.org/headers`, {stdio: [0, 1, 2]})
  28. execSync('cp -Rf ./build/Release/zoomvideosdk.node ./sdk/mac', {stdio: [0, 1, 2]})
  29. execSync('cp -Rf ./build/Release/zoomvideosdk_libuv.node ./sdk/mac', {stdio: [0, 1, 2]})
  30. execSync('cp -Rf ./build/Release/zoomvideosdk_napi_util.node ./sdk/mac', {stdio: [0, 1, 2]})
  31. } else if (platform == 'linux') {
  32. execSync(`node-gyp rebuild --target=${electronVersion} --arch=${arch} --dist-url=https://electronjs.org/headers`, {stdio: [0, 1, 2]})
  33. execSync('cp -Rf ./build/Release/zoomvideosdk.node ./sdk/linux', {stdio: [0, 1, 2]})
  34. execSync('cp -Rf ./build/Release/zoomvideosdk_libuv.node ./sdk/linux', {stdio: [0, 1, 2]})
  35. execSync('cp -Rf ./build/Release/zoomvideosdk_napi_util.node ./sdk/linux', {stdio: [0, 1, 2]})
  36. } else if (platform == 'win32') {
  37. execSync(`node-gyp rebuild --target=${electronVersion} --arch=${arch} --dist-url=https://electronjs.org/headers --release --msvs_version=2019`, {stdio: [0, 1, 2]})
  38. }
  39. } catch (error) {
  40. console.log('rebuild .node files failed, please refer to README.md')
  41. }
  42. }
  43. pkgObject.config = {}
  44. fs.writeFileSync(pkgPath, JSON.stringify(pkgObject, null, 2))