Skip to content

Commit

Permalink
feat: add beforePack hook (#6176)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaodeng committed Aug 25, 2021
1 parent f45110c commit 6f42f64
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/stale-candles-boil.md
@@ -0,0 +1,5 @@
---
"app-builder-lib": minor
---

feat: add `beforePack` hook to build process with the same payload interface as that of `afterPack`
14 changes: 14 additions & 0 deletions packages/app-builder-lib/scheme.json
Expand Up @@ -6025,6 +6025,20 @@
],
"description": "The function (or path to file or module id) to be [run after all artifacts are build](#afterAllArtifactBuild)."
},
"beforePack": {
"anyOf": [
{
"typeof": "function"
},
{
"type": [
"null",
"string"
]
}
],
"description": "The function (or path to file or module id) to be [run before pack](#beforepack)"
},
"afterPack": {
"anyOf": [
{
Expand Down
6 changes: 5 additions & 1 deletion packages/app-builder-lib/src/configuration.ts
Expand Up @@ -195,6 +195,8 @@ export interface Configuration extends PlatformSpecificBuildOptions {
*/
readonly framework?: string | null

readonly beforePack?: ((context: BeforePackContext) => Promise<any> | any) | string | null

/**
* The function (or path to file or module id) to be [run after pack](#afterpack) (but before pack into distributable format and sign).
*/
Expand Down Expand Up @@ -262,14 +264,16 @@ export interface Configuration extends PlatformSpecificBuildOptions {
readonly removePackageKeywords?: boolean
}

export interface AfterPackContext {
interface PackContext {
readonly outDir: string
readonly appOutDir: string
readonly packager: PlatformPackager<any>
readonly electronPlatformName: string
readonly arch: Arch
readonly targets: Array<Target>
}
export type AfterPackContext = PackContext
export type BeforePackContext = PackContext

export interface MetadataDirectories {
/**
Expand Down
12 changes: 12 additions & 0 deletions packages/app-builder-lib/src/platformPackager.ts
Expand Up @@ -201,6 +201,18 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
return
}

const beforePack = resolveFunction(this.config.beforePack, "beforePack")
if (beforePack != null) {
await beforePack({
appOutDir,
outDir,
arch,
targets,
packager: this,
electronPlatformName: platformName,
})
}

await this.info.installAppDependencies(this.platform, arch)

if (this.info.cancellationToken.cancelled) {
Expand Down

0 comments on commit 6f42f64

Please sign in to comment.