@@ -2,6 +2,17 @@ var VersionInfo = require('./lib/versionInfo')
2
2
var execute = require ( './lib/execute' )
3
3
var format = require ( 'util' ) . format
4
4
var path = require ( 'path' )
5
+ var fs = require ( 'fs' )
6
+
7
+ const fileExists = ( path ) => new Promise ( ( resolve , reject ) => fs . access ( path , ( err , exists ) => {
8
+ resolve ( ! err )
9
+ } ) )
10
+ const execPromise = ( cmd ) => new Promise ( ( resolve , reject ) => {
11
+ execute ( cmd , { } , err => {
12
+ if ( err ) return reject ( err )
13
+ resolve ( )
14
+ } )
15
+ } )
5
16
6
17
const isWindows = process . platform === 'win32'
7
18
const isDarwin = process . platform === 'darwin'
@@ -105,27 +116,48 @@ if (isDarwin) {
105
116
'python tools/signature_generator.py --input_file "' + wvBundle + '" --output_file "' + wvBundleSig + '" --flag 1' ,
106
117
'python tools/signature_generator.py --input_file "' + wvPlugin + '"' ,
107
118
108
- // Sign it
119
+ // Sign it (requires Apple 'Developer ID Application' certificate installed in keychain)
109
120
'cd ' + buildDir + `/${ appName } .app/Contents/Frameworks` ,
110
121
'codesign --deep --force --strict --verbose --sign $IDENTIFIER *' ,
111
122
'cd ../../..' ,
112
123
`codesign --deep --force --strict --verbose --sign $IDENTIFIER ${ appName } .app/` ,
113
124
114
- // Package it into a dmg or package
125
+ // Package it into a dmg and/ or package
115
126
'cd ..' ,
116
127
'build ' +
117
- ' --prepackaged="' + buildDir + ` /${ appName } .app" ` +
118
- ` --config=res/${ channel } /builderConfig.json ` ,
128
+ ` --prepackaged="${ buildDir } /${ appName } .app" ` +
129
+ `--config=res/${ channel } /builderConfig.json ` ,
119
130
120
131
// Create an update zip
121
132
'ditto -c -k --sequesterRsrc --keepParent ' + buildDir + `/${ appName } .app dist/${ appName } -` + VersionInfo . braveVersion + '.zip'
122
133
]
123
- execute ( cmds , { } , ( err ) => {
134
+ execute ( cmds , { } , async ( err ) => {
124
135
if ( err ) {
125
136
raiseError ( 'building installer failed: ' + JSON . stringify ( err ) )
126
137
return
127
138
}
128
139
140
+ // sign pkg if it exists (requires Apple 'Developer ID Installer' certificate installed in keychain)
141
+ const fileName = `${ appName } -${ VersionInfo . braveVersion } `
142
+ const packagePath = path . join ( outDir , `${ fileName } .pkg` )
143
+ const packagePathUnsigned = path . join ( outDir , `${ fileName } _unsigned.pkg` )
144
+
145
+ const pkgExists = await fileExists ( packagePath )
146
+ if ( pkgExists ) {
147
+ console . log ( `Signing pkg at ${ packagePath } ` )
148
+ try {
149
+ await execPromise ( [
150
+ `mv ${ packagePath } ${ packagePathUnsigned } ` ,
151
+ `productsign --sign ${ identifier } ${ packagePathUnsigned } ${ packagePath } ` ,
152
+ `rm ${ packagePathUnsigned } `
153
+ ] )
154
+ console . log ( `pkg signing complete` )
155
+ } catch ( e ) {
156
+ console . error ( 'Error signing pkg:' )
157
+ raiseError ( e )
158
+ return
159
+ }
160
+ }
129
161
console . log ( 'done' )
130
162
} )
131
163
} else if ( isWindows ) {
0 commit comments