Skip to content

Commit

Permalink
feat(mac): Add build-version override property
Browse files Browse the repository at this point in the history
Closes #565
  • Loading branch information
develar committed Jul 6, 2016
1 parent 1f16b41 commit 0b0ed62
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 32 deletions.
1 change: 1 addition & 0 deletions .idea/bashsupport_project.xml

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

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ MacOS specific build options.
| icon | <a name="MacOptions-icon"></a>The path to application icon. Defaults to `build/icon.icns` (consider using this convention instead of complicating your configuration).
| entitlements | <a name="MacOptions-entitlements"></a><p>The path to entitlements file for signing the app. <code>build/entitlements.mac.plist</code> will be used if exists (it is a recommended way to set). MAS entitlements is specified in the [.build.mas](#MasBuildOptions-entitlements).</p>
| entitlementsInherit | <a name="MacOptions-entitlementsInherit"></a><p>The path to child entitlements which inherit the security settings for signing frameworks and bundles of a distribution. <code>build/entitlements.mac.inherit.plist</code> 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).</p> <p>This option only applies when signing with <code>entitlements</code> provided.</p>
| bundleVersion | <a name="MacOptions-bundleVersion"></a>The `CFBundleVersion`. Do not use it unless [you need to](see (https://github.com/electron-userland/electron-builder/issues/565#issuecomment-230678643)).

<a name="DmgOptions"></a>
### `.build.dmg`
Expand Down
25 changes: 14 additions & 11 deletions src/appInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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) {
Expand Down
9 changes: 7 additions & 2 deletions src/gitHubPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -198,6 +203,6 @@ export class GitHubPublisher implements Publisher {
}
}

warn(`Cannot delete release ${this._releasePromise.value().id}`)
warn(`Cannot delete release ${release.id}`)
}
}
2 changes: 1 addition & 1 deletion src/linuxPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class LinuxPackager extends PlatformPackager<LinuxBuildOptions> {
}
else {
return Object.assign({
description: this.appInfo.description,
description: this.info.appInfo.description,
}, options)
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/macPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -28,6 +29,10 @@ export default class MacPackager extends PlatformPackager<MacOptions> {
}
}

protected prepareAppInfo(appInfo: AppInfo): AppInfo {
return new AppInfo(appInfo.metadata, this.devMetadata, this.platformSpecificBuildOptions.bundleVersion)
}

async getIconPath(): Promise<string | null> {
let iconPath = this.platformSpecificBuildOptions.icon || this.devMetadata.build.icon
if (iconPath != null && !iconPath.endsWith(".icns")) {
Expand Down
5 changes: 5 additions & 0 deletions src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/*
Expand Down
11 changes: 7 additions & 4 deletions src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,14 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
readonly appInfo: AppInfo

constructor(public info: BuildInfo) {
this.appInfo = info.appInfo
this.devMetadata = info.devMetadata
this.platformSpecificBuildOptions = this.normalizePlatformSpecificBuildOptions((<any>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((<any>info.devMetadata.build)[this.platform.buildConfigurationKey])

this.resourceList = readdir(this.buildResourcesDir)
.catch(e => {
if (e.code !== "ENOENT") {
Expand All @@ -114,6 +113,10 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
})
}

protected prepareAppInfo(appInfo: AppInfo) {
return appInfo
}

normalizePlatformSpecificBuildOptions(options: DC | n): DC {
return options == null ? Object.create(null) : options
}
Expand Down
20 changes: 10 additions & 10 deletions templates/linux/AppRun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions test/src/macPackagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function createTargetTest(target: Array<string>, expectedContents: Array<string>
devMetadata: {
build: {
mac: {
target: target
target: target,
}
}
}
Expand Down Expand Up @@ -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(),
Expand All @@ -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)
},
})
Expand Down

0 comments on commit 0b0ed62

Please sign in to comment.