Skip to content

Commit

Permalink
Handle app without an icon
Browse files Browse the repository at this point in the history
Fixes #51
  • Loading branch information
sindresorhus committed Apr 20, 2020
1 parent 4394f4f commit fab154f
Show file tree
Hide file tree
Showing 19 changed files with 84 additions and 8 deletions.
18 changes: 12 additions & 6 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ async function init() {
}

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

Expand All @@ -89,8 +88,13 @@ async function init() {
} catch (_) {}
}

ora.text = 'Creating icon';
const composedIconPath = await composeIcon(path.join(appPath, 'Contents/Resources', `${appIconName}.icns`));
const hasAppIcon = appInfo.CFBundleIconFile;
let composedIconPath;
if (hasAppIcon) {
ora.text = 'Creating icon';
const appIconName = appInfo.CFBundleIconFile.replace(/\.icns/, '');
composedIconPath = await composeIcon(path.join(appPath, 'Contents/Resources', `${appIconName}.icns`));
}

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

ora.text = 'Replacing DMG icon';
// `seticon`` is a native tool to change files icons (Source: https://github.com/sveinbjornt/osxiconutils)
await execa(path.join(__dirname, 'seticon'), [composedIconPath, dmgPath]);
if (hasAppIcon) {
ora.text = 'Replacing DMG icon';
// `seticon`` is a native tool to change files icons (Source: https://github.com/sveinbjornt/osxiconutils)
await execa(path.join(__dirname, 'seticon'), [composedIconPath, dmgPath]);
}

ora.text = 'Code signing DMG';
let identity;
Expand Down
54 changes: 54 additions & 0 deletions fixtures/Fixture-no-icon.app/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>15G1217</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>fixture</string>
<key>CFBundleIdentifier</key>
<string>com.sindresorhus.create-dmg.fixture</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Fixture</string>
<key>LSApplicationCategoryType</key>
<string></string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.0.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>MacOSX</string>
</array>
<key>CFBundleVersion</key>
<string>0.0.1</string>
<key>DTCompiler</key>
<string>com.apple.compilers.llvm.clang.1_0</string>
<key>DTPlatformBuild</key>
<string>8C38</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>16C58</string>
<key>DTSDKName</key>
<string>macosx10.12</string>
<key>DTXcode</key>
<string>0820</string>
<key>DTXcodeBuild</key>
<string>8C38</string>
<key>LSMinimumSystemVersion</key>
<string>10.11</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>EventViewerApplication</string>
<key>NSSupportsSuddenTermination</key>
<string>YES</string>
</dict>
</plist>
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added fixtures/Fixture.app/Contents/MacOS/fixture
Binary file not shown.
1 change: 1 addition & 0 deletions fixtures/Fixture.app/Contents/PkgInfo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
APPL????
Binary file not shown.
Binary file not shown.
File renamed without changes.
19 changes: 17 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test('main', async t => {
const cwd = tempy.directory();

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

try {
await execa(path.join(__dirname, 'cli.js'), [path.join(__dirname, 'fixture-with-binary-plist.app')], {cwd});
await execa(path.join(__dirname, 'cli.js'), [path.join(__dirname, 'fixtures/Fixture-with-binary-plist.app')], {cwd});
} catch (error) {
// Silence code signing failure
if (!error.message.includes('Code signing failed')) {
throw error;
}
}

t.true(fs.existsSync(path.join(cwd, 'Fixture 0.0.1.dmg')));
});

test('app without icon', async t => {
const cwd = tempy.directory();

try {
await execa(path.join(__dirname, 'cli.js'), [path.join(__dirname, 'fixtures/Fixture-no-icon.app')], {cwd});
} catch (error) {
// Silence code signing failure
if (!error.message.includes('Code signing failed')) {
Expand Down

0 comments on commit fab154f

Please sign in to comment.