Skip to content

Commit e7ff5e8

Browse files
committed
feat: afterAllArtifactBuild hook
Close electron-userland#3116
1 parent 1ce3a89 commit e7ff5e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+230
-121
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ See documentation on [electron.build](https://www.electron.build).
1414
* [macOS](https://www.electron.build/configuration/mac): `dmg`, `pkg`, `mas`.
1515
* [Linux](https://www.electron.build/configuration/linux): [AppImage](http://appimage.org), [snap](http://snapcraft.io), debian package (`deb`), `rpm`, `freebsd`, `pacman`, `p5p`, `apk`.
1616
* [Windows](https://www.electron.build/configuration/win): `nsis` (Installer), `nsis-web` (Web installer), `portable` (portable app without installation), AppX (Windows Store), MSI, Squirrel.Windows.
17-
* [Build version management](https://www.electron.build/configuration/configuration#build-version-management).
1817
* [Publishing artifacts](https://www.electron.build/configuration/publish) to GitHub Releases, Amazon S3, DigitalOcean Spaces and Bintray.
1918
* Advanced building:
2019
* Pack in a distributable format [already packaged app](https://www.electron.build/#pack-only-in-a-distributable-format).

docs/configuration/appx.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Inherited from `TargetSpecificOptions`:
1616

1717
* <code id="AppXOptions-artifactName">artifactName</code> String - The [artifact file name template](/configuration/configuration.md#artifact-file-name-template).
1818
* <code id="AppXOptions-publish">publish</code> The [publish](/configuration/publish.md) options.
19+
1920
<!-- end of generated block -->
2021

2122
## AppX Package Code Signing

docs/configuration/configuration.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,21 @@ Env file `electron-builder.env` in the current dir ([example](https://github.com
119119

120120
---
121121

122-
* <code id="Configuration-afterPack">afterPack</code> (context: AfterPackContext) => Promise | null - The function (or path to file or module id) to be run after pack (but before pack into distributable format and sign). See [example](/hooks.md#afterpack).
123-
124-
---
125-
126-
* <code id="Configuration-afterSign">afterSign</code> (context: AfterPackContext) => Promise | null - The function (or path to file or module id) to be run after pack and sign (but before pack into distributable format). See [example](/hooks.md#aftersign).
127-
* <code id="Configuration-onNodeModuleFile">onNodeModuleFile</code> module:electron-builder-lib/out/configuration.__type | String - The function (or path to file or module id) to be run on each node module file.
122+
* <code id="Configuration-afterPack">afterPack</code> - The function (or path to file or module id) to be [run after pack](#afterpack) (but before pack into distributable format and sign).
123+
* <code id="Configuration-afterSign">afterSign</code> - The function (or path to file or module id) to be [run after pack and sign](#aftersign) (but before pack into distributable format).
124+
* <code id="Configuration-afterAllArtifactBuild">afterAllArtifactBuild</code> - The function (or path to file or module id) to be [run after all artifacts are build](#afterAllArtifactBuild).
125+
* <code id="Configuration-onNodeModuleFile">onNodeModuleFile</code> - The function (or path to file or module id) to be [run on each node module](#onnodemodulefile) file.
128126
* <code id="Configuration-beforeBuild">beforeBuild</code> (context: BeforeBuildContext) => Promise | null - The function (or path to file or module id) to be run before dependencies are installed or rebuilt. Works when `npmRebuild` is set to `true`. Resolving to `false` will skip dependencies install or rebuild.
129127

130128
If provided and `node_modules` are missing, it will not invoke production dependencies check.
131129

130+
131+
---
132+
132133
* <code id="Configuration-remoteBuild">remoteBuild</code> = `true` Boolean - Whether to build using Electron Build Service if target not supported on current OS.
133134
* <code id="Configuration-includePdb">includePdb</code> = `false` Boolean - Whether to include PDB files.
134135
* <code id="Configuration-removePackageScripts">removePackageScripts</code> = `true` Boolean - Whether to remove `scripts` field from `package.json` files.
136+
135137
<!-- end of generated block -->
136138

137139
---
@@ -152,3 +154,5 @@ Currently, only macOS and Linux supported.
152154

153155
## Build Version Management
154156
`CFBundleVersion` (macOS) and `FileVersion` (Windows) will be set automatically to `version.build_number` on CI server (Travis, AppVeyor, CircleCI and Bamboo supported).
157+
158+
{!includes/hooks.md!}

docs/configuration/dmg.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Inherited from `TargetSpecificOptions`:
2828

2929
* <code id="DmgOptions-artifactName">artifactName</code> String - The [artifact file name template](/configuration/configuration.md#artifact-file-name-template).
3030
* <code id="DmgOptions-publish">publish</code> The [publish](/configuration/publish.md) options.
31+
3132
<!-- end of generated block -->
3233

3334
## DMG License

docs/configuration/linux.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The top-level [linux](configuration.md#Configuration-linux) key contains set of
1616
* <code id="LinuxConfiguration-category">category</code> String - The [application category](https://specifications.freedesktop.org/menu-spec/latest/apa.html#main-category-registry).
1717
* <code id="LinuxConfiguration-mimeTypes">mimeTypes</code> Array&lt;String&gt; - The mime types in addition to specified in the file associations. Use it if you don't want to register a new mime type, but reuse existing.
1818
* <code id="LinuxConfiguration-desktop">desktop</code> any - The [Desktop file](https://developer.gnome.org/integration-guide/stable/desktop-files.html.en) entries (name to value).
19+
1920
<!-- end of generated block -->
2021

2122
## Debian Package Options

docs/configuration/mac.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ The top-level [mac](configuration.md#Configuration-mac) key contains set of opti
2929
1.0.0 latest-mac.json 2.15.0 path 2.16.0 files
3030

3131
* <code id="MacConfiguration-electronLanguages">electronLanguages</code> Array&lt;String&gt; | String - The electron locales. By default Electron locales used as is.
32+
3233
<!-- end of generated block -->

docs/configuration/mas.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ Inherits [macOS options](mac.md).
55
* <code id="MasConfiguration-entitlements">entitlements</code> String - The path to entitlements file for signing the app. `build/entitlements.mas.plist` will be used if exists (it is a recommended way to set). Otherwise [default](https://github.com/electron-userland/electron-osx-sign/blob/master/default.entitlements.mas.plist).
66
* <code id="MasConfiguration-entitlementsInherit">entitlementsInherit</code> String - The path to child entitlements which inherit the security settings for signing frameworks and bundles of a distribution. `build/entitlements.mas.inherit.plist` will be used if exists (it is a recommended way to set). Otherwise [default](https://github.com/electron-userland/electron-osx-sign/blob/master/default.entitlements.mas.inherit.plist).
77
* <code id="MasConfiguration-binaries">binaries</code> Array&lt;String&gt; - Paths of any extra binaries that need to be signed.
8+
89
<!-- end of generated block -->

docs/configuration/nsis.md

+16-14
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ To build web installer, set [target](/configuration/win.md#WindowsConfiguration-
2626
To customize web installer, use the top-level `nsisWeb` key (not `nsis`).
2727

2828
If for some reasons web installer cannot download (antivirus, offline):
29+
2930
* Download package file into the same directory where installer located. It will be detected automatically and used instead of downloading from the Internet. Please note — only original package file is allowed (checksum is checked).
3031
* Specify any local package file using `--package-file=path_to_file`.
3132

@@ -80,19 +81,20 @@ It is also important to set the Application User Model ID (AUMID) to the [appId]
8081
---
8182

8283
## Common Questions
83-
#### How do change the default installation directory to custom?
84-
85-
It is very specific requirement. Do not do if you are not sure. Add [custom macro](#custom-nsis-script):
86-
87-
```nsis
88-
!macro preInit
89-
SetRegView 64
90-
WriteRegExpandStr HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
91-
WriteRegExpandStr HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
92-
SetRegView 32
93-
WriteRegExpandStr HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
94-
WriteRegExpandStr HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
95-
!macroend
96-
```
84+
85+
??? question "How do change the default installation directory to custom?"
86+
87+
It is very specific requirement. Do not do if you are not sure. Add [custom macro](#custom-nsis-script):
88+
89+
```nsis
90+
!macro preInit
91+
SetRegView 64
92+
WriteRegExpandStr HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
93+
WriteRegExpandStr HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
94+
SetRegView 32
95+
WriteRegExpandStr HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
96+
WriteRegExpandStr HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
97+
!macroend
98+
```
9799

98100

docs/configuration/pkg.md

+1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ Inherited from `TargetSpecificOptions`:
3333

3434
* <code id="PkgOptions-artifactName">artifactName</code> String - The [artifact file name template](/configuration/configuration.md#artifact-file-name-template).
3535
* <code id="PkgOptions-publish">publish</code> The [publish](/configuration/publish.md) options.
36+
3637
<!-- end of generated block -->

docs/configuration/publish.md

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ Inherited from `PublishConfiguration`:
145145
Auto update relies only on the first provider in the list (you can specify several publishers). Thus, probably, there`s no need to upload the metadata files for the other configured providers. But by default will be uploaded.
146146

147147

148+
148149
<!-- end of generated block -->
149150

150151
## S3Options

docs/configuration/snap.md

+1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ Inherited from `TargetSpecificOptions`:
3636

3737
* <code id="SnapOptions-artifactName">artifactName</code> String - The [artifact file name template](/configuration/configuration.md#artifact-file-name-template).
3838
* <code id="SnapOptions-publish">publish</code> The [publish](/configuration/publish.md) options.
39+
3940
<!-- end of generated block -->

docs/configuration/squirrel-windows.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ Inherited from `TargetSpecificOptions`:
2222

2323
* <code id="SquirrelWindowsOptions-artifactName">artifactName</code> String - The [artifact file name template](/configuration/configuration.md#artifact-file-name-template).
2424
* <code id="SquirrelWindowsOptions-publish">publish</code> The [publish](/configuration/publish.md) options.
25+
2526
<!-- end of generated block -->

docs/configuration/target.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ build -wl
3131
<!-- do not edit. start of generated block -->
3232
* **<code id="TargetConfiguration-target">target</code>** String - The target name. e.g. `snap`.
3333
* <code id="TargetConfiguration-arch">arch</code> Array&lt;"x64" | "ia32" | "armv7l" | "arm64"&gt; | "x64" | "ia32" | "armv7l" | "arm64" - The arch or list of archs.
34+
3435
<!-- end of generated block -->

docs/configuration/win.md

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ The top-level [win](configuration.md#Configuration-win) key contains set of opti
3333

3434
1.0.0 sha2 2.15.0 path 2.16.0 files
3535

36+
3637
<!-- end of generated block -->
3738

3839
---

docs/generated/DebOptions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
* <code id="DebOptions-depends">depends</code> Array&lt;String&gt; - Package dependencies. Defaults to `["gconf2", "gconf-service", "libnotify4", "libappindicator1", "libxtst6", "libnss3"]`.
22
* <code id="DebOptions-packageCategory">packageCategory</code> String - The [package category](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Section).
3-
* <code id="DebOptions-priority">priority</code> String - The [Priority](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Priority) attribute.
3+
* <code id="DebOptions-priority">priority</code> String - The [Priority](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Priority) attribute.

docs/generated/LinuxTargetSpecificOptions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ Inherited from `CommonLinuxOptions`:
2222
Inherited from `TargetSpecificOptions`:
2323

2424
* <code id="LinuxTargetSpecificOptions-artifactName">artifactName</code> String - The [artifact file name template](/configuration/configuration.md#artifact-file-name-template).
25-
* <code id="LinuxTargetSpecificOptions-publish">publish</code> The [publish](/configuration/publish.md) options.
25+
* <code id="LinuxTargetSpecificOptions-publish">publish</code> The [publish](/configuration/publish.md) options.

docs/generated/Metadata.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
* <code id="AuthorMetadata-email">email</code> String
1111
* <code id="Metadata-repository">repository</code> String | RepositoryInfo<a name="RepositoryInfo"></a> - The [repository](https://docs.npmjs.com/files/package.json#repository).
1212
* **<code id="RepositoryInfo-url">url</code>** String
13-
* <code id="Metadata-build">build</code> [Configuration](#configuration) - The electron-builder configuration.
13+
* <code id="Metadata-build">build</code> [Configuration](#configuration) - The electron-builder configuration.

docs/generated/NsisOptions.md

+1
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,5 @@
5252
* <code id="NsisOptions-createStartMenuShortcut">createStartMenuShortcut</code> = `true` Boolean - Whether to create start menu shortcut.
5353
* <code id="NsisOptions-menuCategory">menuCategory</code> = `false` Boolean | String - Whether to create submenu for start menu shortcut and program files directory. If `true`, company name will be used. Or string value.
5454
* <code id="NsisOptions-shortcutName">shortcutName</code> String - The name that will be used for all shortcuts. Defaults to the application name.
55+
5556
<!-- end of generated block -->

docs/generated/PlatformSpecificBuildOptions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@
4343
* <code id="ReleaseInfo-releaseNotes">releaseNotes</code> String - The release notes.
4444
* <code id="ReleaseInfo-releaseNotesFile">releaseNotesFile</code> String - The path to release notes file. Defaults to `release-notes-${platform}.md` (where `platform` it is current platform — `mac`, `linux` or `windows`) or `release-notes.md` in the [build resources](#MetadataDirectories-buildResources).
4545
* <code id="ReleaseInfo-releaseDate">releaseDate</code> String - The release date.
46-
* <code id="PlatformSpecificBuildOptions-target">target</code> String | [TargetConfiguration](/configuration/target.md#targetconfiguration)
46+
* <code id="PlatformSpecificBuildOptions-target">target</code> String | [TargetConfiguration](/configuration/target.md#targetconfiguration)
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
* <code id="TargetSpecificOptions-artifactName">artifactName</code> String - The [artifact file name template](/configuration/configuration.md#artifact-file-name-template).
2-
* <code id="TargetSpecificOptions-publish">publish</code> The [publish](/configuration/publish.md) options.
2+
* <code id="TargetSpecificOptions-publish">publish</code> The [publish](/configuration/publish.md) options.

docs/generated/appimage-options.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ Inherited from `CommonLinuxOptions`:
1212
Inherited from `TargetSpecificOptions`:
1313

1414
* <code id="AppImageOptions-artifactName">artifactName</code> String - The [artifact file name template](/configuration/configuration.md#artifact-file-name-template).
15-
* <code id="AppImageOptions-publish">publish</code> The [publish](/configuration/publish.md) options.
15+
* <code id="AppImageOptions-publish">publish</code> The [publish](/configuration/publish.md) options.

docs/generated/s3-options.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
* <code id="S3Options-endpoint">endpoint</code> String - The endpoint URI to send requests to. The default endpoint is built from the configured region. The endpoint should be a string like `https://{service}.{region}.amazonaws.com`.
1414
* <code id="S3Options-channel">channel</code> = `latest` String - The update channel.
1515
* <code id="S3Options-path">path</code> = `/` String - The directory path.
16+
1617
<!-- end of generated block -->

docs/generated/spaces-options.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ Access key is required, define `DO_KEY_ID` and `DO_SECRET_KEY` environment varia
1212
* <code id="SpacesOptions-path">path</code> = `/` String - The directory path.
1313
* <code id="SpacesOptions-acl">acl</code> = `public-read` "private" | "public-read" - The ACL. Set to `null` to not [add](https://github.com/electron-userland/electron-builder/issues/1822).
1414

15+
1516
<!-- end of generated block -->

docs/hooks.md docs/includes/hooks.md

+46-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
## Hooks
2+
13
!!! note "Node.js 8"
24
All examples assumed that you use latest Node.js 8.11.x or higher.
35

4-
## afterPack
6+
### afterPack
57

68
The function (or path to file or module id) to be run after pack (but before pack into distributable format and sign).
79

810
```typescript
9-
(context: AfterPackContext): Promise<any> | string | null
11+
(context: AfterPackContext): Promise<any> | any
1012
```
1113
1214
!!! example "As function"
@@ -35,19 +37,47 @@ File `myAfterPackHook.js` in the project root directory:
3537
}
3638
```
3739

38-
## afterSign
40+
### afterSign
3941

4042
The function (or path to file or module id) to be run after pack and sign (but before pack into distributable format).
4143

4244
```typescript
43-
(context: AfterPackContext): Promise<any> | string | null
45+
(context: AfterPackContext): Promise<any> | any
46+
```
47+
48+
Configuration in the same way as `afterPack` (see above).
49+
50+
### afterAllArtifactBuild
51+
52+
The function (or path to file or module id) to be run after all artifacts are build.
53+
54+
```typescript
55+
(buildResult: BuildResult): Promise<Array<string>> | Array<string>
56+
```
57+
58+
Configuration in the same way as `afterPack` (see above).
59+
60+
!!! example "myAfterAllArtifactBuild.js"
61+
```js
62+
exports.default = function () {
63+
// you can return additional files to publish
64+
return ["/path/to/additional/result/file"]
65+
}
66+
```
67+
68+
### onNodeModuleFile
69+
70+
The function (or path to file or module id) to be run on each node module file.
71+
72+
```typescript
73+
(file: string) => void
4474
```
4575

4676
Configuration in the same way as `afterPack` (see above).
4777

4878
---
4979

50-
## AfterPackContext
80+
### AfterPackContext
5181

5282
```typescript
5383
interface AfterPackContext {
@@ -60,5 +90,16 @@ interface AfterPackContext {
6090
}
6191
```
6292

93+
### BuildResult
94+
95+
```typescript
96+
interface BuildResult {
97+
outDir: string
98+
artifactPaths: Array<string>
99+
platformToTargets: Map<Platform, Map<string, Target>>
100+
configuration: Configuration
101+
}
102+
```
103+
63104

64105

docs/index.md

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ A complete solution to package and build a ready for distribution Electron app f
1212
* [macOS](configuration/mac.md#MacConfiguration-target): `dmg`, `pkg`, `mas`, `mas-dev`.
1313
* [Linux](configuration/linux.md#LinuxConfiguration-target): [AppImage](http://appimage.org), [snap](http://snapcraft.io), debian package (`deb`), `rpm`, `freebsd`, `pacman`, `p5p`, `apk`.
1414
* [Windows](configuration/win.md#WindowsConfiguration-target): `nsis` (Installer), `nsis-web` (Web installer), `portable` (portable app without installation), AppX (Windows Store), Squirrel.Windows.
15-
* [Build version management](configuration/configuration.md#build-version-management).
1615
* [Publishing artifacts](/configuration/publish) to GitHub Releases, Amazon S3, DigitalOcean Spaces and Bintray.
1716
* Advanced building:
1817
* Pack in a distributable format [already packaged app](#pack-only-in-a-distributable-format).

mkdocs.yml

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ pages:
3535
- Introduction: index.md
3636
- Command Line Interface (CLI): cli.md
3737
- Programmatic API: api/electron-builder.md
38-
- Hooks: hooks.md
3938
- Donate: donate.md
4039

4140
- Configuration:

packages/builder-util/src/DebugLogger.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { serializeToYaml } from "./util"
44
export class DebugLogger {
55
readonly data: any = {}
66

7-
constructor(readonly enabled = true) {
7+
constructor(readonly isEnabled = true) {
88
}
99

1010
add(key: string, value: any) {
11-
if (!this.enabled) {
11+
if (!this.isEnabled) {
1212
return
1313
}
1414

@@ -41,7 +41,7 @@ export class DebugLogger {
4141

4242
save(file: string) {
4343
// toml and json doesn't correctly output multiline string as multiline
44-
if (this.enabled && Object.keys(this.data).length > 0) {
44+
if (this.isEnabled && Object.keys(this.data).length > 0) {
4545
return outputFile(file, serializeToYaml(this.data))
4646
}
4747
else {

packages/builder-util/src/promise.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function printErrorAndExit(error: Error) {
66
}
77

88
// you don't need to handle error in your task - it is passed only indicate status of promise
9-
export async function executeFinally<T>(promise: Promise<T>, task: (errorOccurred: boolean) => Promise<any>): Promise<T> {
9+
export async function executeFinally<T>(promise: Promise<T>, task: (isErrorOccurred: boolean) => Promise<any>): Promise<T> {
1010
let result: T | null = null
1111
try {
1212
result = await promise
@@ -22,12 +22,7 @@ export async function executeFinally<T>(promise: Promise<T>, task: (errorOccurre
2222
throw originalError
2323
}
2424

25-
try {
26-
await task(false)
27-
}
28-
catch (taskError) {
29-
throw taskError
30-
}
25+
await task(false)
3126
return result
3227
}
3328

0 commit comments

Comments
 (0)