Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add beforePack hook #6176

Merged
merged 2 commits into from Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -5820,6 +5820,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