From 2dd5d7c79444f4d706ac9b7b2974491846e9e09e Mon Sep 17 00:00:00 2001 From: develar Date: Tue, 5 Apr 2016 09:59:34 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20use=207za=20to=20produce=20Squirrel.mac?= =?UTF-8?q?=20zip=20(smaller=20size=20=E2=80=94=20the=20same=20time=20to?= =?UTF-8?q?=20compress)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also, add compression option to set compression level in one place (currently, only Linux and OS X supported) --- .gitattributes | 1 + docs/options.md | 57 ++++++++++------ package.json | 18 +++-- src/index.ts | 2 +- src/linuxPackager.ts | 10 +-- src/macPackager.ts | 22 +++--- src/metadata.ts | 91 ++++++++++++++++++------- src/packager.ts | 2 +- test/fixtures/test-app-one/package.json | 5 +- test/fixtures/test-app/package.json | 5 +- typings/appdmg.d.ts | 2 +- vendor/osx/7za | 3 + 12 files changed, 138 insertions(+), 80 deletions(-) create mode 100755 vendor/osx/7za diff --git a/.gitattributes b/.gitattributes index 25134f467dd..25dfab20a3d 100755 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/docs/options.md b/docs/options.md index 0f6e766a863..76481e76b6f 100644 --- a/docs/options.md +++ b/docs/options.md @@ -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, @@ -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: - + # Application `package.json` | Name | Description | --- | --- -| name | The application name. -| productName |

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

+| name | The application name. +| productName |

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

- + # Development `package.json` | Name | Description | --- | --- -| homepage |

The url to the project [homepage](https://docs.npmjs.com/files/package.json#homepage) (NuGet Package projectUrl (optional) or Linux Package URL (required)).

If not specified and your project repository is public on GitHub, it will be https://github.com/${user}/${project} by default.

-| license | *linux-only.* The [license](https://docs.npmjs.com/files/package.json#license) name for this package. -| build | See [.build](#BuildMetadata). +| homepage |

The url to the project [homepage](https://docs.npmjs.com/files/package.json#homepage) (NuGet Package projectUrl (optional) or Linux Package URL (required)).

If not specified and your project repository is public on GitHub, it will be https://github.com/${user}/${project} by default.

+| license | *linux-only.* The [license](https://docs.npmjs.com/files/package.json#license) name for this package. +| build | See [.build](#BuildMetadata). +| directories | See [.directories](#MetadataDirectories) - + ## `.build` | Name | Description | --- | --- -| iconUrl |

*windows-only.* A URL to an ICO file to use as the application icon (displayed in Control Panel > Programs and Features). Defaults to the Atom icon.

Please note — [local icon file url is not accepted](https://github.com/atom/grunt-electron-installer/issues/73), must be https/http.

-| productName | See [AppMetadata.productName](#AppMetadata-productName). -| extraResources |

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 (Contents/Resources for OS X).

You can use ${os} (expanded to osx, linux or win according to current platform) and ${arch} in the pattern.

If directory matched, all contents are copied. So, you can just specify foo to copy <project_dir>/foo directory.

May be specified in the platform options (i.e. in the build.osx).

-| osx | See [OS X options](https://www.npmjs.com/package/appdmg#json-specification) -| win | See [windows-installer options](https://github.com/electronjs/windows-installer#usage) -| linux | See [.linux](#DebOptions). +| app-bundle-id | The bundle identifier to use in the application's plist. +| app-category-type |

The application category type, as shown in the Finder via *View -> Arrange by Application Category* when viewing the Applications directory.

For example, app-category-type=public.app-category.developer-tools will set the application category to *Developer Tools*.

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

+| iconUrl |

*windows-only.* A URL to an ICO file to use as the application icon (displayed in Control Panel > Programs and Features). Defaults to the Atom icon.

Please note — [local icon file url is not accepted](https://github.com/atom/grunt-electron-installer/issues/73), must be https/http.

+| productName | See [AppMetadata.productName](#AppMetadata-productName). +| extraResources |

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 (Contents/Resources for OS X).

You can use ${os} (expanded to osx, linux or win according to current platform) and ${arch} in the pattern.

If directory matched, all contents are copied. So, you can just specify foo to copy <project_dir>/foo directory.

May be specified in the platform options (i.e. in the build.osx).

+| osx | See [.build.osx](#OsXBuildOptions). +| win | See [windows-installer options](https://github.com/electronjs/windows-installer#usage). +| linux | See [.build.linux](#LinuxBuildOptions). +| compression | The compression level, one of `store`, `normal`, `maximum` (default: `normal`). If you want to rapidly test build, `store` can reduce build time significantly. - + +### `.build.osx` + +See all [appdmg options](https://www.npmjs.com/package/appdmg#json-specification). + +| Name | Description +| --- | --- +| icon | The path to icon, which will be shown when mounted (default: `build/icon.icns`). +| background | The path to background (default: `build/background.png`). + + ### `.build.linux` | Name | Description | --- | --- -| compression | *deb-only.* The compression type to use, must be one of gz, bzip2, xz. (default: `xz`) +| compression | *deb-only.* The compression type, one of `gz`, `bzip2`, `xz`. (default: `xz`). + + +## `.directories` +| Name | Description +| --- | --- +| buildResources | The path to build resources, default `build`. diff --git a/package.json b/package.json index 88027e908dc..3c0d2a5d1e4 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "out/index.js", "files": [ "out", - "templates" + "templates", + "vendor" ], "bin": { "build": "./out/build-cli.js", @@ -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", @@ -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": { @@ -109,5 +110,8 @@ "typings": "./out/electron-builder.d.ts", "precommit": [ "validate-commit-msg" - ] + ], + "publishConfig": { + "tag": "next" + } } diff --git a/src/index.ts b/src/index.ts index c030e46f500..27a7f13ea77 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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" \ No newline at end of file +export { AppMetadata, DevMetadata, Platform, getProductName, BuildMetadata, OsXBuildOptions, LinuxBuildOptions } from "./metadata" \ No newline at end of file diff --git a/src/linuxPackager.ts b/src/linuxPackager.ts index e5b2d30fcf8..1ce44807555 100755 --- a/src/linuxPackager.ts +++ b/src/linuxPackager.ts @@ -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" @@ -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 { - private readonly debOptions: DebOptions +export class LinuxPackager extends PlatformPackager { + private readonly debOptions: LinuxBuildOptions private readonly packageFiles: Promise> private readonly scriptFiles: Promise> @@ -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 { + private async buildDeb(options: LinuxBuildOptions, outDir: string, appOutDir: string, arch: string): Promise { const archName = arch === "ia32" ? "i386" : "amd64" const target = "deb" const destination = path.join(outDir, `${this.metadata.name}-${this.metadata.version}-${archName}.${target}`) @@ -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, ] diff --git a/src/macPackager.ts b/src/macPackager.ts index b13a1d5b33b..2da574bb504 100644 --- a/src/macPackager.ts +++ b/src/macPackager.ts @@ -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 { codeSigningInfo: Promise @@ -107,16 +104,17 @@ export default class MacPackager extends PlatformPackager { // 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)) } diff --git a/src/metadata.ts b/src/metadata.ts index 8b3cfac0a9d..c5b7ac49692 100755 --- a/src/metadata.ts +++ b/src/metadata.ts @@ -2,18 +2,18 @@ export interface Metadata { readonly repository: string | RepositoryInfo } -/** +/* # Application `package.json` */ export interface AppMetadata extends Metadata { readonly version: string - /** + /* The application name. */ readonly name: string - /** + /* 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}). */ @@ -24,27 +24,30 @@ export interface AppMetadata extends Metadata { readonly author: AuthorMetadata } -/** +/* # Development `package.json` */ export interface DevMetadata extends Metadata { - /** + /* The url to the project [homepage](https://docs.npmjs.com/files/package.json#homepage) (NuGet Package `projectUrl` (optional) or Linux Package URL (required)). If not specified and your project repository is public on GitHub, it will be `https://github.com/${user}/${project}` by default. */ readonly homepage?: string - /** + /* *linux-only.* The [license](https://docs.npmjs.com/files/package.json#license) name for this package. */ readonly license?: string - /** + /* See [.build](#BuildMetadata). */ - readonly build?: BuildMetadata + readonly build: BuildMetadata + /* + See [.directories](#MetadataDirectories) + */ readonly directories?: MetadataDirectories } @@ -57,18 +60,24 @@ export interface AuthorMetadata { readonly email: string } -export interface MetadataDirectories { - readonly buildResources?: string -} - -/** +/* ## `.build` */ export interface BuildMetadata { + /* + The bundle identifier to use in the application's plist. + */ readonly "app-bundle-id": string + /* + The application category type, as shown in the Finder via *View -> Arrange by Application Category* when viewing the Applications directory. + + For example, `app-category-type=public.app-category.developer-tools` will set the application category to *Developer Tools*. + + 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). + */ readonly "app-category-type": string - /** + /* *windows-only.* A URL to an ICO file to use as the application icon (displayed in Control Panel > Programs and Features). Defaults to the Atom icon. Please note — [local icon file url is not accepted](https://github.com/atom/grunt-electron-installer/issues/73), must be https/http. @@ -78,7 +87,7 @@ export interface BuildMetadata { */ readonly iconUrl: string - /** + /* See [AppMetadata.productName](#AppMetadata-productName). */ readonly productName?: string @@ -94,26 +103,48 @@ export interface BuildMetadata { */ readonly extraResources?: Array - /** - See [OS X options](https://www.npmjs.com/package/appdmg#json-specification) + /* + See [.build.osx](#OsXBuildOptions). */ - readonly osx?: appdmg.Specification + readonly osx?: OsXBuildOptions /** - See [windows-installer options](https://github.com/electronjs/windows-installer#usage) + See [windows-installer options](https://github.com/electronjs/windows-installer#usage). */ readonly win?: any, - /** - See [.linux](#DebOptions). + /* + See [.build.linux](#LinuxBuildOptions). + */ + readonly linux?: LinuxBuildOptions + + /* + The compression level, one of `store`, `normal`, `maximum` (default: `normal`). If you want to rapidly test build, `store` can reduce build time significantly. + */ + readonly compression?: "store" | "normal" | "maximum" +} + +/* + ### `.build.osx` + + See all [appdmg options](https://www.npmjs.com/package/appdmg#json-specification). + */ +export interface OsXBuildOptions extends PlatformSpecificBuildOptions { + /* + The path to icon, which will be shown when mounted (default: `build/icon.icns`). + */ + icon?: string + + /* + The path to background (default: `build/background.png`). */ - readonly linux?: any + background?: string } -/** +/* ### `.build.linux` */ -export interface DebOptions { +export interface LinuxBuildOptions { name: string comment: string @@ -126,11 +157,21 @@ export interface DebOptions { afterRemove?: string /* - *deb-only.* The compression type to use, must be one of gz, bzip2, xz. (default: `xz`) + *deb-only.* The compression type, one of `gz`, `bzip2`, `xz`. (default: `xz`). */ readonly compression?: string } +/* + ## `.directories` + */ +export interface MetadataDirectories { + /* + The path to build resources, default `build`. + */ + readonly buildResources?: string +} + export interface PlatformSpecificBuildOptions { readonly extraResources?: Array } diff --git a/src/packager.ts b/src/packager.ts index 615fcd66188..561bb0d99e1 100644 --- a/src/packager.ts +++ b/src/packager.ts @@ -148,7 +148,7 @@ export class Packager implements BuildInfo { else if (appMetadata.version == null) { reportError("version") } - else if (appMetadata !== this.devMetadata && (appMetadata).build != null) { + else if ((appMetadata) !== this.devMetadata && (appMetadata).build != null) { throw new Error(util.format(errorMessages.buildInAppSpecified, appPackageFile, devAppPackageFile)) } else if (this.devMetadata.build == null) { diff --git a/test/fixtures/test-app-one/package.json b/test/fixtures/test-app-one/package.json index 5b4199af852..0c9ae13a31c 100755 --- a/test/fixtures/test-app-one/package.json +++ b/test/fixtures/test-app-one/package.json @@ -16,10 +16,7 @@ "app-bundle-id": "your.id", "app-category-type": "your.app.category.type", "iconUrl": "https://raw.githubusercontent.com/szwacz/electron-boilerplate/master/resources/windows/icon.ico", - "linux": { - "//": "gz is much faster, in tests we don't need efficient compression", - "compression": "gz" - }, + "compression": "store", "win": { "title": "My App" } diff --git a/test/fixtures/test-app/package.json b/test/fixtures/test-app/package.json index 382069ff559..acf80facadd 100755 --- a/test/fixtures/test-app/package.json +++ b/test/fixtures/test-app/package.json @@ -10,9 +10,6 @@ "app-bundle-id": "your.id", "app-category-type": "your.app.category.type", "iconUrl": "https://raw.githubusercontent.com/szwacz/electron-boilerplate/master/resources/windows/icon.ico", - "linux": { - "//": "gz is much faster, in tests we don't need efficient compression", - "compression": "gz" - } + "compression": "store" } } diff --git a/typings/appdmg.d.ts b/typings/appdmg.d.ts index 279d0b9f180..cd0cb00fe13 100644 --- a/typings/appdmg.d.ts +++ b/typings/appdmg.d.ts @@ -1,7 +1,7 @@ declare namespace appdmg { interface Specification { title: string - background: string + background?: string icon: string "icon-size": number diff --git a/vendor/osx/7za b/vendor/osx/7za new file mode 100755 index 00000000000..fd31c11fca3 --- /dev/null +++ b/vendor/osx/7za @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2ee47fe33aece30af6baf9826eebcdea60ceecaa9559ee5bd305c62bea279a74 +size 1667792