1
- import { PlatformPackager , BuildInfo } from "./platformPackager"
1
+ import { PlatformPackager , BuildInfo , normalizeTargets } from "./platformPackager"
2
2
import { Platform , OsXBuildOptions } from "./metadata"
3
3
import * as path from "path"
4
4
import { Promise as BluebirdPromise } from "bluebird"
@@ -14,7 +14,7 @@ const __awaiter = require("./awaiter")
14
14
export default class OsXPackager extends PlatformPackager < OsXBuildOptions > {
15
15
codeSigningInfo : Promise < CodeSigningInfo >
16
16
17
- readonly target : Array < string >
17
+ readonly targets : Array < string >
18
18
19
19
constructor ( info : BuildInfo , cleanupTasks : Array < ( ) => Promise < any > > ) {
20
20
super ( info )
@@ -28,41 +28,45 @@ export default class OsXPackager extends PlatformPackager<OsXBuildOptions> {
28
28
this . codeSigningInfo = BluebirdPromise . resolve ( null )
29
29
}
30
30
31
- let target = this . customBuildOptions == null ? null : this . customBuildOptions . target
32
- if ( target != null ) {
33
- target = Array . isArray ( target ) ? target : [ target ]
34
- target = target . map ( it => it . toLowerCase ( ) . trim ( ) )
35
- for ( let t of target ) {
36
- if ( t !== "default" && t !== "dmg" && t !== "zip" && t !== "mas" ) {
37
- throw new Error ( "Unknown target: " + t )
31
+ const targets = normalizeTargets ( this . customBuildOptions == null ? null : this . customBuildOptions . target )
32
+ if ( targets != null ) {
33
+ for ( let target of targets ) {
34
+ if ( target !== "default" && target !== "dmg" && target !== "zip" && target !== "mas" && target !== "7z" ) {
35
+ throw new Error ( "Unknown target: " + target )
38
36
}
39
37
}
40
38
}
41
- this . target = target == null ? [ "default" ] : target
39
+ this . targets = targets == null ? [ "default" ] : targets
42
40
}
43
41
44
42
get platform ( ) {
45
43
return Platform . OSX
46
44
}
47
45
48
- protected computeAppOutDir ( outDir : string , arch : string ) : string {
49
- return this . target . includes ( "mas" ) ? path . join ( outDir , `${ this . appName } -mas-${ arch } ` ) : super . computeAppOutDir ( outDir , arch )
50
- }
46
+ async pack ( outDir : string , arch : string , postAsyncTasks : Array < Promise < any > > ) : Promise < any > {
47
+ const packOptions = this . computePackOptions ( outDir , arch )
48
+ let nonMasPromise : Promise < any > = null
49
+ if ( this . targets . length > 1 || this . targets [ 0 ] !== "mas" ) {
50
+ const appOutDir = this . computeAppOutDir ( outDir , arch )
51
+ nonMasPromise = this . doPack ( packOptions , outDir , appOutDir , arch )
52
+ . then ( ( ) => this . sign ( appOutDir , false ) )
53
+ . then ( ( ) => postAsyncTasks . push ( this . packageInDistributableFormat ( outDir , appOutDir , arch ) ) )
54
+ }
51
55
52
- async doPack ( outDir : string , appOutDir : string , arch : string ) : Promise < any > {
53
- await super . doPack ( outDir , appOutDir , arch )
54
- await this . sign ( appOutDir , await this . codeSigningInfo )
55
- }
56
+ if ( this . targets . includes ( "mas" ) ) {
57
+ // osx-sign - disable warning
58
+ const appOutDir = path . join ( outDir , `${ this . appName } -mas-${ arch } ` )
59
+ await this . doPack ( Object . assign ( { } , packOptions , { platform : "mas" , "osx-sign" : false } ) , outDir , appOutDir , arch )
60
+ await this . sign ( appOutDir , true )
61
+ }
56
62
57
- protected beforePack ( options : any ) : void {
58
- if ( this . target . includes ( "mas" ) ) {
59
- options . platform = "mas"
63
+ if ( nonMasPromise != null ) {
64
+ await nonMasPromise
60
65
}
61
- // disable warning
62
- options [ "osx-sign" ] = false
63
66
}
64
67
65
- private async sign ( appOutDir : string , codeSigningInfo : CodeSigningInfo ) : Promise < any > {
68
+ private async sign ( appOutDir : string , isMas : boolean ) : Promise < any > {
69
+ let codeSigningInfo = await this . codeSigningInfo
66
70
if ( codeSigningInfo == null ) {
67
71
codeSigningInfo = {
68
72
name : this . options . sign || process . env . CSC_NAME ,
@@ -77,7 +81,6 @@ export default class OsXPackager extends PlatformPackager<OsXBuildOptions> {
77
81
78
82
log ( "Signing app" )
79
83
80
- const isMas = this . target . includes ( "mas" )
81
84
const baseSignOptions : BaseSignOptions = {
82
85
app : path . join ( appOutDir , this . appName + ".app" ) ,
83
86
platform : isMas ? "mas" : "darwin"
@@ -133,10 +136,10 @@ export default class OsXPackager extends PlatformPackager<OsXBuildOptions> {
133
136
}
134
137
135
138
packageInDistributableFormat ( outDir : string , appOutDir : string , arch : string ) : Promise < any > {
136
- const artifactPath = path . join ( appOutDir , `${ this . appName } -${ this . metadata . version } .dmg` )
137
139
const promises : Array < Promise < any > > = [ ]
138
140
139
- if ( this . target . includes ( "dmg" ) || this . target . includes ( "default" ) ) {
141
+ if ( this . targets . includes ( "dmg" ) || this . targets . includes ( "default" ) ) {
142
+ const artifactPath = path . join ( appOutDir , `${ this . appName } -${ this . metadata . version } .dmg` )
140
143
promises . push ( new BluebirdPromise < any > ( async ( resolve , reject ) => {
141
144
log ( "Creating DMG" )
142
145
const dmgOptions = {
@@ -164,24 +167,34 @@ export default class OsXPackager extends PlatformPackager<OsXBuildOptions> {
164
167
. then ( ( ) => this . dispatchArtifactCreated ( artifactPath , `${ this . metadata . name } -${ this . metadata . version } .dmg` ) ) )
165
168
}
166
169
167
- if ( this . target . includes ( "zip" ) || this . target . includes ( "default" ) ) {
168
- promises . push ( this . zipMacApp ( appOutDir )
169
- . then ( it => this . dispatchArtifactCreated ( it , `${ this . metadata . name } -${ this . metadata . version } -mac.zip` ) ) )
170
+ for ( let target of this . targets ) {
171
+ if ( target !== "mas" && target !== "dmg" ) {
172
+ const format = target === "default" ? "zip" : target
173
+ log ( "Creating OS X " + format )
174
+ // for default we use mac to be compatible with Squirrel.Mac
175
+ const classifier = target === "default" ? "mac" : "osx"
176
+ promises . push ( this . archiveApp ( appOutDir , format , classifier )
177
+ . then ( it => this . dispatchArtifactCreated ( it , `${ this . metadata . name } -${ this . metadata . version } -${ classifier } .${ format } ` ) ) )
178
+ }
170
179
}
171
-
172
180
return BluebirdPromise . all ( promises )
173
181
}
174
182
175
- private zipMacApp ( outDir : string ) : Promise < string > {
176
- log ( "Creating ZIP for Squirrel.Mac" )
177
- // we use app name here - see https://github.com/electron-userland/electron-builder/pull/204
178
- const resultPath = `${ this . appName } -${ this . metadata . version } -mac.zip`
179
- const args = [ "a" , "-mm=" + ( this . devMetadata . build . compression === "store" ? "Copy" : "Deflate" ) , "-bb" + ( debug . enabled ? "3" : "0" ) , "-bd" ]
180
- if ( this . devMetadata . build . compression === "maximum" ) {
183
+ private archiveApp ( outDir : string , format : string , classifier : string ) : Promise < string > {
184
+ const args = [ "a" , "-bb" + ( debug . enabled ? "3" : "0" ) , "-bd" ]
185
+ const compression = this . devMetadata . build . compression
186
+ const storeOnly = compression === "store"
187
+ if ( format === "zip" || storeOnly ) {
188
+ args . push ( "-mm=" + ( storeOnly ? "Copy" : "Deflate" ) )
189
+ }
190
+ if ( compression === "maximum" ) {
181
191
// http://superuser.com/a/742034
182
192
//noinspection SpellCheckingInspection
183
193
args . push ( "-mfb=258" , "-mpass=15" )
184
194
}
195
+
196
+ // we use app name here - see https://github.com/electron-userland/electron-builder/pull/204
197
+ const resultPath = `${ this . appName } -${ this . metadata . version } -${ classifier } .${ format } `
185
198
args . push ( resultPath , this . appName + ".app" )
186
199
187
200
return spawn ( path7za , args , {
0 commit comments