Skip to content

Commit

Permalink
feat: The function to be run after pack (but before pack into distrib…
Browse files Browse the repository at this point in the history
…utable format and sign)

Closes #397
  • Loading branch information
develar committed May 18, 2016
1 parent cc8278a commit 7f32573
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 5 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/develar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/Multi Platform Build.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ To build app in distributable format for Windows on Linux:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
sudo apt-get update
sudo apt-get install mono-devel -y
sudo apt-get install mono-devel ca-certificates-mono -y
```

* Install zip.
Expand Down
1 change: 1 addition & 0 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Here documented only `electron-builder` specific options:
| win | <a name="BuildMetadata-win"></a>See [.build.win](#LinuxBuildOptions).
| linux | <a name="BuildMetadata-linux"></a>See [.build.linux](#LinuxBuildOptions).
| compression | <a name="BuildMetadata-compression"></a>The compression level, one of `store`, `normal`, `maximum` (default: `normal`). If you want to rapidly test build, `store` can reduce build time significantly.
| afterPack | <a name="BuildMetadata-afterPack"></a>*programmatic API only* The function to be run after pack (but before pack into distributable format and sign). Promise must be returned.

<a name="OsXBuildOptions"></a>
### `.build.osx`
Expand Down
11 changes: 11 additions & 0 deletions src/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ElectronPackagerOptions = ElectronPackager.ElectronPackagerOptions
export interface Metadata {
readonly repository?: string | RepositoryInfo | null
}
Expand Down Expand Up @@ -139,6 +140,16 @@ export interface BuildMetadata {
readonly compression?: "store" | "normal" | "maximum" | null

readonly "build-version"?: string | null

/*
*programmatic API only* The function to be run after pack (but before pack into distributable format and sign). Promise must be returned.
*/
readonly afterPack?: (context: AfterPackContext) => Promise<any> | null
}

export interface AfterPackContext {
readonly appOutDir: string
readonly options: ElectronPackagerOptions
}

/*
Expand Down
13 changes: 11 additions & 2 deletions src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>

protected async packApp(options: ElectronPackagerOptions, appOutDir: string): Promise<any> {
await pack(options)

const afterPack = this.devMetadata.build.afterPack
if (afterPack != null) {
await afterPack({
appOutDir: appOutDir,
options: options,
})
}

await this.sanityCheckPackage(appOutDir, <boolean>options.asar)
}

Expand Down Expand Up @@ -226,7 +235,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
}
}

private async sanityCheckAsar(asarFile: string): Promise<any> {
private static async sanityCheckAsar(asarFile: string): Promise<any> {
const outStat = await statOrNull(asarFile)

if (outStat == null) {
Expand All @@ -253,7 +262,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>

const resourcesDir = this.getResourcesDir(appOutDir)
if (isAsar) {
await this.sanityCheckAsar(path.join(resourcesDir, "app.asar"))
await PlatformPackager.sanityCheckAsar(path.join(resourcesDir, "app.asar"))
}

const mainFile = this.metadata.main || "index.js"
Expand Down
2 changes: 1 addition & 1 deletion test/install-linux-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key ad
sudo dpkg --add-architecture i386
sudo add-apt-repository ppa:ubuntu-wine/ppa -y
sudo apt-get update
sudo apt-get install wine1.8 -y
sudo apt-get install wine1.8 ca-certificates-mono -y
24 changes: 23 additions & 1 deletion test/src/BuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,28 @@ test("www as default dir", () => assertPack("test-app", {
tempDirCreated: projectDir => move(path.join(projectDir, "app"), path.join(projectDir, "www"))
}))

test("afterPack", t => {
let called = false
return assertPack("test-app", {
// linux pack is very fast, so, we use it :)
platform: [Platform.LINUX],
dist: true,
devMetadata: {
build: {
afterPack: () => {
called = true
return Promise.resolve()
}
}
}
}, {
packed: () => {
t.true(called)
return Promise.resolve()
}
})
})

test("copy extra resource", async () => {
for (let platform of getPossiblePlatforms()) {
const osName = platform.buildConfigurationKey
Expand Down Expand Up @@ -172,7 +194,7 @@ test("copy extra resource", async () => {
}
})

test("invalid platform", (t) => t.throws(assertPack("test-app-one", {
test("invalid platform", t => t.throws(assertPack("test-app-one", {
platform: [null],
dist: false
}), "Unknown platform: null"))
Expand Down
1 change: 1 addition & 0 deletions test/src/helpers/fileAssert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { stat } from "fs-extra-p"
//noinspection JSUnusedLocalSymbols
const __awaiter = require("out/awaiter")

// http://joel-costigliola.github.io/assertj/
export function assertThat(path: string) {
return new FileAssertions(path)
}
Expand Down

0 comments on commit 7f32573

Please sign in to comment.