1
1
// eslint-disable-next-line strict
2
2
'use strict' ;
3
3
const chalk = require ( 'chalk' ) ;
4
- const childProcess = require ( 'child_process' ) ;
5
- const download = require ( 'download' ) ;
6
4
const fs = require ( 'fs' ) ;
7
5
const _ = require ( 'lodash' ) ;
8
6
const semver = require ( 'semver' ) ;
9
7
const path = require ( 'path' ) ;
10
- const { promisify } = require ( 'util' ) ;
11
8
const normalizePkg = require ( 'normalize-package-data' ) ;
12
9
const parseGitHubRepoURL = require ( 'parse-github-repo-url' ) ;
13
10
const ffmpegAfterExtract = require ( 'electron-packager-plugin-non-proprietary-codecs-ffmpeg' ) . default ;
14
11
const windowsInstallerVersion = require ( './windows-installer-version' ) ;
15
12
const debug = require ( 'debug' ) ( 'hadron-build:target' ) ;
16
- const execFile = promisify ( childProcess . execFile ) ;
17
13
const which = require ( 'which' ) ;
18
14
const plist = require ( 'plist' ) ;
19
15
const { sign, getSignedFilename } = require ( './signtool' ) ;
20
16
const tarGz = require ( './tar-gz' ) ;
17
+ const { notarize } = require ( './mac-notary-service' ) ;
21
18
22
19
function _canBuildInstaller ( ext ) {
23
20
var bin = null ;
@@ -562,7 +559,6 @@ class Target {
562
559
} ;
563
560
564
561
this . createInstaller = async ( ) => {
565
- const appDirectoryName = `${ this . productName } .app` ;
566
562
const appPath = this . appPath ;
567
563
568
564
{
@@ -580,58 +576,32 @@ class Target {
580
576
await fs . promises . writeFile ( plistFilePath , plist . build ( plistContents ) ) ;
581
577
}
582
578
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 ;
595
583
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 ) ;
629
591
} else {
630
592
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 !' ) ) ;
632
594
}
595
+
633
596
const createDMG = require ( 'electron-installer-dmg' ) ;
634
597
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
+ }
635
605
} ;
636
606
}
637
607
0 commit comments