@@ -14,6 +14,7 @@ import { safeDump } from "js-yaml"
14
14
import { createHash } from "crypto"
15
15
import { Target , Arch } from "electron-builder-core"
16
16
import sanitizeFileName from "sanitize-filename"
17
+ import { unlinkIfExists } from "electron-builder-util/out/fs"
17
18
18
19
const NSIS_VERSION = "3.0.4"
19
20
//noinspection SpellCheckingInspection
@@ -42,14 +43,25 @@ export default class NsisTarget extends Target {
42
43
}
43
44
}
44
45
45
- private computePublishConfigs ( ) : Promise < Array < PublishConfiguration > | null > {
46
- const publishConfigs = getPublishConfigs ( this . packager , this . options )
47
- if ( publishConfigs != null && publishConfigs . length > 0 ) {
48
- return BluebirdPromise . map ( publishConfigs , it => getResolvedPublishConfig ( this . packager . info , it , true ) )
46
+ private async computePublishConfigs ( ) : Promise < Array < PublishConfiguration > | null > {
47
+ let publishConfigs = getPublishConfigs ( this . packager , this . options )
48
+ if ( publishConfigs == null ) {
49
+ return null
49
50
}
50
- else {
51
- return BluebirdPromise . resolve ( null )
51
+
52
+ if ( publishConfigs . length === 0 ) {
53
+ // https://github.com/electron-userland/electron-builder/issues/925#issuecomment-261732378
54
+ // default publish config is github, file should be generated regardless of publish state (user can test installer locally or manage the release process manually)
55
+ const repositoryInfo = await this . packager . getRepositoryInfo ( )
56
+ if ( repositoryInfo != null && repositoryInfo . type === "github" ) {
57
+ publishConfigs = [ { provider : "github" } ]
58
+ }
59
+ else {
60
+ return null
61
+ }
52
62
}
63
+
64
+ return await BluebirdPromise . map ( publishConfigs , it => < Promise < PublishConfiguration > > getResolvedPublishConfig ( this . packager . info , it , true ) )
53
65
}
54
66
55
67
build ( appOutDir : string , arch : Arch ) {
@@ -226,36 +238,36 @@ export default class NsisTarget extends Target {
226
238
const publishConfigs = await this . publishConfigs
227
239
const githubArtifactName = `${ appInfo . name } -Setup-${ version } .exe`
228
240
if ( publishConfigs != null ) {
229
- let sha2 : string | null = null
230
241
for ( const publishConfig of publishConfigs ) {
231
- if ( publishConfig . provider === "generic" || publishConfig . provider === "github" ) {
232
- if ( sha2 == null ) {
233
- sha2 = await sha256 ( installerPath )
234
- }
242
+ if ( ! ( publishConfig . provider === "generic" || publishConfig . provider === "github" ) ) {
243
+ continue
244
+ }
235
245
236
- const channel = ( < GenericServerOptions > publishConfig ) . channel || "latest"
237
- if ( publishConfig . provider === "generic" ) {
238
- await writeFile ( path . join ( this . outDir , `${ channel } .yml` ) , safeDump ( < UpdateInfo > {
239
- version : version ,
240
- path : installerFilename ,
241
- sha2 : sha2 ,
242
- } ) )
243
- }
244
- else {
245
- packager . info . eventEmitter . emit ( "artifactCreated" , < ArtifactCreated > {
246
- data : new Buffer ( safeDump ( < UpdateInfo > {
247
- version : version ,
248
- path : githubArtifactName ,
249
- sha2 : sha2 ,
250
- } ) ) ,
251
- artifactName : `${ channel } .yml` ,
252
- packager : packager ,
253
- publishConfig : publishConfig ,
254
- } )
255
- }
246
+ const sha2 = await sha256 ( installerPath )
247
+ const channel = ( < GenericServerOptions > publishConfig ) . channel || "latest"
248
+ const updateInfoFile = path . join ( this . outDir , `${ channel } .yml` )
249
+ await writeFile ( updateInfoFile , safeDump ( < UpdateInfo > {
250
+ version : version ,
251
+ githubArtifactName : githubArtifactName ,
252
+ path : installerFilename ,
253
+ sha2 : sha2 ,
254
+ } ) )
255
+
256
+ const githubPublishConfig = publishConfigs . find ( it => it . provider === "github" )
257
+ if ( githubPublishConfig != null ) {
258
+ packager . info . eventEmitter . emit ( "artifactCreated" , < ArtifactCreated > {
259
+ file : updateInfoFile ,
260
+ packager : packager ,
261
+ publishConfig : githubPublishConfig ,
262
+ } )
256
263
}
264
+
265
+ break
257
266
}
258
267
}
268
+ else {
269
+ await unlinkIfExists ( path . join ( this . outDir , `latest.yml` ) )
270
+ }
259
271
260
272
packager . dispatchArtifactCreated ( installerPath , githubArtifactName )
261
273
}
0 commit comments