Skip to content

Commit

Permalink
feat: afterAllArtifactBuild hook
Browse files Browse the repository at this point in the history
Close #3116
  • Loading branch information
develar committed Jul 16, 2018
1 parent 1ce3a89 commit e7ff5e8
Show file tree
Hide file tree
Showing 42 changed files with 230 additions and 121 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ See documentation on [electron.build](https://www.electron.build).
* [macOS](https://www.electron.build/configuration/mac): `dmg`, `pkg`, `mas`.
* [Linux](https://www.electron.build/configuration/linux): [AppImage](http://appimage.org), [snap](http://snapcraft.io), debian package (`deb`), `rpm`, `freebsd`, `pacman`, `p5p`, `apk`.
* [Windows](https://www.electron.build/configuration/win): `nsis` (Installer), `nsis-web` (Web installer), `portable` (portable app without installation), AppX (Windows Store), MSI, Squirrel.Windows.
* [Build version management](https://www.electron.build/configuration/configuration#build-version-management).
* [Publishing artifacts](https://www.electron.build/configuration/publish) to GitHub Releases, Amazon S3, DigitalOcean Spaces and Bintray.
* Advanced building:
* Pack in a distributable format [already packaged app](https://www.electron.build/#pack-only-in-a-distributable-format).
Expand Down
1 change: 1 addition & 0 deletions docs/configuration/appx.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Inherited from `TargetSpecificOptions`:

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

<!-- end of generated block -->

## AppX Package Code Signing
Expand Down
16 changes: 10 additions & 6 deletions docs/configuration/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,21 @@ Env file `electron-builder.env` in the current dir ([example](https://github.com

---

* <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).

---

* <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).
* <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.
* <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).
* <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).
* <code id="Configuration-afterAllArtifactBuild">afterAllArtifactBuild</code> - The function (or path to file or module id) to be [run after all artifacts are build](#afterAllArtifactBuild).
* <code id="Configuration-onNodeModuleFile">onNodeModuleFile</code> - The function (or path to file or module id) to be [run on each node module](#onnodemodulefile) file.
* <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.

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


---

* <code id="Configuration-remoteBuild">remoteBuild</code> = `true` Boolean - Whether to build using Electron Build Service if target not supported on current OS.
* <code id="Configuration-includePdb">includePdb</code> = `false` Boolean - Whether to include PDB files.
* <code id="Configuration-removePackageScripts">removePackageScripts</code> = `true` Boolean - Whether to remove `scripts` field from `package.json` files.

<!-- end of generated block -->

---
Expand All @@ -152,3 +154,5 @@ Currently, only macOS and Linux supported.

## Build Version Management
`CFBundleVersion` (macOS) and `FileVersion` (Windows) will be set automatically to `version.build_number` on CI server (Travis, AppVeyor, CircleCI and Bamboo supported).

{!includes/hooks.md!}
1 change: 1 addition & 0 deletions docs/configuration/dmg.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Inherited from `TargetSpecificOptions`:

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

<!-- end of generated block -->

## DMG License
Expand Down
1 change: 1 addition & 0 deletions docs/configuration/linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The top-level [linux](configuration.md#Configuration-linux) key contains set of
* <code id="LinuxConfiguration-category">category</code> String - The [application category](https://specifications.freedesktop.org/menu-spec/latest/apa.html#main-category-registry).
* <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.
* <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).

<!-- end of generated block -->

## Debian Package Options
Expand Down
1 change: 1 addition & 0 deletions docs/configuration/mac.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ The top-level [mac](configuration.md#Configuration-mac) key contains set of opti
1.0.0 latest-mac.json 2.15.0 path 2.16.0 files

* <code id="MacConfiguration-electronLanguages">electronLanguages</code> Array&lt;String&gt; | String - The electron locales. By default Electron locales used as is.

<!-- end of generated block -->
1 change: 1 addition & 0 deletions docs/configuration/mas.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ Inherits [macOS options](mac.md).
* <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).
* <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).
* <code id="MasConfiguration-binaries">binaries</code> Array&lt;String&gt; - Paths of any extra binaries that need to be signed.

<!-- end of generated block -->
30 changes: 16 additions & 14 deletions docs/configuration/nsis.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ To build web installer, set [target](/configuration/win.md#WindowsConfiguration-
To customize web installer, use the top-level `nsisWeb` key (not `nsis`).

If for some reasons web installer cannot download (antivirus, offline):

* 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).
* Specify any local package file using `--package-file=path_to_file`.

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

## Common Questions
#### How do change the default installation directory to custom?

It is very specific requirement. Do not do if you are not sure. Add [custom macro](#custom-nsis-script):

```nsis
!macro preInit
SetRegView 64
WriteRegExpandStr HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
WriteRegExpandStr HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
SetRegView 32
WriteRegExpandStr HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
WriteRegExpandStr HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
!macroend
```

??? question "How do change the default installation directory to custom?"

It is very specific requirement. Do not do if you are not sure. Add [custom macro](#custom-nsis-script):

```nsis
!macro preInit
SetRegView 64
WriteRegExpandStr HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
WriteRegExpandStr HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
SetRegView 32
WriteRegExpandStr HKLM "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
WriteRegExpandStr HKCU "${INSTALL_REGISTRY_KEY}" InstallLocation "C:\MyApp"
!macroend
```


1 change: 1 addition & 0 deletions docs/configuration/pkg.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ Inherited from `TargetSpecificOptions`:

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

<!-- end of generated block -->
1 change: 1 addition & 0 deletions docs/configuration/publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ Inherited from `PublishConfiguration`:
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.



<!-- end of generated block -->

## S3Options
Expand Down
1 change: 1 addition & 0 deletions docs/configuration/snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ Inherited from `TargetSpecificOptions`:

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

<!-- end of generated block -->
1 change: 1 addition & 0 deletions docs/configuration/squirrel-windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ Inherited from `TargetSpecificOptions`:

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

<!-- end of generated block -->
1 change: 1 addition & 0 deletions docs/configuration/target.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ build -wl
<!-- do not edit. start of generated block -->
* **<code id="TargetConfiguration-target">target</code>** String - The target name. e.g. `snap`.
* <code id="TargetConfiguration-arch">arch</code> Array&lt;"x64" | "ia32" | "armv7l" | "arm64"&gt; | "x64" | "ia32" | "armv7l" | "arm64" - The arch or list of archs.

<!-- end of generated block -->
1 change: 1 addition & 0 deletions docs/configuration/win.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ The top-level [win](configuration.md#Configuration-win) key contains set of opti

1.0.0 sha2 2.15.0 path 2.16.0 files


<!-- end of generated block -->

---
Expand Down
2 changes: 1 addition & 1 deletion docs/generated/DebOptions.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
* <code id="DebOptions-depends">depends</code> Array&lt;String&gt; - Package dependencies. Defaults to `["gconf2", "gconf-service", "libnotify4", "libappindicator1", "libxtst6", "libnss3"]`.
* <code id="DebOptions-packageCategory">packageCategory</code> String - The [package category](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Section).
* <code id="DebOptions-priority">priority</code> String - The [Priority](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Priority) attribute.
* <code id="DebOptions-priority">priority</code> String - The [Priority](https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Priority) attribute.
2 changes: 1 addition & 1 deletion docs/generated/LinuxTargetSpecificOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ Inherited from `CommonLinuxOptions`:
Inherited from `TargetSpecificOptions`:

* <code id="LinuxTargetSpecificOptions-artifactName">artifactName</code> String - The [artifact file name template](/configuration/configuration.md#artifact-file-name-template).
* <code id="LinuxTargetSpecificOptions-publish">publish</code> The [publish](/configuration/publish.md) options.
* <code id="LinuxTargetSpecificOptions-publish">publish</code> The [publish](/configuration/publish.md) options.
2 changes: 1 addition & 1 deletion docs/generated/Metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
* <code id="AuthorMetadata-email">email</code> String
* <code id="Metadata-repository">repository</code> String | RepositoryInfo<a name="RepositoryInfo"></a> - The [repository](https://docs.npmjs.com/files/package.json#repository).
* **<code id="RepositoryInfo-url">url</code>** String
* <code id="Metadata-build">build</code> [Configuration](#configuration) - The electron-builder configuration.
* <code id="Metadata-build">build</code> [Configuration](#configuration) - The electron-builder configuration.
1 change: 1 addition & 0 deletions docs/generated/NsisOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@
* <code id="NsisOptions-createStartMenuShortcut">createStartMenuShortcut</code> = `true` Boolean - Whether to create start menu shortcut.
* <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.
* <code id="NsisOptions-shortcutName">shortcutName</code> String - The name that will be used for all shortcuts. Defaults to the application name.

<!-- end of generated block -->
2 changes: 1 addition & 1 deletion docs/generated/PlatformSpecificBuildOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
* <code id="ReleaseInfo-releaseNotes">releaseNotes</code> String - The release notes.
* <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).
* <code id="ReleaseInfo-releaseDate">releaseDate</code> String - The release date.
* <code id="PlatformSpecificBuildOptions-target">target</code> String | [TargetConfiguration](/configuration/target.md#targetconfiguration)
* <code id="PlatformSpecificBuildOptions-target">target</code> String | [TargetConfiguration](/configuration/target.md#targetconfiguration)
2 changes: 1 addition & 1 deletion docs/generated/TargetSpecificOptions.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
* <code id="TargetSpecificOptions-artifactName">artifactName</code> String - The [artifact file name template](/configuration/configuration.md#artifact-file-name-template).
* <code id="TargetSpecificOptions-publish">publish</code> The [publish](/configuration/publish.md) options.
* <code id="TargetSpecificOptions-publish">publish</code> The [publish](/configuration/publish.md) options.
2 changes: 1 addition & 1 deletion docs/generated/appimage-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Inherited from `CommonLinuxOptions`:
Inherited from `TargetSpecificOptions`:

* <code id="AppImageOptions-artifactName">artifactName</code> String - The [artifact file name template](/configuration/configuration.md#artifact-file-name-template).
* <code id="AppImageOptions-publish">publish</code> The [publish](/configuration/publish.md) options.
* <code id="AppImageOptions-publish">publish</code> The [publish](/configuration/publish.md) options.
1 change: 1 addition & 0 deletions docs/generated/s3-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
* <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`.
* <code id="S3Options-channel">channel</code> = `latest` String - The update channel.
* <code id="S3Options-path">path</code> = `/` String - The directory path.

<!-- end of generated block -->
1 change: 1 addition & 0 deletions docs/generated/spaces-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ Access key is required, define `DO_KEY_ID` and `DO_SECRET_KEY` environment varia
* <code id="SpacesOptions-path">path</code> = `/` String - The directory path.
* <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).


<!-- end of generated block -->
51 changes: 46 additions & 5 deletions docs/hooks.md → docs/includes/hooks.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
## Hooks

!!! note "Node.js 8"
All examples assumed that you use latest Node.js 8.11.x or higher.

## afterPack
### afterPack

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

```typescript
(context: AfterPackContext): Promise<any> | string | null
(context: AfterPackContext): Promise<any> | any
```
!!! example "As function"
Expand Down Expand Up @@ -35,19 +37,47 @@ File `myAfterPackHook.js` in the project root directory:
}
```

## afterSign
### afterSign

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

```typescript
(context: AfterPackContext): Promise<any> | string | null
(context: AfterPackContext): Promise<any> | any
```

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

### afterAllArtifactBuild

The function (or path to file or module id) to be run after all artifacts are build.

```typescript
(buildResult: BuildResult): Promise<Array<string>> | Array<string>
```

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

!!! example "myAfterAllArtifactBuild.js"
```js
exports.default = function () {
// you can return additional files to publish
return ["/path/to/additional/result/file"]
}
```

### onNodeModuleFile

The function (or path to file or module id) to be run on each node module file.

```typescript
(file: string) => void
```

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

---

## AfterPackContext
### AfterPackContext

```typescript
interface AfterPackContext {
Expand All @@ -60,5 +90,16 @@ interface AfterPackContext {
}
```

### BuildResult

```typescript
interface BuildResult {
outDir: string
artifactPaths: Array<string>
platformToTargets: Map<Platform, Map<string, Target>>
configuration: Configuration
}
```



1 change: 0 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ A complete solution to package and build a ready for distribution Electron app f
* [macOS](configuration/mac.md#MacConfiguration-target): `dmg`, `pkg`, `mas`, `mas-dev`.
* [Linux](configuration/linux.md#LinuxConfiguration-target): [AppImage](http://appimage.org), [snap](http://snapcraft.io), debian package (`deb`), `rpm`, `freebsd`, `pacman`, `p5p`, `apk`.
* [Windows](configuration/win.md#WindowsConfiguration-target): `nsis` (Installer), `nsis-web` (Web installer), `portable` (portable app without installation), AppX (Windows Store), Squirrel.Windows.
* [Build version management](configuration/configuration.md#build-version-management).
* [Publishing artifacts](/configuration/publish) to GitHub Releases, Amazon S3, DigitalOcean Spaces and Bintray.
* Advanced building:
* Pack in a distributable format [already packaged app](#pack-only-in-a-distributable-format).
Expand Down
1 change: 0 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ pages:
- Introduction: index.md
- Command Line Interface (CLI): cli.md
- Programmatic API: api/electron-builder.md
- Hooks: hooks.md
- Donate: donate.md

- Configuration:
Expand Down
6 changes: 3 additions & 3 deletions packages/builder-util/src/DebugLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { serializeToYaml } from "./util"
export class DebugLogger {
readonly data: any = {}

constructor(readonly enabled = true) {
constructor(readonly isEnabled = true) {
}

add(key: string, value: any) {
if (!this.enabled) {
if (!this.isEnabled) {
return
}

Expand Down Expand Up @@ -41,7 +41,7 @@ export class DebugLogger {

save(file: string) {
// toml and json doesn't correctly output multiline string as multiline
if (this.enabled && Object.keys(this.data).length > 0) {
if (this.isEnabled && Object.keys(this.data).length > 0) {
return outputFile(file, serializeToYaml(this.data))
}
else {
Expand Down
9 changes: 2 additions & 7 deletions packages/builder-util/src/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function printErrorAndExit(error: Error) {
}

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

try {
await task(false)
}
catch (taskError) {
throw taskError
}
await task(false)
return result
}

Expand Down
Loading

0 comments on commit e7ff5e8

Please sign in to comment.