@@ -18,6 +18,7 @@ import {
18
18
} from "fs/promises" ;
19
19
import { EventEmitter } from "events" ;
20
20
21
+ import { debug , format } from "util" ;
21
22
import { MakerBase } from "@electron-forge/maker-base" ;
22
23
import sanitizeName from "@spacingbat3/lss" ;
23
24
@@ -34,6 +35,7 @@ import {
34
35
35
36
import type MakerAppImageConfig from "../types/config.d.ts" ;
36
37
import type { MakerMeta } from "./utils.js" ;
38
+ import type { DebugLoggerFunction } from "util" ;
37
39
38
40
const enum RemoteDefaults {
39
41
MirrorHost = 'https://github.com/AppImage/' ,
@@ -46,6 +48,18 @@ const enum RemoteDefaults {
46
48
FileName = "{{ filename }}-{{ arch }}" ,
47
49
}
48
50
51
+ const d :DebugLoggerFunction = ( ( ) => {
52
+ if ( debug ( "reforged:maker-appimage" ) . enabled || / (?: ^ | , ) (?: \* | r e f o r g e d : (?: \* | m a k e r - a p p i m a g e ) ) (?: $ | , ) /
53
+ . test ( process . env [ "DEBUG" ] ?? "" ) )
54
+ // Function that logs similarly to debugLog.
55
+ return ( ...args :unknown [ ] ) => console . error (
56
+ "@reforged/maker-appimage %o: %s" ,
57
+ process . pid ,
58
+ format ( ...args )
59
+ ) ;
60
+ // NO-OP function
61
+ return ( ) => { } ;
62
+ } ) ( )
49
63
50
64
/**
51
65
* An AppImage maker for Electron Forge.
@@ -90,8 +104,9 @@ export default class MakerAppImage extends MakerBase<MakerAppImageConfig> {
90
104
override requiredExternalBinaries :[ "mksquashfs" ] = [ "mksquashfs" ] ;
91
105
override isSupportedOnCurrentPlatform :( ) => true = ( ) => true ;
92
106
override async make ( {
93
- appName, dir, makeDir, packageJSON, targetArch
107
+ appName, dir, makeDir, packageJSON, targetArch, forgeConfig : forge
94
108
} : MakerMeta , ...vendorExt : unknown [ ] ) : Promise < [ AppImagePath :string ] > {
109
+ d ( "Initializing maker metadata." )
95
110
const {
96
111
actions, categories, compressor, genericName, flagsFile, type2runtime
97
112
} = ( this . config . options ?? { } ) ;
@@ -149,6 +164,7 @@ export default class MakerAppImage extends MakerBase<MakerAppImageConfig> {
149
164
runtime : Object . freeze ( {
150
165
data : fetch ( parseMirror ( `${ remote . mirror . runtime } ${ remote . dir } /${ remote . file } ` , currentTag , "runtime" ) )
151
166
. then ( response => {
167
+ d ( "Fetched AppImage runtime from mirror." )
152
168
if ( response . ok )
153
169
return response . arrayBuffer ( )
154
170
else
@@ -160,6 +176,7 @@ export default class MakerAppImage extends MakerBase<MakerAppImageConfig> {
160
176
AppRun : Object . freeze ( {
161
177
data : fetch ( parseMirror ( `${ remote . mirror . AppRun } ${ remote . dir } /${ remote . file } ` , currentTag , "AppRun" ) )
162
178
. then ( response => {
179
+ d ( "Fetched AppImage AppRun from mirror." )
163
180
if ( response . ok )
164
181
return response . arrayBuffer ( )
165
182
else
@@ -240,6 +257,7 @@ export default class MakerAppImage extends MakerBase<MakerAppImageConfig> {
240
257
)
241
258
}
242
259
const iconPath = icon ? resolve ( workDir , name + extname ( icon ) ) : undefined ;
260
+ d ( "Queuing asynchronous jobs batches." )
243
261
/** First-step jobs, which does not depend on any other job. */
244
262
const earlyJobs = [
245
263
// Create further directory tree (0,1,2)
@@ -249,9 +267,9 @@ export default class MakerAppImage extends MakerBase<MakerAppImageConfig> {
249
267
. then ( path => path ? mkdir ( path , { recursive : true , mode : 0o755 } ) . then ( ( ) => path ) : undefined ) ,
250
268
// Save `.desktop` to file (3)
251
269
sources . desktop
252
- . then ( data => writeFile (
270
+ . then ( data => ( d ( "Writing '.desktop' file to 'workDir'." ) , writeFile (
253
271
resolve ( workDir , productName + '.desktop' ) , data , { mode :0o755 , encoding : "utf-8" } )
254
- ) ,
272
+ ) ) ,
255
273
// Verify and save `AppRun` to file (4)
256
274
sources . AppRun . data
257
275
. then ( data => {
@@ -265,6 +283,7 @@ export default class MakerAppImage extends MakerBase<MakerAppImageConfig> {
265
283
if ( hash !== sources . AppRun . md5 )
266
284
throw new Error ( "AppRun hash mismatch." ) ;
267
285
}
286
+ d ( "Writing AppRun to file." )
268
287
return writeFile ( resolve ( workDir , 'AppRun' ) , buffer , { mode : 0o755 } ) ;
269
288
} ) ,
270
289
// Save icon to file and symlink it as `.DirIcon` (5)
@@ -284,7 +303,7 @@ export default class MakerAppImage extends MakerBase<MakerAppImageConfig> {
284
303
} ) ,
285
304
// Copy Electron app to AppImage directories
286
305
earlyJobs [ 0 ]
287
- . then ( ( ) => copyPath ( dir , directories . data , 0o755 ) ) ,
306
+ . then ( ( ) => ( d ( "Copying Electron app data." ) , copyPath ( dir , directories . data , 0o755 ) ) ) ,
288
307
// Copy icon to `usr` directory whenever possible
289
308
Promise . all ( [ earlyJobs [ 2 ] , earlyJobs [ 5 ] ] )
290
309
. then ( ( [ path ] ) => icon && path ?
@@ -294,8 +313,10 @@ export default class MakerAppImage extends MakerBase<MakerAppImageConfig> {
294
313
// Ensure that root folder has proper file mode
295
314
chmod ( workDir , 0o755 )
296
315
] as const ;
316
+ d ( "Waiting for queued jobs to finish." )
297
317
// Wait for early/late jobs to finish
298
318
await ( Promise . all ( [ ...earlyJobs , ...lateJobs ] ) ) ;
319
+ d ( "Preparing 'mksquashfs' arguments for data image generation." )
299
320
// Run `mksquashfs` and wait for it to finish
300
321
const mkSquashFsArgs = [ workDir , outFile ] ;
301
322
const mkSquashFsVer = getSquashFsVer ( ) ;
@@ -325,6 +346,7 @@ export default class MakerAppImage extends MakerBase<MakerAppImageConfig> {
325
346
"-b" ,
326
347
"16384"
327
348
) ;
349
+ d ( "Queuing 'mksquashfs' task." )
328
350
await new Promise ( ( resolve , reject ) => {
329
351
this . ensureFile ( outFile ) . then ( ( ) => {
330
352
const evtCh = mkSquashFs ( ...mkSquashFsArgs )
@@ -340,6 +362,7 @@ export default class MakerAppImage extends MakerBase<MakerAppImageConfig> {
340
362
evtCh . on ( "progress" , percent => vndCh . emit ( "progress" , percent ) ) ;
341
363
} ) . catch ( error => reject ( error ) ) ;
342
364
} ) ;
365
+ d ( "Merging AppImage data and runtime into single file." )
343
366
// Append runtime to SquashFS image and wait for that task to finish
344
367
await sources . runtime . data
345
368
//TODO: Find how properly embed MD5 or SHA256 signatures
0 commit comments