artifactBuildCompleted.mjs 932 B

12345678910111213141516171819202122232425262728293031
  1. import { notarize } from '@electron/notarize'
  2. import path from 'node:path'
  3. import { isEnvFlagEnabled } from '../libs/build-env.mjs'
  4. import { getNotarizeOptions } from './notarize-options.mjs'
  5. export default async function artifactBuildCompleted(context) {
  6. const { file, packager } = context
  7. if (!file || path.extname(file) !== '.dmg') {
  8. return
  9. }
  10. if (packager?.platform?.name !== 'mac') {
  11. return
  12. }
  13. if (process.env.MAKE_FOR === 'dev' || isEnvFlagEnabled(process.env.SKIP_NOTARIZATION)) {
  14. console.log(`skip notarization for ${path.basename(file)}.`)
  15. return
  16. }
  17. const options = await getNotarizeOptions(file)
  18. if (!options) {
  19. throw new Error(`Notarization credentials are missing for ${path.basename(file)}.`)
  20. }
  21. console.log('in artifactBuildCompleted, notarize dmg...')
  22. console.log(`dmgPath: ${file}`)
  23. await notarize(options)
  24. console.log(`Notarize done for ${path.basename(file)}.`)
  25. }