Skip to content

Commit

Permalink
fix(mac): build.fileAssociations icon links to original file in output
Browse files Browse the repository at this point in the history
Closes #954
  • Loading branch information
develar committed Dec 1, 2016
1 parent c2eb8c2 commit d289f4b
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 25 deletions.
23 changes: 19 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
node_modules/
*.log
out/

#**/out/**/*
#!**/*js.snap

dist/

/.idea/compiler.xml
/.idea/encodings.xml
/.idea/copyright/profiles_settings.xml
/.idea/workspace.xml
/.idea/copyright/
/.idea/deployment.xml
/.idea/shelf/

/docs/.idea/

/typings/browser/
/typings/browser.d.ts
/typings/main.d.ts

.DS_Store
.idea/shelf/

/test/typings/electron-builder.d.ts
/test/typings/electron-auto-updater.d.ts
/test/typings/electron-auto-updater.d.ts

/nsis-auto-updater/out/
/out/
# to not exclude .js.snap (jest snapshots)
/test/out/**/*.js
/test/out/**/*.map
5 changes: 5 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"devDependencies": {
"@develar/semantic-release": "^6.3.24",
"@types/ini": "^1.3.29",
"@types/jest": "^16.0.0",
"@types/jest": "^16.0.1",
"@types/js-yaml": "^3.5.28",
"@types/source-map-support": "^0.2.28",
"babel-plugin-array-includes": "^2.0.3",
Expand All @@ -115,7 +115,7 @@
"jest-cli": "^17.0.3",
"json8": "^0.9.2",
"path-sort": "^0.1.0",
"ts-babel": "^1.1.5",
"ts-babel": "^1.2.2",
"tslint": "^4.0.2",
"typescript": "^2.1.1",
"validate-commit-msg": "^2.8.2",
Expand Down
16 changes: 12 additions & 4 deletions src/packager/mac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import BluebirdPromise from "bluebird-lst-c"
import { use, asArray } from "../util/util"
import { normalizeExt, PlatformPackager } from "../platformPackager"
import { warn } from "../util/log"
import { unlinkIfExists } from "../util/fs"
import { unlinkIfExists, copyFile } from "../util/fs"

function doRename (basePath: string, oldName: string, newName: string) {
return rename(path.join(basePath, oldName), path.join(basePath, newName))
Expand Down Expand Up @@ -98,17 +98,25 @@ export async function createApp(packager: PlatformPackager<any>, appOutDir: stri
})
}

const resourcesPath = path.join(contentsPath, "Resources")

const fileAssociations = packager.getFileAssociations()
if (fileAssociations.length > 0) {
appPlist.CFBundleDocumentTypes = await BluebirdPromise.map(fileAssociations, async fileAssociation => {
const extensions = asArray(fileAssociation.ext).map(normalizeExt)
const customIcon = await packager.getResource(fileAssociation.icon, `${extensions[0]}.icns`)
let iconFile = appPlist.CFBundleIconFile
if (customIcon != null) {
iconFile = path.basename(customIcon)
await copyFile(customIcon, path.join(resourcesPath, iconFile))
}

// todo rename electron.icns
return <any>{
CFBundleTypeExtensions: extensions,
CFBundleTypeName: fileAssociation.name,
CFBundleTypeRole: fileAssociation.role || "Editor",
CFBundleTypeIconFile: customIcon || appPlist.CFBundleIconFile
CFBundleTypeIconFile: iconFile
}
})
}
Expand All @@ -127,8 +135,8 @@ export async function createApp(packager: PlatformPackager<any>, appOutDir: stri
]

if (icon != null) {
promises.push(unlink(path.join(contentsPath, "Resources", oldIcon)))
promises.push(copy(icon, path.join(contentsPath, "Resources", appPlist.CFBundleIconFile)))
promises.push(unlink(path.join(resourcesPath, oldIcon)))
promises.push(copy(icon, path.join(resourcesPath, appPlist.CFBundleIconFile)))
}

await BluebirdPromise.all(promises)
Expand Down
35 changes: 35 additions & 0 deletions test/out/mac/__snapshots__/macPackagerTest.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
exports[`test one-package 1`] = `
Object {
"BuildMachineOSBuild": "15E65",
"CFBundleDisplayName": "Test App ß/W",
"CFBundleDocumentTypes": Array [
Object {
"CFBundleTypeExtensions": Array [
"foo",
],
"CFBundleTypeIconFile": "foo.icns",
"CFBundleTypeName": "Foo",
"CFBundleTypeRole": "Viewer",
},
],
"CFBundleExecutable": "Test App ßW",
"CFBundleIconFile": "Test App ßW.icns",
"CFBundleIdentifier": "org.electron-builder.testApp",
"CFBundleInfoDictionaryVersion": "6.0",
"CFBundleName": "Test App ß/W",
"CFBundlePackageType": "APPL",
"CFBundleShortVersionString": "1.1.0",
"CFBundleVersion": "1.1.0.42",
"DTSDKBuild": "14D125",
"DTSDKName": "macosx10.1010.10",
"DTXcode": "0721",
"DTXcodeBuild": "7C1002",
"LSApplicationCategoryType": "your.app.category.type",
"LSMinimumSystemVersion": "10.9.0",
"NSHighResolutionCapable": true,
"NSHumanReadableCopyright": "Copyright © 2016 Foo Bar",
"NSMainNibFile": "MainMenu",
"NSPrincipalClass": "AtomApplication",
"NSSupportsAutomaticGraphicsSwitching": true,
}
`;
9 changes: 7 additions & 2 deletions test/src/helpers/packTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface AssertPackOptions {
readonly expectedArtifacts?: Array<string>

readonly expectedDepends?: string
readonly checkMacApp?: (appDir: string, info: any) => Promise<any>

readonly useTempDir?: boolean
readonly signed?: boolean
Expand Down Expand Up @@ -184,7 +185,7 @@ async function packAndCheck(outDir: string, packagerOptions: PackagerOptions, ch

const nameToTarget = platformToTarget.get(platform)
if (platform === Platform.MAC) {
await checkOsXResult(packager, packagerOptions, checkOptions, artifacts.get(Platform.MAC))
await checkMacResult(packager, packagerOptions, checkOptions, artifacts.get(Platform.MAC))
}
else if (platform === Platform.LINUX) {
await checkLinuxResult(outDir, packager, checkOptions, artifacts.get(Platform.LINUX), arch, nameToTarget)
Expand Down Expand Up @@ -273,7 +274,7 @@ function parseDebControl(info: string): any {
return metadata
}

async function checkOsXResult(packager: Packager, packagerOptions: PackagerOptions, checkOptions: AssertPackOptions, artifacts: Array<ArtifactCreated>) {
async function checkMacResult(packager: Packager, packagerOptions: PackagerOptions, checkOptions: AssertPackOptions, artifacts: Array<ArtifactCreated>) {
const appInfo = packager.appInfo
const packedAppDir = path.join(path.dirname(artifacts[0].file), `${appInfo.productFilename}.app`)
const info = parsePlist(await readFile(path.join(packedAppDir, "Contents", "Info.plist"), "utf8"))
Expand All @@ -284,6 +285,10 @@ async function checkOsXResult(packager: Packager, packagerOptions: PackagerOptio
CFBundleVersion: `${appInfo.version}.${(process.env.TRAVIS_BUILD_NUMBER || process.env.CIRCLE_BUILD_NUM)}`
})

if (checkOptions.checkMacApp != null) {
await checkOptions.checkMacApp(packedAppDir, info)
}

if (packagerOptions.cscLink != null) {
const result = await exec("codesign", ["--verify", packedAppDir])
expect(result).not.toMatch(/is not signed at all/)
Expand Down
29 changes: 27 additions & 2 deletions test/src/mac/macPackagerTest.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
import { assertPack, platform, modifyPackageJson, app, appThrows } from "../helpers/packTester"
import { Platform, createTargets } from "out"
import { DIR_TARGET } from "out/targets/targetFactory"
import { copyFile } from "out/util/fs"
import * as path from "path"
import { assertThat } from "../helpers/fileAssert"

test.ifMac("two-package", () => assertPack("test-app", {targets: createTargets([Platform.MAC], null, "all")}, {signed: true, useTempDir: true}))

test.ifMac("one-package", app(platform(Platform.MAC), {signed: true}))
test.ifMac("one-package", app({
targets: Platform.MAC.createTarget(),
devMetadata: {
build: {
mac: {
fileAssociations: [
{
ext: "foo",
name: "Foo",
role: "Viewer",
},
]
}
}
}
}, {
signed: true,
projectDirCreated: projectDir => copyFile(path.join(projectDir, "build", "icon.icns"), path.join(projectDir, "build", "foo.icns")),
checkMacApp: async (appDir, info) => {
expect(info).toMatchSnapshot()
await assertThat(path.join(appDir, "Contents", "Resources", "foo.icns")).isFile()
},
}))

test.ifMac("electronDist", appThrows(/ENOENT: no such file or directory/, {
targets: Platform.OSX.createTarget(DIR_TARGET),
targets: Platform.MAC.createTarget(DIR_TARGET),
}, {
projectDirCreated: projectDir => modifyPackageJson(projectDir, data => {
data.build.electronDist = "foo"
Expand Down
22 changes: 11 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
version "1.3.29"
resolved "https://registry.yarnpkg.com/@types/ini/-/ini-1.3.29.tgz#1325e981e047d40d13ce0359b821475b97741d2f"

"@types/jest@^16.0.0":
version "16.0.0"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-16.0.0.tgz#5fe49adee6db194357a52438c0d80695b59a45e9"
"@types/jest@^16.0.1":
version "16.0.1"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-16.0.1.tgz#c7820ab2bedefe121d0e5ffaa8d0b22f44793f24"

"@types/js-yaml@^3.5.28":
version "3.5.28"
Expand Down Expand Up @@ -2435,9 +2435,9 @@ map-stream@~0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/map-stream/-/map-stream-0.1.0.tgz#e56aa94c4c8055a16404a0674b78f215f7c8e194"

markdown-it@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-8.1.0.tgz#38902d4e7bac2260c073eb67be623211fbb2c2e3"
markdown-it@^8.2.0:
version "8.2.0"
resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-8.2.0.tgz#089e924bc2efd3886a2eb8ab869109c5ceb73958"
dependencies:
argparse "^1.0.7"
entities "~1.1.1"
Expand Down Expand Up @@ -3485,15 +3485,15 @@ truncate-utf8-bytes@^1.0.0:
dependencies:
utf8-byte-length "^1.0.1"

ts-babel@^1.1.5:
version "1.1.5"
resolved "https://registry.yarnpkg.com/ts-babel/-/ts-babel-1.1.5.tgz#5a83460bb66eeb6c5af727ad18afb4f3c6e189b8"
ts-babel@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/ts-babel/-/ts-babel-1.2.2.tgz#d2e315c9202924b4979adcf56c047aa7ba1e002d"
dependencies:
babel-core "^6.18.2"
bluebird-lst-c "^1.0.5"
chalk "^1.1.3"
fs-extra-p "^3.0.2"
markdown-it "^8.1.0"
fs-extra-p "^3.0.3"
markdown-it "^8.2.0"
source-map-support "^0.4.6"

tslint@^4.0.2:
Expand Down

0 comments on commit d289f4b

Please sign in to comment.