Skip to content

Commit 6f42f64

Browse files
authored
feat: add beforePack hook (#6176)
1 parent f45110c commit 6f42f64

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

.changeset/stale-candles-boil.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"app-builder-lib": minor
3+
---
4+
5+
feat: add `beforePack` hook to build process with the same payload interface as that of `afterPack`

packages/app-builder-lib/scheme.json

+14
Original file line numberDiff line numberDiff line change
@@ -6025,6 +6025,20 @@
60256025
],
60266026
"description": "The function (or path to file or module id) to be [run after all artifacts are build](#afterAllArtifactBuild)."
60276027
},
6028+
"beforePack": {
6029+
"anyOf": [
6030+
{
6031+
"typeof": "function"
6032+
},
6033+
{
6034+
"type": [
6035+
"null",
6036+
"string"
6037+
]
6038+
}
6039+
],
6040+
"description": "The function (or path to file or module id) to be [run before pack](#beforepack)"
6041+
},
60286042
"afterPack": {
60296043
"anyOf": [
60306044
{

packages/app-builder-lib/src/configuration.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ export interface Configuration extends PlatformSpecificBuildOptions {
195195
*/
196196
readonly framework?: string | null
197197

198+
readonly beforePack?: ((context: BeforePackContext) => Promise<any> | any) | string | null
199+
198200
/**
199201
* The function (or path to file or module id) to be [run after pack](#afterpack) (but before pack into distributable format and sign).
200202
*/
@@ -262,14 +264,16 @@ export interface Configuration extends PlatformSpecificBuildOptions {
262264
readonly removePackageKeywords?: boolean
263265
}
264266

265-
export interface AfterPackContext {
267+
interface PackContext {
266268
readonly outDir: string
267269
readonly appOutDir: string
268270
readonly packager: PlatformPackager<any>
269271
readonly electronPlatformName: string
270272
readonly arch: Arch
271273
readonly targets: Array<Target>
272274
}
275+
export type AfterPackContext = PackContext
276+
export type BeforePackContext = PackContext
273277

274278
export interface MetadataDirectories {
275279
/**

packages/app-builder-lib/src/platformPackager.ts

+12
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,18 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
201201
return
202202
}
203203

204+
const beforePack = resolveFunction(this.config.beforePack, "beforePack")
205+
if (beforePack != null) {
206+
await beforePack({
207+
appOutDir,
208+
outDir,
209+
arch,
210+
targets,
211+
packager: this,
212+
electronPlatformName: platformName,
213+
})
214+
}
215+
204216
await this.info.installAppDependencies(this.platform, arch)
205217

206218
if (this.info.cancellationToken.cancelled) {

0 commit comments

Comments
 (0)