From 0b0ed62dfcd05e1ece79e2d5ee509146037a0e3c Mon Sep 17 00:00:00 2001 From: develar Date: Wed, 6 Jul 2016 09:08:43 +0200 Subject: [PATCH] feat(mac): Add build-version override property Closes #565 --- .idea/bashsupport_project.xml | 1 + .travis.yml | 2 +- docs/Options.md | 1 + src/appInfo.ts | 25 ++++++++++++++----------- src/gitHubPublisher.ts | 9 +++++++-- src/linuxPackager.ts | 2 +- src/macPackager.ts | 5 +++++ src/metadata.ts | 5 +++++ src/platformPackager.ts | 11 +++++++---- templates/linux/AppRun.sh | 20 ++++++++++---------- test/src/macPackagerTest.ts | 10 +++++++--- 11 files changed, 59 insertions(+), 32 deletions(-) diff --git a/.idea/bashsupport_project.xml b/.idea/bashsupport_project.xml index 5aa825effb2..85d5b63ed56 100644 --- a/.idea/bashsupport_project.xml +++ b/.idea/bashsupport_project.xml @@ -8,6 +8,7 @@ diff --git a/.travis.yml b/.travis.yml index 33e26096904..c02bd007160 100755 --- a/.travis.yml +++ b/.travis.yml @@ -28,7 +28,7 @@ install: - nvm install $NODE_VERSION - nvm use --delete-prefix $NODE_VERSION - if [[ "$TRAVIS_OS_NAME" == "osx" && "$NODE_VERSION" == "4" ]]; then npm install npm -g ; fi -- npm install +- npm install --registry http://registry.npmjs.eu - npm prune script: diff --git a/docs/Options.md b/docs/Options.md index dad08b6a86f..7e894102db1 100644 --- a/docs/Options.md +++ b/docs/Options.md @@ -78,6 +78,7 @@ MacOS specific build options. | icon | The path to application icon. Defaults to `build/icon.icns` (consider using this convention instead of complicating your configuration). | entitlements |

The path to entitlements file for signing the app. build/entitlements.mac.plist will be used if exists (it is a recommended way to set). MAS entitlements is specified in the [.build.mas](#MasBuildOptions-entitlements).

| entitlementsInherit |

The path to child entitlements which inherit the security settings for signing frameworks and bundles of a distribution. build/entitlements.mac.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.darwin.inherit.plist).

This option only applies when signing with entitlements provided.

+| bundleVersion | The `CFBundleVersion`. Do not use it unless [you need to](see (https://github.com/electron-userland/electron-builder/issues/565#issuecomment-230678643)). ### `.build.dmg` diff --git a/src/appInfo.ts b/src/appInfo.ts index ab1c71533a7..6dfca99a948 100644 --- a/src/appInfo.ts +++ b/src/appInfo.ts @@ -22,19 +22,26 @@ export class AppInfo { } readonly version: string + readonly buildNumber: string readonly buildVersion: string readonly productFilename: string - constructor(public metadata: AppMetadata, private devMetadata: DevMetadata) { - let buildVersion = metadata.version! - this.version = buildVersion + constructor(public metadata: AppMetadata, private devMetadata: DevMetadata, buildVersion?: string | null) { + this.version = metadata.version! - const buildNumber = this.buildNumber - if (!isEmptyOrSpaces(buildNumber)) { - buildVersion += `.${buildNumber}` + this.buildNumber = this.devMetadata.build["build-version"] || process.env.TRAVIS_BUILD_NUMBER || process.env.APPVEYOR_BUILD_NUMBER || process.env.CIRCLE_BUILD_NUM || process.env.BUILD_NUMBER + + if (isEmptyOrSpaces(buildVersion)) { + buildVersion = this.version + if (!isEmptyOrSpaces(this.buildNumber)) { + buildVersion += `.${this.buildNumber}` + } + this.buildVersion = buildVersion + } + else { + this.buildVersion = buildVersion! } - this.buildVersion = buildVersion this.productFilename = sanitizeFileName(this.productName) } @@ -43,10 +50,6 @@ export class AppInfo { return this.metadata.author!.name } - get buildNumber(): string | null { - return this.devMetadata.build["build-version"] || process.env.TRAVIS_BUILD_NUMBER || process.env.APPVEYOR_BUILD_NUMBER || process.env.CIRCLE_BUILD_NUM || process.env.BUILD_NUMBER - } - get id(): string { const appId = this.devMetadata.build["app-bundle-id"] if (appId != null) { diff --git a/src/gitHubPublisher.ts b/src/gitHubPublisher.ts index b31ca4f662f..37c70f0d934 100644 --- a/src/gitHubPublisher.ts +++ b/src/gitHubPublisher.ts @@ -185,9 +185,14 @@ export class GitHubPublisher implements Publisher { return BluebirdPromise.resolve() } + const release = this._releasePromise.value() + if (release == null) { + return BluebirdPromise.resolve() + } + for (let i = 0; i < 3; i++) { try { - return await gitHubRequest(`/repos/${this.owner}/${this.repo}/releases/${this._releasePromise.value().id}`, this.token, null, "DELETE") + return await gitHubRequest(`/repos/${this.owner}/${this.repo}/releases/${release.id}`, this.token, null, "DELETE") } catch (e) { if (e instanceof HttpError && (e.response.statusCode === 405 || e.response.statusCode === 502)) { @@ -198,6 +203,6 @@ export class GitHubPublisher implements Publisher { } } - warn(`Cannot delete release ${this._releasePromise.value().id}`) + warn(`Cannot delete release ${release.id}`) } } \ No newline at end of file diff --git a/src/linuxPackager.ts b/src/linuxPackager.ts index 8f548408b1b..e71a6ede022 100755 --- a/src/linuxPackager.ts +++ b/src/linuxPackager.ts @@ -21,7 +21,7 @@ export class LinuxPackager extends PlatformPackager { } else { return Object.assign({ - description: this.appInfo.description, + description: this.info.appInfo.description, }, options) } } diff --git a/src/macPackager.ts b/src/macPackager.ts index 6f1a3fe9767..070de44c895 100644 --- a/src/macPackager.ts +++ b/src/macPackager.ts @@ -8,6 +8,7 @@ import { deepAssign } from "./util/deepAssign" import { signAsync, flatAsync, BaseSignOptions, SignOptions, FlatOptions } from "electron-osx-sign" import { DmgTarget } from "./targets/dmg" import { createCommonTarget, DEFAULT_TARGET } from "./targets/targetFactory" +import { AppInfo } from "./appInfo" //noinspection JSUnusedLocalSymbols const __awaiter = require("./util/awaiter") @@ -28,6 +29,10 @@ export default class MacPackager extends PlatformPackager { } } + protected prepareAppInfo(appInfo: AppInfo): AppInfo { + return new AppInfo(appInfo.metadata, this.devMetadata, this.platformSpecificBuildOptions.bundleVersion) + } + async getIconPath(): Promise { let iconPath = this.platformSpecificBuildOptions.icon || this.devMetadata.build.icon if (iconPath != null && !iconPath.endsWith(".icns")) { diff --git a/src/metadata.ts b/src/metadata.ts index e627842d5ea..1d63b70633c 100755 --- a/src/metadata.ts +++ b/src/metadata.ts @@ -248,6 +248,11 @@ export interface MacOptions extends PlatformSpecificBuildOptions { This option only applies when signing with `entitlements` provided. */ readonly entitlementsInherit?: string | null + + /* + The `CFBundleVersion`. Do not use it unless [you need to](see (https://github.com/electron-userland/electron-builder/issues/565#issuecomment-230678643)). + */ + readonly bundleVersion?: string | null } /* diff --git a/src/platformPackager.ts b/src/platformPackager.ts index 4276cd85bac..8569f93aeda 100644 --- a/src/platformPackager.ts +++ b/src/platformPackager.ts @@ -96,15 +96,14 @@ export abstract class PlatformPackager readonly appInfo: AppInfo constructor(public info: BuildInfo) { - this.appInfo = info.appInfo + this.devMetadata = info.devMetadata + this.platformSpecificBuildOptions = this.normalizePlatformSpecificBuildOptions((info.devMetadata.build)[this.platform.buildConfigurationKey]) + this.appInfo = this.prepareAppInfo(info.appInfo) this.options = info.options this.projectDir = info.projectDir - this.devMetadata = info.devMetadata this.buildResourcesDir = path.resolve(this.projectDir, this.relativeBuildResourcesDirname) - this.platformSpecificBuildOptions = this.normalizePlatformSpecificBuildOptions((info.devMetadata.build)[this.platform.buildConfigurationKey]) - this.resourceList = readdir(this.buildResourcesDir) .catch(e => { if (e.code !== "ENOENT") { @@ -114,6 +113,10 @@ export abstract class PlatformPackager }) } + protected prepareAppInfo(appInfo: AppInfo) { + return appInfo + } + normalizePlatformSpecificBuildOptions(options: DC | n): DC { return options == null ? Object.create(null) : options } diff --git a/templates/linux/AppRun.sh b/templates/linux/AppRun.sh index c59afdd9189..f159dd2bafb 100755 --- a/templates/linux/AppRun.sh +++ b/templates/linux/AppRun.sh @@ -43,7 +43,7 @@ trap atexit EXIT # http://stackoverflow.com/questions/3190818 atexit() { -if [ $NUMBER_OF_ARGS -eq 0 ] ; then +if [ "$NUMBER_OF_ARGS" -eq 0 ] ; then # if [ -z $(which "gtk-launch") ] ; then exec "${BIN}" # else @@ -172,29 +172,29 @@ if [ -z "$SKIP" ] ; then # and to /usr/share/applications if run as root # but that does not really work for me... desktop-file-install --rebuild-mime-info-cache \ - --vendor=$VENDORPREFIX --set-key=Exec --set-value="${APPIMAGE} %U" \ + --vendor=$VENDORPREFIX --set-key=Exec --set-value="$APPIMAGE %U" \ --set-key=X-AppImage-Comment --set-value="Generated by ${THIS}" \ - --set-icon="$VENDORPREFIX-$APP" --set-key=TryExec --set-value="${APPIMAGE}" "${DESKTOP_FILE}" \ + --set-icon="$VENDORPREFIX-$APP" --set-key=TryExec --set-value="$APPIMAGE" "$DESKTOP_FILE" \ --dir "$DESTINATION_DIR_DESKTOP" chmod a+x "$DESTINATION_DIR_DESKTOP/"* RESOURCE_NAME=$(echo "$VENDORPREFIX-$DESKTOP_FILE_NAME" | sed -e 's/.desktop//g') - echo ${RESOURCE_NAME} + echo "${RESOURCE_NAME}" # Install the icon files for the application; TODO: scalable - ICONS=$(find "${APPDIR}/usr/share/icons/" -path "*/apps/${APP}.png" || true) + ICONS=$(find "$APPDIR/usr/share/icons/" -path "*/apps/$APP.png" || true) for ICON in $ICONS ; do - ICON_SIZE=$(echo "${ICON}" | rev | cut -d "/" -f 3 | rev | cut -d "x" -f 1) - xdg-icon-resource install --context apps --size ${ICON_SIZE} "${ICON}" "${RESOURCE_NAME}" + ICON_SIZE=$(echo "$ICON" | rev | cut -d "/" -f 3 | rev | cut -d "x" -f 1) + xdg-icon-resource install --context apps --size "$ICON_SIZE" "$ICON" "$RESOURCE_NAME" done # Install mime type - find "${APPDIR}/usr/share/mime/" -type f -name *xml -exec xdg-mime install $SYSTEM_WIDE --novendor {} \; || true + find "$APPDIR/usr/share/mime/" -type f -name "*xml" -exec xdg-mime install ${SYSTEM_WIDE} --novendor {} \; || true # Install the icon files for the mime type; TODO: scalable ICONS=$(find "${APPDIR}/usr/share/icons/" -wholename "*/mimetypes/*.png" || true) for ICON in $ICONS ; do - ICON_SIZE=$(echo "${ICON}" | rev | cut -d "/" -f 3 | rev | cut -d "x" -f 1) - xdg-icon-resource install --context mimetypes --size ${ICON_SIZE} "${ICON}" $(basename $ICON | sed -e 's/.png//g') + ICON_SIZE=$(echo "$ICON" | rev | cut -d "/" -f 3 | rev | cut -d "x" -f 1) + xdg-icon-resource install --context mimetypes --size "$ICON_SIZE" "$ICON" $(basename "$ICON" | sed -e 's/.png//g') done xdg-desktop-menu forceupdate diff --git a/test/src/macPackagerTest.ts b/test/src/macPackagerTest.ts index 23a64a7d794..c635615141d 100644 --- a/test/src/macPackagerTest.ts +++ b/test/src/macPackagerTest.ts @@ -28,7 +28,7 @@ function createTargetTest(target: Array, expectedContents: Array devMetadata: { build: { mac: { - target: target + target: target, } } } @@ -186,7 +186,7 @@ test.ifOsx("custom background - new way", () => { }) }) -test.ifOsx("disable dmg icon", () => { +test.ifOsx("disable dmg icon, bundleVersion", () => { let platformPackager: CheckingMacPackager = null return assertPack("test-app-one", { targets: Platform.MAC.createTarget(), @@ -195,13 +195,17 @@ test.ifOsx("disable dmg icon", () => { build: { dmg: { icon: null, - } + }, + mac: { + bundleVersion: "50" + }, }, } }, { packed: () => { assertThat(platformPackager.effectiveDistOptions.icon).equal(null) assertThat(platformPackager.effectivePackOptions.icon).not.equal(null) + assertThat(platformPackager.effectivePackOptions["build-version"]).equal("50") return BluebirdPromise.resolve(null) }, })