@@ -9,6 +9,7 @@ import { filterCFBundleIdentifier } from "../appInfo"
9
9
import { findIdentity , Identity } from "../codeSign/macCodeSign"
10
10
import { Target } from "../core"
11
11
import MacPackager from "../macPackager"
12
+ import { readdirSync } from "fs"
12
13
13
14
const certType = "Developer ID Installer"
14
15
@@ -144,8 +145,9 @@ export class PkgTarget extends Target {
144
145
const plistInfo = ( await executeAppBuilderAsJson < Array < any > > ( [ "decode-plist" , "-f" , propertyListOutputFile ] ) ) [ 0 ] . filter (
145
146
( it : any ) => it . RootRelativeBundlePath !== "Electron.dSYM"
146
147
)
148
+ let packageInfo : any = { }
147
149
if ( plistInfo . length > 0 ) {
148
- const packageInfo = plistInfo [ 0 ]
150
+ packageInfo = plistInfo [ 0 ]
149
151
150
152
// ChildBundles lists all of electron binaries within the .app.
151
153
// There is no particular reason for removing that key, except to be as close as possible to
@@ -167,22 +169,35 @@ export class PkgTarget extends Target {
167
169
if ( options . overwriteAction != null ) {
168
170
packageInfo . BundleOverwriteAction = options . overwriteAction
169
171
}
170
-
171
- await executeAppBuilderAndWriteJson ( [ "encode-plist" ] , { [ propertyListOutputFile ] : plistInfo } )
172
172
}
173
173
174
174
// now build the package
175
175
const args = [ "--root" , rootPath , "--identifier" , this . packager . appInfo . id , "--component-plist" , propertyListOutputFile ]
176
176
177
177
use ( this . options . installLocation || "/Applications" , it => args . push ( "--install-location" , it ) )
178
- if ( options . scripts != null ) {
179
- args . push ( "--scripts" , path . resolve ( this . packager . info . buildResourcesDir , options . scripts ) )
180
- } else if ( options . scripts !== null ) {
181
- const dir = path . join ( this . packager . info . buildResourcesDir , "pkg-scripts" )
182
- const stat = await statOrNull ( dir )
183
- if ( stat != null && stat . isDirectory ( ) ) {
184
- args . push ( "--scripts" , dir )
185
- }
178
+
179
+ // nasty nested ternary-statement, probably should optimize
180
+ const scriptsDir =
181
+ // user-provided scripts dir
182
+ options . scripts != null
183
+ ? path . resolve ( this . packager . info . buildResourcesDir , options . scripts )
184
+ : // fallback to default unless user explicitly sets null
185
+ options . scripts !== null
186
+ ? path . join ( this . packager . info . buildResourcesDir , "pkg-scripts" )
187
+ : null
188
+ if ( scriptsDir && ( await statOrNull ( scriptsDir ) ) ?. isDirectory ( ) ) {
189
+ const dirContents = readdirSync ( scriptsDir )
190
+ dirContents . forEach ( name => {
191
+ if ( name . includes ( "preinstall" ) ) {
192
+ packageInfo . BundlePreInstallScriptPath = name
193
+ } else if ( name . includes ( "postinstall" ) ) {
194
+ packageInfo . BundlePostInstallScriptPath = name
195
+ }
196
+ } )
197
+ args . push ( "--scripts" , scriptsDir )
198
+ }
199
+ if ( plistInfo . length > 0 ) {
200
+ await executeAppBuilderAndWriteJson ( [ "encode-plist" ] , { [ propertyListOutputFile ] : plistInfo } )
186
201
}
187
202
188
203
args . push ( packageOutputFile )
0 commit comments