1
+ import { CancellationToken } from "builder-util-runtime/out/CancellationToken"
2
+ import { executeFinally } from "builder-util/out/promise"
3
+ import { PublishOptions } from "electron-publish/out/publisher"
4
+ import { log } from "builder-util"
5
+ import { Packager } from "./packager"
6
+ import { PackagerOptions } from "./packagerApi"
7
+ import BluebirdPromise from "bluebird-lst"
8
+ import { PublishManager } from "./publish/PublishManager"
9
+
1
10
export { Packager , BuildResult } from "./packager"
2
11
export { PackagerOptions , ArtifactCreated } from "./packagerApi"
3
12
export { TargetConfiguration , Platform , Target , DIR_TARGET , BeforeBuildContext , SourceRepositoryInfo , TargetSpecificOptions , TargetConfigType , DEFAULT_TARGET , CompressionLevel } from "./core"
@@ -21,3 +30,46 @@ export { CancellationToken } from "builder-util-runtime"
21
30
export { PublishOptions , UploadTask } from "electron-publish"
22
31
export { PublishManager } from "./publish/PublishManager"
23
32
export { PlatformPackager } from "./platformPackager"
33
+ export { buildForge , ForgeOptions } from "./forge-maker"
34
+
35
+ export async function build ( options : PackagerOptions & PublishOptions , cancellationToken : CancellationToken = new CancellationToken ( ) ) : Promise < Array < string > > {
36
+ const packager = new Packager ( options , cancellationToken )
37
+
38
+ let electronDownloader : any = null
39
+ packager . electronDownloader = options => {
40
+ if ( electronDownloader == null ) {
41
+ electronDownloader = BluebirdPromise . promisify ( require ( "electron-download-tf" ) )
42
+ }
43
+ return electronDownloader ( options )
44
+ }
45
+
46
+ // because artifact event maybe dispatched several times for different publish providers
47
+ const artifactPaths = new Set < string > ( )
48
+ packager . artifactCreated ( event => {
49
+ if ( event . file != null ) {
50
+ artifactPaths . add ( event . file )
51
+ }
52
+ } )
53
+
54
+ const publishManager = new PublishManager ( packager , options )
55
+ const sigIntHandler = ( ) => {
56
+ log . warn ( "cancelled by SIGINT" )
57
+ cancellationToken . cancel ( )
58
+ publishManager . cancelTasks ( )
59
+ }
60
+ process . once ( "SIGINT" , sigIntHandler )
61
+
62
+ return await executeFinally ( packager . build ( ) . then ( ( ) => Array . from ( artifactPaths ) ) , errorOccurred => {
63
+ let promise : Promise < any >
64
+ if ( errorOccurred ) {
65
+ publishManager . cancelTasks ( )
66
+ promise = Promise . resolve ( null )
67
+ }
68
+ else {
69
+ promise = publishManager . awaitTasks ( )
70
+ }
71
+
72
+ return promise
73
+ . then ( ( ) => process . removeListener ( "SIGINT" , sigIntHandler ) )
74
+ } )
75
+ }
0 commit comments