commit 9b29b6853faaecd10c86e02538065c2f4c3ffdf2 Author: Sindre Sorhus Date: Mon Mar 27 21:09:27 2017 +0700 Init diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..98a761d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +indent_style = tab +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[{package.json,*.yml}] +indent_style = space +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..391f0a4 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +* text=auto +*.js text eol=lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..dffce55 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +os: osx +language: node_js +node_js: + - '6' + - '4' diff --git a/assets/dmg-background.png b/assets/dmg-background.png new file mode 100644 index 0000000..21e9c9e Binary files /dev/null and b/assets/dmg-background.png differ diff --git a/assets/dmg-background@2x.png b/assets/dmg-background@2x.png new file mode 100644 index 0000000..6c79aee Binary files /dev/null and b/assets/dmg-background@2x.png differ diff --git a/cli.js b/cli.js new file mode 100755 index 0000000..b2af6c5 --- /dev/null +++ b/cli.js @@ -0,0 +1,99 @@ +#!/usr/bin/env node +'use strict'; +const path = require('path'); +const fs = require('fs'); +const meow = require('meow'); +const appdmg = require('appdmg'); +const plist = require('plist'); +const Ora = require('ora'); +const execa = require('execa'); + +const cli = meow(` + Usage + $ create-dmg + + Example + $ create-dmg 'Lungo.app' +`); + +if (process.platform !== 'darwin') { + console.error('macOS only'); + process.exit(1); +} + +if (cli.input.length === 0) { + console.error('Specify an app'); + process.exit(1); +} + +const appPath = path.resolve(cli.input[0]); +const appInfo = plist.parse(fs.readFileSync(path.join(appPath, 'Contents/Info.plist'), 'utf8')); +const appName = appInfo.CFBundleName; +const appIconName = appInfo.CFBundleIconFile.replace(/\.icns/, ''); +const dmgPath = `${appName} ${appInfo.CFBundleShortVersionString}.dmg`; + +const ora = new Ora('Creating DMG'); +ora.start(); + +const ee = appdmg({ + target: dmgPath, + basepath: __dirname, + specification: { + title: appName, + icon: path.join(appPath, 'Contents/Resources', `${appIconName}.icns`), + // Use transparent background and `background-color` option when this is fixed: + // https://github.com/LinusU/node-appdmg/issues/135 + background: path.join(__dirname, 'assets/dmg-background.png'), + 'icon-size': 160, + format: 'ULFO', + window: { + size: { + width: 660, + height: 400 + } + }, + contents: [ + { + x: 180, + y: 170, + type: 'file', + path: appPath + }, + { + x: 480, + y: 170, + type: 'link', + path: '/Applications' + } + ] + } +}); + +ee.on('progress', info => { + if (info.type === 'step-begin') { + ora.text = info.title; + } +}); + +ee.on('finish', () => { + ora.text = 'Code signing DMG'; + + execa('codesign', ['--sign', 'Developer ID Application', dmgPath]).then(() => { + return execa.stderr('codesign', [dmgPath, '--display', '--verbose=2']); + }).then(stderr => { + const match = /^Authority=(.*)$/m.exec(stderr); + + if (!match) { + ora.fail('Not code signed'); + process.exit(1); + } + + ora.info(`Code signing identity: ${match[1]}`).start(); + ora.succeed('DMG created'); + }).catch(ora.fail.bind(ora)); +}); + +ee.on('error', err => { + ora.fail(err); + process.exit(1); +}); diff --git a/fixture.app/Contents/Info.plist b/fixture.app/Contents/Info.plist new file mode 100644 index 0000000..1490323 --- /dev/null +++ b/fixture.app/Contents/Info.plist @@ -0,0 +1,54 @@ + + + + + BuildMachineOSBuild + 15G1217 + CFBundleDevelopmentRegion + English + CFBundleExecutable + fixture + CFBundleIconFile + app.icns + CFBundleIdentifier + com.sindresorhus.create-dmg.fixture + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + fixture + CFBundlePackageType + APPL + CFBundleShortVersionString + 0.0.1 + CFBundleSignature + ???? + CFBundleSupportedPlatforms + + MacOSX + + CFBundleVersion + 0.0.1 + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTPlatformBuild + 8C38 + DTPlatformVersion + GM + DTSDKBuild + 16C58 + DTSDKName + macosx10.12 + DTXcode + 0820 + DTXcodeBuild + 8C38 + LSMinimumSystemVersion + 10.11 + NSMainNibFile + MainMenu + NSPrincipalClass + EventViewerApplication + NSSupportsSuddenTermination + YES + + diff --git a/fixture.app/Contents/MacOS/fixture b/fixture.app/Contents/MacOS/fixture new file mode 100755 index 0000000..58aa377 Binary files /dev/null and b/fixture.app/Contents/MacOS/fixture differ diff --git a/fixture.app/Contents/PkgInfo b/fixture.app/Contents/PkgInfo new file mode 100644 index 0000000..bd04210 --- /dev/null +++ b/fixture.app/Contents/PkgInfo @@ -0,0 +1 @@ +APPL???? \ No newline at end of file diff --git a/fixture.app/Contents/Resources/English.lproj/InfoPlist.strings b/fixture.app/Contents/Resources/English.lproj/InfoPlist.strings new file mode 100644 index 0000000..5e45963 Binary files /dev/null and b/fixture.app/Contents/Resources/English.lproj/InfoPlist.strings differ diff --git a/fixture.app/Contents/Resources/English.lproj/MainMenu.nib b/fixture.app/Contents/Resources/English.lproj/MainMenu.nib new file mode 100644 index 0000000..fdd1e70 Binary files /dev/null and b/fixture.app/Contents/Resources/English.lproj/MainMenu.nib differ diff --git a/fixture.app/Contents/Resources/app.icns b/fixture.app/Contents/Resources/app.icns new file mode 100644 index 0000000..2685aa9 Binary files /dev/null and b/fixture.app/Contents/Resources/app.icns differ diff --git a/license b/license new file mode 100644 index 0000000..654d0bf --- /dev/null +++ b/license @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Sindre Sorhus (sindresorhus.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/package.json b/package.json new file mode 100644 index 0000000..722fd7d --- /dev/null +++ b/package.json @@ -0,0 +1,50 @@ +{ + "name": "create-dmg", + "version": "0.0.0", + "description": "Create a DMG from an app (macOS)", + "license": "MIT", + "repository": "sindresorhus/create-dmg", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "sindresorhus.com" + }, + "bin": { + "create-dmg": "cli.js" + }, + "engines": { + "node": ">=4" + }, + "scripts": { + "test": "xo && ava" + }, + "files": [ + "cli.js", + "assets" + ], + "keywords": [ + "cli-app", + "cli", + "create", + "dmg", + "disk", + "image", + "macos", + "mac", + "app", + "application", + "apple" + ], + "dependencies": { + "appdmg": "^0.4.5", + "execa": "^0.6.3", + "meow": "^3.4.2", + "ora": "^1.2.0", + "plist": "^2.0.1" + }, + "devDependencies": { + "ava": "*", + "tempfile": "^1.1.1", + "xo": "*" + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..8f5c343 --- /dev/null +++ b/readme.md @@ -0,0 +1,39 @@ +# create-dmg [![Build Status](https://travis-ci.org/sindresorhus/create-dmg.svg?branch=master)](https://travis-ci.org/sindresorhus/create-dmg) + +> Create a [DMG](https://en.m.wikipedia.org/wiki/Apple_Disk_Image) from an app *(macOS)* + + + +*This tool is intentionally opinionated and simple. I'm not interested in adding lots of options.* + + +## Install + +``` +$ npm install --global create-dmg +``` + + +## Usage + +``` +$ create-dmg --help + + Usage + $ create-dmg + + Example + $ create-dmg 'Lungo.app' +``` + + +## DMG + +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`. + + + + +## License + +MIT © [Sindre Sorhus](https://sindresorhus.com) diff --git a/screenshot-cli.gif b/screenshot-cli.gif new file mode 100644 index 0000000..41d2bca Binary files /dev/null and b/screenshot-cli.gif differ diff --git a/screenshot-dmg.png b/screenshot-dmg.png new file mode 100644 index 0000000..4084f78 Binary files /dev/null and b/screenshot-dmg.png differ diff --git a/stuff/dmg-background.sketch b/stuff/dmg-background.sketch new file mode 100644 index 0000000..4f7b32f Binary files /dev/null and b/stuff/dmg-background.sketch differ diff --git a/test.js b/test.js new file mode 100644 index 0000000..00d362a --- /dev/null +++ b/test.js @@ -0,0 +1,12 @@ +import path from 'path'; +import fs from 'fs'; +import test from 'ava'; +import execa from 'execa'; +import tempfile from 'tempfile'; + +test(async t => { + const cwd = tempfile(); + fs.mkdirSync(cwd); + await execa(path.join(__dirname, 'cli.js'), [path.join(__dirname, 'fixture.app')], {cwd}); + t.true(fs.existsSync(path.join(cwd, 'fixture 0.0.1.dmg'))); +});