Skip to content

Commit

Permalink
feat: use 7za to produce Squirrel.mac zip (smaller size — the same ti…
Browse files Browse the repository at this point in the history
…me to compress)

Also, add compression option to set compression level in one place (currently, only Linux and OS X supported)
  • Loading branch information
develar committed Apr 5, 2016
1 parent 217debf commit 2dd5d7c
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 80 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.png filter=lfs diff=lfs merge=lfs -text
*.ico filter=lfs diff=lfs merge=lfs -text
*.icns filter=lfs diff=lfs merge=lfs -text
vendor/**/* filter=lfs diff=lfs merge=lfs -text
57 changes: 37 additions & 20 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ In the development `package.json` custom `build` field can be specified to custo
```json
"build": {
"osx": {
"icon": "build/icon.icns",
"icon-size": 80,
"background": "build/background.png",
"contents": [
{
"x": 410,
Expand All @@ -26,42 +23,62 @@ In the development `package.json` custom `build` field can be specified to custo
```

As you can see, you need to customize OS X options only if you want to provide custom `x, y`.
Don't customize paths to background and icon, — just follow conventions (if you don't want to use `build` as directory of resources — please create issue to ask ability to customize it).
Don't customize paths to background and icon, — just follow conventions.

Here documented only `electron-builder` specific options:

<!-- do not edit. start of generated block -->

<a name="#AppMetadata"></a>
<a name="AppMetadata"></a>
# Application `package.json`
| Name | Description
| --- | ---
| <a name="#AppMetadata-name"></a>name | The application name.
| <a name="#AppMetadata-productName"></a>productName | <p>As [name](#AppMetadata-name), but allows you to specify a product name for your executable which contains spaces and other special characters not allowed in the [name property](https://docs.npmjs.com/files/package.json#name}).</p>
| name | <a name="AppMetadata-name"></a>The application name.
| productName | <a name="AppMetadata-productName"></a><p>As [name](#AppMetadata-name), but allows you to specify a product name for your executable which contains spaces and other special characters not allowed in the [name property](https://docs.npmjs.com/files/package.json#name}).</p>

<a name="#DevMetadata"></a>
<a name="DevMetadata"></a>
# Development `package.json`
| Name | Description
| --- | ---
| <a name="#DevMetadata-homepage"></a>homepage | <p>The url to the project [homepage](https://docs.npmjs.com/files/package.json#homepage) (NuGet Package <code>projectUrl</code> (optional) or Linux Package URL (required)).</p> <p>If not specified and your project repository is public on GitHub, it will be <code>https://github.com/${user}/${project}</code> by default.</p>
| <a name="#DevMetadata-license"></a>license | *linux-only.* The [license](https://docs.npmjs.com/files/package.json#license) name for this package.
| <a name="#DevMetadata-build"></a>build | See [.build](#BuildMetadata).
| homepage | <a name="DevMetadata-homepage"></a><p>The url to the project [homepage](https://docs.npmjs.com/files/package.json#homepage) (NuGet Package <code>projectUrl</code> (optional) or Linux Package URL (required)).</p> <p>If not specified and your project repository is public on GitHub, it will be <code>https://github.com/${user}/${project}</code> by default.</p>
| license | <a name="DevMetadata-license"></a>*linux-only.* The [license](https://docs.npmjs.com/files/package.json#license) name for this package.
| build | <a name="DevMetadata-build"></a>See [.build](#BuildMetadata).
| directories | <a name="DevMetadata-directories"></a>See [.directories](#MetadataDirectories)

<a name="#BuildMetadata"></a>
<a name="BuildMetadata"></a>
## `.build`
| Name | Description
| --- | ---
| <a name="#BuildMetadata-iconUrl"></a>iconUrl | <p>*windows-only.* A URL to an ICO file to use as the application icon (displayed in Control Panel &gt; Programs and Features). Defaults to the Atom icon.</p> <p>Please note — [local icon file url is not accepted](https://github.com/atom/grunt-electron-installer/issues/73), must be https/http.</p> <ul> <li>If you don’t plan to build windows installer, you can omit it.</li> <li>If your project repository is public on GitHub, it will be <code>https://raw.githubusercontent.com/${user}/${project}/master/build/icon.ico</code> by default.</li> </ul>
| <a name="#BuildMetadata-productName"></a>productName | See [AppMetadata.productName](#AppMetadata-productName).
| <a name="#BuildMetadata-extraResources"></a>extraResources | <p>A [glob expression](https://www.npmjs.com/package/glob#glob-primer), when specified, copy the file or directory with matching names directly into the app’s directory (<code>Contents/Resources</code> for OS X).</p> <p>You can use <code>${os}</code> (expanded to osx, linux or win according to current platform) and <code>${arch}</code> in the pattern.</p> <p>If directory matched, all contents are copied. So, you can just specify <code>foo</code> to copy <code>&lt;project_dir&gt;/foo</code> directory.</p> <p>May be specified in the platform options (i.e. in the <code>build.osx</code>).</p>
| <a name="#BuildMetadata-osx"></a>osx | See [OS X options](https://www.npmjs.com/package/appdmg#json-specification)
| <a name="#BuildMetadata-win"></a>win | See [windows-installer options](https://github.com/electronjs/windows-installer#usage)
| <a name="#BuildMetadata-linux"></a>linux | See [.linux](#DebOptions).
| app-bundle-id | <a name="BuildMetadata-app-bundle-id"></a>The bundle identifier to use in the application's plist.
| app-category-type | <a name="BuildMetadata-app-category-type"></a><p>The application category type, as shown in the Finder via *View -&gt; Arrange by Application Category* when viewing the Applications directory.</p> <p>For example, <code>app-category-type=public.app-category.developer-tools</code> will set the application category to *Developer Tools*.</p> <p>Valid values are listed in [Apple’s documentation](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/LaunchServicesKeys.html#//apple_ref/doc/uid/TP40009250-SW8).</p>
| iconUrl | <a name="BuildMetadata-iconUrl"></a><p>*windows-only.* A URL to an ICO file to use as the application icon (displayed in Control Panel &gt; Programs and Features). Defaults to the Atom icon.</p> <p>Please note — [local icon file url is not accepted](https://github.com/atom/grunt-electron-installer/issues/73), must be https/http.</p> <ul> <li>If you don’t plan to build windows installer, you can omit it.</li> <li>If your project repository is public on GitHub, it will be <code>https://raw.githubusercontent.com/${user}/${project}/master/build/icon.ico</code> by default.</li> </ul>
| productName | <a name="BuildMetadata-productName"></a>See [AppMetadata.productName](#AppMetadata-productName).
| extraResources | <a name="BuildMetadata-extraResources"></a><p>A [glob expression](https://www.npmjs.com/package/glob#glob-primer), when specified, copy the file or directory with matching names directly into the app’s directory (<code>Contents/Resources</code> for OS X).</p> <p>You can use <code>${os}</code> (expanded to osx, linux or win according to current platform) and <code>${arch}</code> in the pattern.</p> <p>If directory matched, all contents are copied. So, you can just specify <code>foo</code> to copy <code>&lt;project_dir&gt;/foo</code> directory.</p> <p>May be specified in the platform options (i.e. in the <code>build.osx</code>).</p>
| osx | <a name="BuildMetadata-osx"></a>See [.build.osx](#OsXBuildOptions).
| win | <a name="BuildMetadata-win"></a>See [windows-installer options](https://github.com/electronjs/windows-installer#usage).
| 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.

<a name="#DebOptions"></a>
<a name="OsXBuildOptions"></a>
### `.build.osx`

See all [appdmg options](https://www.npmjs.com/package/appdmg#json-specification).

| Name | Description
| --- | ---
| icon | <a name="OsXBuildOptions-icon"></a>The path to icon, which will be shown when mounted (default: `build/icon.icns`).
| background | <a name="OsXBuildOptions-background"></a>The path to background (default: `build/background.png`).

<a name="LinuxBuildOptions"></a>
### `.build.linux`
| Name | Description
| --- | ---
| <a name="#DebOptions-compression"></a>compression | *deb-only.* The compression type to use, must be one of gz, bzip2, xz. (default: `xz`)
| compression | <a name="LinuxBuildOptions-compression"></a>*deb-only.* The compression type, one of `gz`, `bzip2`, `xz`. (default: `xz`).

<a name="MetadataDirectories"></a>
## `.directories`
| Name | Description
| --- | ---
| buildResources | <a name="MetadataDirectories-buildResources"></a>The path to build resources, default `build`.

<!-- end of generated block -->
18 changes: 11 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "out/index.js",
"files": [
"out",
"templates"
"templates",
"vendor"
],
"bin": {
"build": "./out/build-cli.js",
Expand Down Expand Up @@ -55,14 +56,14 @@
"bluebird": "^3.3.4",
"command-line-args": "^2.1.6",
"electron-packager": "^6.0.0",
"electron-winstaller-fixed": "^2.0.6-beta.6",
"electron-winstaller-fixed": "^2.0.6-beta.7",
"fs-extra": "^0.26.7",
"fs-extra-p": "^0.2.0",
"globby": "^4.0.0",
"gm": "^1.21.1",
"hosted-git-info": "^2.1.4",
"image-size": "^0.5.0",
"lodash.template": "^4.2.3",
"lodash.template": "^4.2.4",
"mime": "^1.3.4",
"progress": "^1.1.8",
"progress-stream": "^1.2.0",
Expand All @@ -79,17 +80,17 @@
"babel-plugin-transform-es2015-parameters": "^6.7.0",
"babel-plugin-transform-es2015-spread": "^6.6.5",
"decompress-zip": "^0.3.0",
"electron-download": "^2.1.0",
"electron-download": "^2.1.1",
"json-parse-helpfulerror": "^1.0.3",
"path-sort": "^0.1.0",
"plist": "^1.2.0",
"pre-commit": "^1.1.2",
"semantic-release": "^4.3.5",
"should": "^8.3.0",
"ts-babel": "^0.6.8",
"ts-babel": "^0.6.9",
"tsconfig-glob": "^0.4.3",
"tslint": "next",
"typescript": "^1.9.0-dev.20160402",
"typescript": "^1.9.0-dev.20160405",
"validate-commit-msg": "^2.5.0"
},
"babel": {
Expand All @@ -109,5 +110,8 @@
"typings": "./out/electron-builder.d.ts",
"precommit": [
"validate-commit-msg"
]
],
"publishConfig": {
"tag": "next"
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { Packager } from "./packager"
export { PackagerOptions, ArtifactCreated } from "./platformPackager"
export { BuildOptions, build, createPublisher } from "./builder"
export { AppMetadata, DevMetadata, Platform, getProductName, BuildMetadata, DebOptions } from "./metadata"
export { AppMetadata, DevMetadata, Platform, getProductName, BuildMetadata, OsXBuildOptions, LinuxBuildOptions } from "./metadata"
10 changes: 5 additions & 5 deletions src/linuxPackager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from "path"
import { Promise as BluebirdPromise } from "bluebird"
import { PlatformPackager, BuildInfo } from "./platformPackager"
import { Platform, DebOptions } from "./metadata"
import { Platform, LinuxBuildOptions } from "./metadata"
import { dir as _tpmDir, TmpOptions } from "tmp"
import { exec, log } from "./util"
import { outputFile, readFile, readdir } from "fs-extra-p"
Expand All @@ -13,8 +13,8 @@ const __awaiter = require("./awaiter")

const tmpDir = BluebirdPromise.promisify(<(config: TmpOptions, callback: (error: Error, path: string, cleanupCallback: () => void) => void) => void>_tpmDir)

export class LinuxPackager extends PlatformPackager<DebOptions> {
private readonly debOptions: DebOptions
export class LinuxPackager extends PlatformPackager<LinuxBuildOptions> {
private readonly debOptions: LinuxBuildOptions

private readonly packageFiles: Promise<Array<string>>
private readonly scriptFiles: Promise<Array<string>>
Expand Down Expand Up @@ -167,7 +167,7 @@ Icon=${this.metadata.name}
.then(it => this.dispatchArtifactCreated(it))
}

private async buildDeb(options: DebOptions, outDir: string, appOutDir: string, arch: string): Promise<string> {
private async buildDeb(options: LinuxBuildOptions, outDir: string, appOutDir: string, arch: string): Promise<string> {
const archName = arch === "ia32" ? "i386" : "amd64"
const target = "deb"
const destination = path.join(outDir, `${this.metadata.name}-${this.metadata.version}-${archName}.${target}`)
Expand All @@ -191,7 +191,7 @@ Icon=${this.metadata.name}
"--maintainer", options.maintainer || `${this.metadata.author.name} <${this.metadata.author.email}>`,
"--version", this.metadata.version,
"--package", destination,
"--deb-compression", options.compression || "xz",
"--deb-compression", options.compression || (this.devMetadata.build.compression === "store" ? "gz" : "xz"),
"--url", projectUrl,
]

Expand Down
22 changes: 10 additions & 12 deletions src/macPackager.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { PlatformPackager, BuildInfo } from "./platformPackager"
import { Platform, PlatformSpecificBuildOptions } from "./metadata"
import { Platform, OsXBuildOptions } from "./metadata"
import * as path from "path"
import { Promise as BluebirdPromise } from "bluebird"
import { log, spawn } from "./util"
import { createKeychain, deleteKeychain, CodeSigningInfo, generateKeychainName, sign } from "./codeSign"
import { stat } from "fs-extra-p"

//noinspection JSUnusedLocalSymbols
const __awaiter = require("./awaiter")
Array.isArray(__awaiter)

export interface OsXBuildOptions extends PlatformSpecificBuildOptions, appdmg.Specification {
}

export default class MacPackager extends PlatformPackager<OsXBuildOptions> {
codeSigningInfo: Promise<CodeSigningInfo>
Expand Down Expand Up @@ -107,16 +104,17 @@ export default class MacPackager extends PlatformPackager<OsXBuildOptions> {
// we use app name here - see https://github.com/electron-userland/electron-builder/pull/204
const resultPath = `${this.appName}-${this.metadata.version}-mac.zip`
// -y param is important - "store symbolic links as the link instead of the referenced file"
const args = ["-ryXq", resultPath, this.appName + ".app"]

// todo move to options
if (process.env.TEST_MODE === "true") {
args.unshift("-0")
const args = ["a", "-mm=" + (this.devMetadata.build.compression === "store" ? "Copy" : "Deflate"), "-r", "-bb0", "-bd"]
if (this.devMetadata.build.compression === "maximum") {
// http://superuser.com/a/742034
//noinspection SpellCheckingInspection
args.push("-mfb=258", "-mpass=15")
}
args.push(resultPath, this.appName + ".app")

return spawn("zip", args, {
return spawn(path.join(__dirname, "..", "vendor", "osx", "7za"), args, {
cwd: outDir,
stdio: "inherit",
stdio: ["ignore", "ignore", "inherit"],
})
.thenReturn(path.join(outDir, resultPath))
}
Expand Down
Loading

0 comments on commit 2dd5d7c

Please sign in to comment.