11// eslint-disable-next-line strict
22'use strict' ;
33const chalk = require ( 'chalk' ) ;
4- const childProcess = require ( 'child_process' ) ;
5- const download = require ( 'download' ) ;
64const fs = require ( 'fs' ) ;
75const _ = require ( 'lodash' ) ;
86const semver = require ( 'semver' ) ;
97const path = require ( 'path' ) ;
10- const { promisify } = require ( 'util' ) ;
118const normalizePkg = require ( 'normalize-package-data' ) ;
129const parseGitHubRepoURL = require ( 'parse-github-repo-url' ) ;
1310const ffmpegAfterExtract = require ( 'electron-packager-plugin-non-proprietary-codecs-ffmpeg' ) . default ;
1411const windowsInstallerVersion = require ( './windows-installer-version' ) ;
1512const debug = require ( 'debug' ) ( 'hadron-build:target' ) ;
16- const execFile = promisify ( childProcess . execFile ) ;
1713const which = require ( 'which' ) ;
1814const plist = require ( 'plist' ) ;
1915const { sign, getSignedFilename } = require ( './signtool' ) ;
2016const tarGz = require ( './tar-gz' ) ;
17+ const { notarize } = require ( './mac-notary-service' ) ;
2118
2219function _canBuildInstaller ( ext ) {
2320 var bin = null ;
@@ -562,7 +559,6 @@ class Target {
562559 } ;
563560
564561 this . createInstaller = async ( ) => {
565- const appDirectoryName = `${ this . productName } .app` ;
566562 const appPath = this . appPath ;
567563
568564 {
@@ -580,58 +576,32 @@ class Target {
580576 await fs . promises . writeFile ( plistFilePath , plist . build ( plistContents ) ) ;
581577 }
582578
583- if ( process . env . MACOS_NOTARY_KEY &&
584- process . env . MACOS_NOTARY_SECRET &&
585- process . env . MACOS_NOTARY_CLIENT_URL &&
586- process . env . MACOS_NOTARY_API_URL ) {
587- debug ( `Signing and notarizing "${ appPath } "` ) ;
588- // https://wiki.corp.mongodb.com/display/BUILD/How+to+use+MacOS+notary+service
589- debug ( `Downloading the notary client from ${ process . env . MACOS_NOTARY_CLIENT_URL } to ${ path . resolve ( 'macnotary' ) } ` ) ;
590- await download ( process . env . MACOS_NOTARY_CLIENT_URL , 'macnotary' , {
591- extract : true ,
592- strip : 1 // remove leading platform + arch directory
593- } ) ;
594- await fs . promises . chmod ( 'macnotary/macnotary' , 0o755 ) ; // ensure +x is set
579+ const isNotarizationPossible = process . env . MACOS_NOTARY_KEY &&
580+ process . env . MACOS_NOTARY_SECRET &&
581+ process . env . MACOS_NOTARY_CLIENT_URL &&
582+ process . env . MACOS_NOTARY_API_URL ;
595583
596- debug ( `running "zip -y -r '${ appDirectoryName } .zip' '${ appDirectoryName } '"` ) ;
597- await execFile ( 'zip' , [ '-y' , '-r' , `${ appDirectoryName } .zip` , appDirectoryName ] , {
598- cwd : path . dirname ( appPath )
599- } ) ;
600- debug ( `sending file to notary service (bundle id = ${ this . bundleId } )` ) ;
601- const macnotaryResult = await execFile ( path . resolve ( 'macnotary/macnotary' ) , [
602- '-t' , 'app' ,
603- '-m' , 'notarizeAndSign' ,
604- '-u' , process . env . MACOS_NOTARY_API_URL ,
605- '-b' , this . bundleId ,
606- '-f' , `${ appDirectoryName } .zip` ,
607- '-o' , `${ appDirectoryName } .signed.zip` ,
608- '--verify' ,
609- ...( this . macosEntitlements ? [ '-e' , this . macosEntitlements ] : [ ] )
610- ] , {
611- cwd : path . dirname ( appPath ) ,
612- encoding : 'utf8'
613- } ) ;
614- debug ( 'macnotary result:' , macnotaryResult . stdout , macnotaryResult . stderr ) ;
615- debug ( 'ls' , ( await execFile ( 'ls' , [ '-lh' ] , { cwd : path . dirname ( appPath ) , encoding : 'utf8' } ) ) . stdout ) ;
616- debug ( 'removing existing directory contents' ) ;
617- await execFile ( 'rm' , [ '-r' , appDirectoryName ] , {
618- cwd : path . dirname ( appPath )
619- } ) ;
620- debug ( `unzipping with "unzip -u '${ appDirectoryName } .signed.zip'"` ) ;
621- await execFile ( 'unzip' , [ '-u' , `${ appDirectoryName } .signed.zip` ] , {
622- cwd : path . dirname ( appPath ) ,
623- encoding : 'utf8'
624- } ) ;
625- debug ( 'ls' , ( await execFile ( 'ls' , [ '-lh' ] , { cwd : path . dirname ( appPath ) , encoding : 'utf8' } ) ) . stdout ) ;
626- debug ( `removing '${ appDirectoryName } .signed.zip' and '${ appDirectoryName } .zip'` ) ;
627- await fs . promises . unlink ( `${ appPath } .signed.zip` ) ;
628- await fs . promises . unlink ( `${ appPath } .zip` ) ;
584+ const notarizationOptions = {
585+ bundleId : this . bundleId ,
586+ macosEntitlements : this . macosEntitlements
587+ } ;
588+
589+ if ( isNotarizationPossible ) {
590+ await notarize ( appPath , notarizationOptions ) ;
629591 } else {
630592 console . error ( chalk . yellow . bold (
631- 'WARNING: macos notary service credentials not set -- skipping signing and notarization!' ) ) ;
593+ 'WARNING: macos notary service credentials not set -- skipping signing and notarization of .app !' ) ) ;
632594 }
595+
633596 const createDMG = require ( 'electron-installer-dmg' ) ;
634597 await createDMG ( this . installerOptions ) ;
598+
599+ if ( isNotarizationPossible ) {
600+ await notarize ( this . installerOptions . dmgPath , notarizationOptions ) ;
601+ } else {
602+ console . error ( chalk . yellow . bold (
603+ 'WARNING: macos notary service credentials not set -- skipping signing and notarization of .dmg!' ) ) ;
604+ }
635605 } ;
636606 }
637607
0 commit comments