Skip to content

Commit 0455338

Browse files
committed
Meta tweaks
1 parent a428a90 commit 0455338

8 files changed

+31
-19
lines changed

.gitattributes

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
* text=auto
2-
*.js text eol=lf
1+
* text=auto eol=lf

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
os: osx
22
language: node_js
33
node_js:
4+
- '12'
45
- '10'
56
- '8'

cli.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ async function init() {
117117
ee.on('finish', async () => {
118118
try {
119119
ora.text = 'Replacing DMG icon';
120-
// Seticon is a native tool to change files icons (Source: https://github.com/sveinbjornt/osxiconutils)
120+
// `seticon`` is a native tool to change files icons (Source: https://github.com/sveinbjornt/osxiconutils)
121121
await execa(path.join(__dirname, 'seticon'), [composedIconPath, dmgPath]);
122122

123123
ora.text = 'Code signing DMG';
@@ -128,9 +128,9 @@ async function init() {
128128
} else if (stdout.includes('Mac Developer:')) {
129129
identity = 'Mac Developer';
130130
} else {
131-
const err = new Error();
132-
err.stderr = 'No usable identity found';
133-
throw err;
131+
const error = new Error();
132+
error.stderr = 'No usable identity found';
133+
throw error;
134134
}
135135

136136
await execa('codesign', ['--sign', identity, dmgPath]);

compose-icon.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const readFile = promisify(fs.readFile);
99
const writeFile = promisify(fs.writeFile);
1010

1111
const filterMap = (map, filterFn) => Object.entries(map).filter(filterFn).reduce((out, [key, item]) => ({...out, [key]: item}), {});
12-
// Drive icon from /System/Library/Extensions/IOStorageFamily.kext/Contents/Resources/Removable.icns
12+
13+
// Drive icon from `/System/Library/Extensions/IOStorageFamily.kext/Contents/Resources/Removable.icns``
1314
const baseDiskIconPath = `${__dirname}/disk-icon.icns`;
1415

1516
async function composeIcon(type, appIcon, mountIcon, composedIcon) {
@@ -20,11 +21,13 @@ async function composeIcon(type, appIcon, mountIcon, composedIcon) {
2021

2122
// Change the perspective of the app icon to match the mount drive icon
2223
appIcon = appIcon.out('-matte').out('-virtual-pixel', 'transparent').out('-distort', 'Perspective', `1,1 ${appIconSize.width * 0.08},1 ${appIconSize.width},1 ${appIconSize.width * 0.92},1 1,${appIconSize.height} 1,${appIconSize.height} ${appIconSize.width},${appIconSize.height} ${appIconSize.width},${appIconSize.height}`);
24+
2325
// Resize the app icon to fit it inside the mount icon, aspect ration should not be kept to create the perspective illution
2426
appIcon = appIcon.resize(appIconSize.width / 1.7, appIconSize.height / 1.78, '!');
2527

2628
const tempAppIconPath = tempy.file({extension: 'png'});
2729
await promisify(appIcon.write.bind(appIcon))(tempAppIconPath);
30+
2831
// Compose the two icons
2932
const iconGravityFactor = mountIconSize.height * 0.155;
3033
mountIcon = mountIcon.composite(tempAppIconPath).gravity('Center').geometry(`+0-${iconGravityFactor}`);
@@ -40,14 +43,16 @@ const hasGm = async () => {
4043
if (error.code === 'ENOENT') {
4144
return false;
4245
}
46+
4347
throw error;
4448
}
4549
};
4650

47-
module.exports = async function (appIconPath) {
51+
module.exports = async appIconPath => {
4852
if (!await hasGm()) {
4953
return baseDiskIconPath;
5054
}
55+
5156
const baseDiskIcons = filterMap(icns.parse(await readFile(baseDiskIconPath)), ([key]) => icns.isImageType(key));
5257
const appIcon = filterMap(icns.parse(await readFile(appIconPath)), ([key]) => icns.isImageType(key));
5358

@@ -56,9 +61,13 @@ module.exports = async function (appIconPath) {
5661
if (baseDiskIcons[type]) {
5762
return composeIcon(type, icon, baseDiskIcons[type], composedIcon);
5863
}
64+
5965
console.warn('There is no base image for this type', type);
6066
}));
67+
6168
const tempComposedIcon = tempy.file({extension: 'icns'});
69+
6270
await writeFile(tempComposedIcon, icns.format(composedIcon));
71+
6372
return tempComposedIcon;
6473
};

icon-example-app.png

-13.9 KB
Loading

icon-example.png

-12.6 KB
Loading

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
},
2121
"files": [
2222
"cli.js",
23+
"compose-icon.js",
2324
"assets",
2425
"disk-icon.icns",
2526
"seticon"
@@ -45,10 +46,10 @@
4546
"meow": "^5.0.0",
4647
"ora": "^3.0.0",
4748
"plist": "^3.0.1",
48-
"tempy": "^0.2.1"
49+
"tempy": "^0.3.0"
4950
},
5051
"devDependencies": {
51-
"ava": "^0.25.0",
52-
"xo": "^0.23.0"
52+
"ava": "^1.4.1",
53+
"xo": "^0.24.0"
5354
}
5455
}

readme.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,20 @@ It will try to code sign the DMG, but the DMG is still created and fine even if
4949

5050
### DMG Icon
5151

52-
[GraphicsMagick](http://www.graphicsmagick.org/) is required to create the DMG icon based on the application icon and macOS mounted device icon.
52+
[GraphicsMagick](http://www.graphicsmagick.org) is required to create the custom DMG icon that's based on the app icon and the macOS mounted device icon.
5353

54-
### Steps using Brew
55-
```bash
56-
brew install imagemagick
57-
brew install graphicsmagick
54+
#### Steps using Homebrew
55+
56+
```
57+
$ brew install graphicsmagick imagemagick
5858
```
5959

60-
### Icon Example
60+
#### Icon Example
61+
62+
Original icon → DMG icon
63+
64+
<img src="icon-example-app.png" width="300"><img src="icon-example.png" width="300">
6165

62-
<img src="icon-example-app.png" width="300">
63-
<img src="icon-example.png" width="300">
6466

6567
## License
6668

0 commit comments

Comments
 (0)