@@ -73,6 +73,21 @@ class App {
73
73
return path . join ( this . originalResourcesDir , 'app.asar' )
74
74
}
75
75
76
+ get commonHookArgs ( ) {
77
+ return [
78
+ this . opts . electronVersion ,
79
+ this . opts . platform ,
80
+ this . opts . arch
81
+ ]
82
+ }
83
+
84
+ get hookArgsWithOriginalResourcesAppDir ( ) {
85
+ return [
86
+ this . originalResourcesAppDir ,
87
+ ...this . commonHookArgs
88
+ ]
89
+ }
90
+
76
91
async relativeRename ( basePath , oldName , newName ) {
77
92
debug ( `Renaming ${ oldName } to ${ newName } in ${ basePath } ` )
78
93
await fs . rename ( path . join ( basePath , oldName ) , path . join ( basePath , newName ) )
@@ -107,6 +122,8 @@ class App {
107
122
} else {
108
123
await this . buildApp ( )
109
124
}
125
+
126
+ await hooks . promisifyHooks ( this . opts . afterInitialize , this . hookArgsWithOriginalResourcesAppDir )
110
127
}
111
128
112
129
async buildApp ( ) {
@@ -116,20 +133,15 @@ class App {
116
133
}
117
134
118
135
async copyTemplate ( ) {
119
- const hookArgs = [
120
- this . originalResourcesAppDir ,
121
- this . opts . electronVersion ,
122
- this . opts . platform ,
123
- this . opts . arch
124
- ]
136
+ await hooks . promisifyHooks ( this . opts . beforeCopy , this . hookArgsWithOriginalResourcesAppDir )
125
137
126
138
await fs . copy ( this . opts . dir , this . originalResourcesAppDir , {
127
139
filter : copyFilter . userPathFilter ( this . opts ) ,
128
140
dereference : this . opts . derefSymlinks
129
141
} )
130
- await hooks . promisifyHooks ( this . opts . afterCopy , hookArgs )
142
+ await hooks . promisifyHooks ( this . opts . afterCopy , this . hookArgsWithOriginalResourcesAppDir )
131
143
if ( this . opts . prune ) {
132
- await hooks . promisifyHooks ( this . opts . afterPrune , hookArgs )
144
+ await hooks . promisifyHooks ( this . opts . afterPrune , this . hookArgsWithOriginalResourcesAppDir )
133
145
}
134
146
}
135
147
@@ -171,7 +183,7 @@ class App {
171
183
common . warning ( 'prebuiltAsar has been specified, all asar options will be ignored' )
172
184
}
173
185
174
- for ( const hookName of [ 'afterCopy' , 'afterPrune' ] ) {
186
+ for ( const hookName of [ 'beforeCopy' , ' afterCopy', 'afterPrune' ] ) {
175
187
if ( this . opts [ hookName ] ) {
176
188
throw new Error ( `${ hookName } is incompatible with prebuiltAsar` )
177
189
}
@@ -202,6 +214,9 @@ class App {
202
214
}
203
215
204
216
debug ( `Running asar with the options ${ JSON . stringify ( this . asarOptions ) } ` )
217
+
218
+ await hooks . promisifyHooks ( this . opts . beforeAsar , this . hookArgsWithOriginalResourcesAppDir )
219
+
205
220
await asar . createPackageWithOptions ( this . originalResourcesAppDir , this . appAsarPath , this . asarOptions )
206
221
const { headerString } = asar . getRawHeader ( this . appAsarPath )
207
222
this . asarIntegrity = {
@@ -211,16 +226,27 @@ class App {
211
226
}
212
227
}
213
228
await fs . remove ( this . originalResourcesAppDir )
229
+
230
+ await hooks . promisifyHooks ( this . opts . afterAsar , this . hookArgsWithOriginalResourcesAppDir )
214
231
}
215
232
216
233
async copyExtraResources ( ) {
217
234
if ( ! this . opts . extraResource ) return Promise . resolve ( )
218
235
219
236
const extraResources = common . ensureArray ( this . opts . extraResource )
220
237
238
+ const hookArgs = [
239
+ this . stagingPath ,
240
+ ...this . commonHookArgs
241
+ ]
242
+
243
+ await hooks . promisifyHooks ( this . opts . beforeCopyExtraResources , hookArgs )
244
+
221
245
await Promise . all ( extraResources . map (
222
246
resource => fs . copy ( resource , path . resolve ( this . stagingPath , this . resourcesDir , path . basename ( resource ) ) )
223
247
) )
248
+
249
+ await hooks . promisifyHooks ( this . opts . afterCopyExtraResources , hookArgs )
224
250
}
225
251
226
252
async move ( ) {
@@ -231,6 +257,15 @@ class App {
231
257
await fs . move ( this . stagingPath , finalPath )
232
258
}
233
259
260
+ if ( this . opts . afterComplete ) {
261
+ const hookArgs = [
262
+ finalPath ,
263
+ ...this . commonHookArgs
264
+ ]
265
+
266
+ await hooks . promisifyHooks ( this . opts . afterComplete , hookArgs )
267
+ }
268
+
234
269
return finalPath
235
270
}
236
271
}
0 commit comments