Skip to content

Commit

Permalink
feat: add beforePack hook
Browse files Browse the repository at this point in the history
  • Loading branch information
gaodeng committed Aug 23, 2021
1 parent 7dd33bc commit f511bca
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
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

0 comments on commit f511bca

Please sign in to comment.