Skip to content

Commit 9b29b68

Browse files
committed
Init
0 parents  commit 9b29b68

20 files changed

+296
-0
lines changed

Diff for: .editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = tab
5+
end_of_line = lf
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
10+
[{package.json,*.yml}]
11+
indent_style = space
12+
indent_size = 2

Diff for: .gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* text=auto
2+
*.js text eol=lf

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

Diff for: .travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
os: osx
2+
language: node_js
3+
node_js:
4+
- '6'
5+
- '4'

Diff for: assets/dmg-background.png

914 Bytes
Loading

Diff for: assets/[email protected]

2.02 KB
Loading

Diff for: cli.js

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env node
2+
'use strict';
3+
const path = require('path');
4+
const fs = require('fs');
5+
const meow = require('meow');
6+
const appdmg = require('appdmg');
7+
const plist = require('plist');
8+
const Ora = require('ora');
9+
const execa = require('execa');
10+
11+
const cli = meow(`
12+
Usage
13+
$ create-dmg <app>
14+
15+
Example
16+
$ create-dmg 'Lungo.app'
17+
`);
18+
19+
if (process.platform !== 'darwin') {
20+
console.error('macOS only');
21+
process.exit(1);
22+
}
23+
24+
if (cli.input.length === 0) {
25+
console.error('Specify an app');
26+
process.exit(1);
27+
}
28+
29+
const appPath = path.resolve(cli.input[0]);
30+
const appInfo = plist.parse(fs.readFileSync(path.join(appPath, 'Contents/Info.plist'), 'utf8'));
31+
const appName = appInfo.CFBundleName;
32+
const appIconName = appInfo.CFBundleIconFile.replace(/\.icns/, '');
33+
const dmgPath = `${appName} ${appInfo.CFBundleShortVersionString}.dmg`;
34+
35+
const ora = new Ora('Creating DMG');
36+
ora.start();
37+
38+
const ee = appdmg({
39+
target: dmgPath,
40+
basepath: __dirname,
41+
specification: {
42+
title: appName,
43+
icon: path.join(appPath, 'Contents/Resources', `${appIconName}.icns`),
44+
// Use transparent background and `background-color` option when this is fixed:
45+
// https://github.com/LinusU/node-appdmg/issues/135
46+
background: path.join(__dirname, 'assets/dmg-background.png'),
47+
'icon-size': 160,
48+
format: 'ULFO',
49+
window: {
50+
size: {
51+
width: 660,
52+
height: 400
53+
}
54+
},
55+
contents: [
56+
{
57+
x: 180,
58+
y: 170,
59+
type: 'file',
60+
path: appPath
61+
},
62+
{
63+
x: 480,
64+
y: 170,
65+
type: 'link',
66+
path: '/Applications'
67+
}
68+
]
69+
}
70+
});
71+
72+
ee.on('progress', info => {
73+
if (info.type === 'step-begin') {
74+
ora.text = info.title;
75+
}
76+
});
77+
78+
ee.on('finish', () => {
79+
ora.text = 'Code signing DMG';
80+
81+
execa('codesign', ['--sign', 'Developer ID Application', dmgPath]).then(() => {
82+
return execa.stderr('codesign', [dmgPath, '--display', '--verbose=2']);
83+
}).then(stderr => {
84+
const match = /^Authority=(.*)$/m.exec(stderr);
85+
86+
if (!match) {
87+
ora.fail('Not code signed');
88+
process.exit(1);
89+
}
90+
91+
ora.info(`Code signing identity: ${match[1]}`).start();
92+
ora.succeed('DMG created');
93+
}).catch(ora.fail.bind(ora));
94+
});
95+
96+
ee.on('error', err => {
97+
ora.fail(err);
98+
process.exit(1);
99+
});

Diff for: fixture.app/Contents/Info.plist

+54
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>CFBundleIconFile</key>
12+
<string>app.icns</string>
13+
<key>CFBundleIdentifier</key>
14+
<string>com.sindresorhus.create-dmg.fixture</string>
15+
<key>CFBundleInfoDictionaryVersion</key>
16+
<string>6.0</string>
17+
<key>CFBundleName</key>
18+
<string>fixture</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>

Diff for: fixture.app/Contents/MacOS/fixture

190 KB
Binary file not shown.

Diff for: fixture.app/Contents/PkgInfo

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

Diff for: fixture.app/Contents/Resources/app.icns

276 KB
Binary file not shown.

Diff for: license

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

Diff for: package.json

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "create-dmg",
3+
"version": "0.0.0",
4+
"description": "Create a DMG from an app (macOS)",
5+
"license": "MIT",
6+
"repository": "sindresorhus/create-dmg",
7+
"author": {
8+
"name": "Sindre Sorhus",
9+
"email": "[email protected]",
10+
"url": "sindresorhus.com"
11+
},
12+
"bin": {
13+
"create-dmg": "cli.js"
14+
},
15+
"engines": {
16+
"node": ">=4"
17+
},
18+
"scripts": {
19+
"test": "xo && ava"
20+
},
21+
"files": [
22+
"cli.js",
23+
"assets"
24+
],
25+
"keywords": [
26+
"cli-app",
27+
"cli",
28+
"create",
29+
"dmg",
30+
"disk",
31+
"image",
32+
"macos",
33+
"mac",
34+
"app",
35+
"application",
36+
"apple"
37+
],
38+
"dependencies": {
39+
"appdmg": "^0.4.5",
40+
"execa": "^0.6.3",
41+
"meow": "^3.4.2",
42+
"ora": "^1.2.0",
43+
"plist": "^2.0.1"
44+
},
45+
"devDependencies": {
46+
"ava": "*",
47+
"tempfile": "^1.1.1",
48+
"xo": "*"
49+
}
50+
}

Diff for: readme.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# create-dmg [![Build Status](https://travis-ci.org/sindresorhus/create-dmg.svg?branch=master)](https://travis-ci.org/sindresorhus/create-dmg)
2+
3+
> Create a [DMG](https://en.m.wikipedia.org/wiki/Apple_Disk_Image) from an app *(macOS)*
4+
5+
<img src="screenshot-cli.gif" width="529">
6+
7+
*This tool is intentionally opinionated and simple. I'm not interested in adding lots of options.*
8+
9+
10+
## Install
11+
12+
```
13+
$ npm install --global create-dmg
14+
```
15+
16+
17+
## Usage
18+
19+
```
20+
$ create-dmg --help
21+
22+
Usage
23+
$ create-dmg <app>
24+
25+
Example
26+
$ create-dmg 'Lungo.app'
27+
```
28+
29+
30+
## DMG
31+
32+
The created DMG is code signed, requires macOS 10.11 or later, and has the filename `${appName} ${appVersion}.dmg`, for example `Lungo 1.0.0.dmg`.
33+
34+
<img src="screenshot-dmg.png" width="772">
35+
36+
37+
## License
38+
39+
MIT © [Sindre Sorhus](https://sindresorhus.com)

Diff for: screenshot-cli.gif

274 KB
Loading

Diff for: screenshot-dmg.png

176 KB
Loading

Diff for: stuff/dmg-background.sketch

32 KB
Binary file not shown.

Diff for: test.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import path from 'path';
2+
import fs from 'fs';
3+
import test from 'ava';
4+
import execa from 'execa';
5+
import tempfile from 'tempfile';
6+
7+
test(async t => {
8+
const cwd = tempfile();
9+
fs.mkdirSync(cwd);
10+
await execa(path.join(__dirname, 'cli.js'), [path.join(__dirname, 'fixture.app')], {cwd});
11+
t.true(fs.existsSync(path.join(cwd, 'fixture 0.0.1.dmg')));
12+
});

0 commit comments

Comments
 (0)