Skip to content

Commit fab154f

Browse files
committed
Handle app without an icon
Fixes #51
1 parent 4394f4f commit fab154f

File tree

19 files changed

+84
-8
lines changed

19 files changed

+84
-8
lines changed

cli.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ async function init() {
7979
}
8080

8181
const appName = appInfo.CFBundleDisplayName || appInfo.CFBundleName;
82-
const appIconName = appInfo.CFBundleIconFile.replace(/\.icns/, '');
8382
const dmgTitle = appName.length > 27 ? (cli.flags.dmgTitle || appName) : appName;
8483
const dmgPath = path.join(destinationPath, `${appName} ${appInfo.CFBundleShortVersionString}.dmg`);
8584

@@ -89,8 +88,13 @@ async function init() {
8988
} catch (_) {}
9089
}
9190

92-
ora.text = 'Creating icon';
93-
const composedIconPath = await composeIcon(path.join(appPath, 'Contents/Resources', `${appIconName}.icns`));
91+
const hasAppIcon = appInfo.CFBundleIconFile;
92+
let composedIconPath;
93+
if (hasAppIcon) {
94+
ora.text = 'Creating icon';
95+
const appIconName = appInfo.CFBundleIconFile.replace(/\.icns/, '');
96+
composedIconPath = await composeIcon(path.join(appPath, 'Contents/Resources', `${appIconName}.icns`));
97+
}
9498

9599
const minSystemVersion = (Object.prototype.hasOwnProperty.call(appInfo, 'LSMinimumSystemVersion') && appInfo.LSMinimumSystemVersion.length > 0) ? appInfo.LSMinimumSystemVersion.toString() : '10.11';
96100
const minorVersion = Number(minSystemVersion.split('.')[1]) || 0;
@@ -143,9 +147,11 @@ async function init() {
143147
ora.text = 'Adding Software License Agreement if needed';
144148
await addLicenseAgreementIfNeeded(dmgPath, dmgFormat);
145149

146-
ora.text = 'Replacing DMG icon';
147-
// `seticon`` is a native tool to change files icons (Source: https://github.com/sveinbjornt/osxiconutils)
148-
await execa(path.join(__dirname, 'seticon'), [composedIconPath, dmgPath]);
150+
if (hasAppIcon) {
151+
ora.text = 'Replacing DMG icon';
152+
// `seticon`` is a native tool to change files icons (Source: https://github.com/sveinbjornt/osxiconutils)
153+
await execa(path.join(__dirname, 'seticon'), [composedIconPath, dmgPath]);
154+
}
149155

150156
ora.text = 'Code signing DMG';
151157
let identity;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>BuildMachineOSBuild</key>
6+
<string>15G1217</string>
7+
<key>CFBundleDevelopmentRegion</key>
8+
<string>English</string>
9+
<key>CFBundleExecutable</key>
10+
<string>fixture</string>
11+
<key>CFBundleIdentifier</key>
12+
<string>com.sindresorhus.create-dmg.fixture</string>
13+
<key>CFBundleInfoDictionaryVersion</key>
14+
<string>6.0</string>
15+
<key>CFBundleName</key>
16+
<string>Fixture</string>
17+
<key>LSApplicationCategoryType</key>
18+
<string></string>
19+
<key>CFBundlePackageType</key>
20+
<string>APPL</string>
21+
<key>CFBundleShortVersionString</key>
22+
<string>0.0.1</string>
23+
<key>CFBundleSignature</key>
24+
<string>????</string>
25+
<key>CFBundleSupportedPlatforms</key>
26+
<array>
27+
<string>MacOSX</string>
28+
</array>
29+
<key>CFBundleVersion</key>
30+
<string>0.0.1</string>
31+
<key>DTCompiler</key>
32+
<string>com.apple.compilers.llvm.clang.1_0</string>
33+
<key>DTPlatformBuild</key>
34+
<string>8C38</string>
35+
<key>DTPlatformVersion</key>
36+
<string>GM</string>
37+
<key>DTSDKBuild</key>
38+
<string>16C58</string>
39+
<key>DTSDKName</key>
40+
<string>macosx10.12</string>
41+
<key>DTXcode</key>
42+
<string>0820</string>
43+
<key>DTXcodeBuild</key>
44+
<string>8C38</string>
45+
<key>LSMinimumSystemVersion</key>
46+
<string>10.11</string>
47+
<key>NSMainNibFile</key>
48+
<string>MainMenu</string>
49+
<key>NSPrincipalClass</key>
50+
<string>EventViewerApplication</string>
51+
<key>NSSupportsSuddenTermination</key>
52+
<string>YES</string>
53+
</dict>
54+
</plist>
File renamed without changes.
190 KB
Binary file not shown.

fixtures/Fixture.app/Contents/PkgInfo

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
APPL????
Binary file not shown.
Binary file not shown.

test.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test('main', async t => {
88
const cwd = tempy.directory();
99

1010
try {
11-
await execa(path.join(__dirname, 'cli.js'), [path.join(__dirname, 'fixture.app')], {cwd});
11+
await execa(path.join(__dirname, 'cli.js'), [path.join(__dirname, 'fixtures/Fixture.app')], {cwd});
1212
} catch (error) {
1313
// Silence code signing failure
1414
if (!error.message.includes('Code signing failed')) {
@@ -23,7 +23,22 @@ test('binary plist', async t => {
2323
const cwd = tempy.directory();
2424

2525
try {
26-
await execa(path.join(__dirname, 'cli.js'), [path.join(__dirname, 'fixture-with-binary-plist.app')], {cwd});
26+
await execa(path.join(__dirname, 'cli.js'), [path.join(__dirname, 'fixtures/Fixture-with-binary-plist.app')], {cwd});
27+
} catch (error) {
28+
// Silence code signing failure
29+
if (!error.message.includes('Code signing failed')) {
30+
throw error;
31+
}
32+
}
33+
34+
t.true(fs.existsSync(path.join(cwd, 'Fixture 0.0.1.dmg')));
35+
});
36+
37+
test('app without icon', async t => {
38+
const cwd = tempy.directory();
39+
40+
try {
41+
await execa(path.join(__dirname, 'cli.js'), [path.join(__dirname, 'fixtures/Fixture-no-icon.app')], {cwd});
2742
} catch (error) {
2843
// Silence code signing failure
2944
if (!error.message.includes('Code signing failed')) {

0 commit comments

Comments
 (0)