Skip to content

Commit 0b0ed62

Browse files
committed
feat(mac): Add build-version override property
Closes #565
1 parent 1f16b41 commit 0b0ed62

File tree

11 files changed

+59
-32
lines changed

11 files changed

+59
-32
lines changed

.idea/bashsupport_project.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ install:
2828
- nvm install $NODE_VERSION
2929
- nvm use --delete-prefix $NODE_VERSION
3030
- if [[ "$TRAVIS_OS_NAME" == "osx" && "$NODE_VERSION" == "4" ]]; then npm install npm -g ; fi
31-
- npm install
31+
- npm install --registry http://registry.npmjs.eu
3232
- npm prune
3333

3434
script:

docs/Options.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ MacOS specific build options.
7878
| 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).
7979
| 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>
8080
| 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>
81+
| 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)).
8182

8283
<a name="DmgOptions"></a>
8384
### `.build.dmg`

src/appInfo.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,26 @@ export class AppInfo {
2222
}
2323

2424
readonly version: string
25+
readonly buildNumber: string
2526
readonly buildVersion: string
2627

2728
readonly productFilename: string
2829

29-
constructor(public metadata: AppMetadata, private devMetadata: DevMetadata) {
30-
let buildVersion = metadata.version!
31-
this.version = buildVersion
30+
constructor(public metadata: AppMetadata, private devMetadata: DevMetadata, buildVersion?: string | null) {
31+
this.version = metadata.version!
3232

33-
const buildNumber = this.buildNumber
34-
if (!isEmptyOrSpaces(buildNumber)) {
35-
buildVersion += `.${buildNumber}`
33+
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
34+
35+
if (isEmptyOrSpaces(buildVersion)) {
36+
buildVersion = this.version
37+
if (!isEmptyOrSpaces(this.buildNumber)) {
38+
buildVersion += `.${this.buildNumber}`
39+
}
40+
this.buildVersion = buildVersion
41+
}
42+
else {
43+
this.buildVersion = buildVersion!
3644
}
37-
this.buildVersion = buildVersion
3845

3946
this.productFilename = sanitizeFileName(this.productName)
4047
}
@@ -43,10 +50,6 @@ export class AppInfo {
4350
return this.metadata.author!.name
4451
}
4552

46-
get buildNumber(): string | null {
47-
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
48-
}
49-
5053
get id(): string {
5154
const appId = this.devMetadata.build["app-bundle-id"]
5255
if (appId != null) {

src/gitHubPublisher.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,14 @@ export class GitHubPublisher implements Publisher {
185185
return BluebirdPromise.resolve()
186186
}
187187

188+
const release = this._releasePromise.value()
189+
if (release == null) {
190+
return BluebirdPromise.resolve()
191+
}
192+
188193
for (let i = 0; i < 3; i++) {
189194
try {
190-
return await gitHubRequest(`/repos/${this.owner}/${this.repo}/releases/${this._releasePromise.value().id}`, this.token, null, "DELETE")
195+
return await gitHubRequest(`/repos/${this.owner}/${this.repo}/releases/${release.id}`, this.token, null, "DELETE")
191196
}
192197
catch (e) {
193198
if (e instanceof HttpError && (e.response.statusCode === 405 || e.response.statusCode === 502)) {
@@ -198,6 +203,6 @@ export class GitHubPublisher implements Publisher {
198203
}
199204
}
200205

201-
warn(`Cannot delete release ${this._releasePromise.value().id}`)
206+
warn(`Cannot delete release ${release.id}`)
202207
}
203208
}

src/linuxPackager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class LinuxPackager extends PlatformPackager<LinuxBuildOptions> {
2121
}
2222
else {
2323
return Object.assign({
24-
description: this.appInfo.description,
24+
description: this.info.appInfo.description,
2525
}, options)
2626
}
2727
}

src/macPackager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { deepAssign } from "./util/deepAssign"
88
import { signAsync, flatAsync, BaseSignOptions, SignOptions, FlatOptions } from "electron-osx-sign"
99
import { DmgTarget } from "./targets/dmg"
1010
import { createCommonTarget, DEFAULT_TARGET } from "./targets/targetFactory"
11+
import { AppInfo } from "./appInfo"
1112

1213
//noinspection JSUnusedLocalSymbols
1314
const __awaiter = require("./util/awaiter")
@@ -28,6 +29,10 @@ export default class MacPackager extends PlatformPackager<MacOptions> {
2829
}
2930
}
3031

32+
protected prepareAppInfo(appInfo: AppInfo): AppInfo {
33+
return new AppInfo(appInfo.metadata, this.devMetadata, this.platformSpecificBuildOptions.bundleVersion)
34+
}
35+
3136
async getIconPath(): Promise<string | null> {
3237
let iconPath = this.platformSpecificBuildOptions.icon || this.devMetadata.build.icon
3338
if (iconPath != null && !iconPath.endsWith(".icns")) {

src/metadata.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ export interface MacOptions extends PlatformSpecificBuildOptions {
248248
This option only applies when signing with `entitlements` provided.
249249
*/
250250
readonly entitlementsInherit?: string | null
251+
252+
/*
253+
The `CFBundleVersion`. Do not use it unless [you need to](see (https://github.com/electron-userland/electron-builder/issues/565#issuecomment-230678643)).
254+
*/
255+
readonly bundleVersion?: string | null
251256
}
252257

253258
/*

src/platformPackager.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,14 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
9696
readonly appInfo: AppInfo
9797

9898
constructor(public info: BuildInfo) {
99-
this.appInfo = info.appInfo
99+
this.devMetadata = info.devMetadata
100+
this.platformSpecificBuildOptions = this.normalizePlatformSpecificBuildOptions((<any>info.devMetadata.build)[this.platform.buildConfigurationKey])
101+
this.appInfo = this.prepareAppInfo(info.appInfo)
100102
this.options = info.options
101103
this.projectDir = info.projectDir
102-
this.devMetadata = info.devMetadata
103104

104105
this.buildResourcesDir = path.resolve(this.projectDir, this.relativeBuildResourcesDirname)
105106

106-
this.platformSpecificBuildOptions = this.normalizePlatformSpecificBuildOptions((<any>info.devMetadata.build)[this.platform.buildConfigurationKey])
107-
108107
this.resourceList = readdir(this.buildResourcesDir)
109108
.catch(e => {
110109
if (e.code !== "ENOENT") {
@@ -114,6 +113,10 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
114113
})
115114
}
116115

116+
protected prepareAppInfo(appInfo: AppInfo) {
117+
return appInfo
118+
}
119+
117120
normalizePlatformSpecificBuildOptions(options: DC | n): DC {
118121
return options == null ? Object.create(null) : options
119122
}

templates/linux/AppRun.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ trap atexit EXIT
4343
# http://stackoverflow.com/questions/3190818
4444
atexit()
4545
{
46-
if [ $NUMBER_OF_ARGS -eq 0 ] ; then
46+
if [ "$NUMBER_OF_ARGS" -eq 0 ] ; then
4747
# if [ -z $(which "gtk-launch") ] ; then
4848
exec "${BIN}"
4949
# else
@@ -172,29 +172,29 @@ if [ -z "$SKIP" ] ; then
172172
# and to /usr/share/applications if run as root
173173
# but that does not really work for me...
174174
desktop-file-install --rebuild-mime-info-cache \
175-
--vendor=$VENDORPREFIX --set-key=Exec --set-value="${APPIMAGE} %U" \
175+
--vendor=$VENDORPREFIX --set-key=Exec --set-value="$APPIMAGE %U" \
176176
--set-key=X-AppImage-Comment --set-value="Generated by ${THIS}" \
177-
--set-icon="$VENDORPREFIX-$APP" --set-key=TryExec --set-value="${APPIMAGE}" "${DESKTOP_FILE}" \
177+
--set-icon="$VENDORPREFIX-$APP" --set-key=TryExec --set-value="$APPIMAGE" "$DESKTOP_FILE" \
178178
--dir "$DESTINATION_DIR_DESKTOP"
179179
chmod a+x "$DESTINATION_DIR_DESKTOP/"*
180180
RESOURCE_NAME=$(echo "$VENDORPREFIX-$DESKTOP_FILE_NAME" | sed -e 's/.desktop//g')
181-
echo ${RESOURCE_NAME}
181+
echo "${RESOURCE_NAME}"
182182

183183
# Install the icon files for the application; TODO: scalable
184-
ICONS=$(find "${APPDIR}/usr/share/icons/" -path "*/apps/${APP}.png" || true)
184+
ICONS=$(find "$APPDIR/usr/share/icons/" -path "*/apps/$APP.png" || true)
185185
for ICON in $ICONS ; do
186-
ICON_SIZE=$(echo "${ICON}" | rev | cut -d "/" -f 3 | rev | cut -d "x" -f 1)
187-
xdg-icon-resource install --context apps --size ${ICON_SIZE} "${ICON}" "${RESOURCE_NAME}"
186+
ICON_SIZE=$(echo "$ICON" | rev | cut -d "/" -f 3 | rev | cut -d "x" -f 1)
187+
xdg-icon-resource install --context apps --size "$ICON_SIZE" "$ICON" "$RESOURCE_NAME"
188188
done
189189

190190
# Install mime type
191-
find "${APPDIR}/usr/share/mime/" -type f -name *xml -exec xdg-mime install $SYSTEM_WIDE --novendor {} \; || true
191+
find "$APPDIR/usr/share/mime/" -type f -name "*xml" -exec xdg-mime install ${SYSTEM_WIDE} --novendor {} \; || true
192192

193193
# Install the icon files for the mime type; TODO: scalable
194194
ICONS=$(find "${APPDIR}/usr/share/icons/" -wholename "*/mimetypes/*.png" || true)
195195
for ICON in $ICONS ; do
196-
ICON_SIZE=$(echo "${ICON}" | rev | cut -d "/" -f 3 | rev | cut -d "x" -f 1)
197-
xdg-icon-resource install --context mimetypes --size ${ICON_SIZE} "${ICON}" $(basename $ICON | sed -e 's/.png//g')
196+
ICON_SIZE=$(echo "$ICON" | rev | cut -d "/" -f 3 | rev | cut -d "x" -f 1)
197+
xdg-icon-resource install --context mimetypes --size "$ICON_SIZE" "$ICON" $(basename "$ICON" | sed -e 's/.png//g')
198198
done
199199

200200
xdg-desktop-menu forceupdate

0 commit comments

Comments
 (0)