Skip to content

Commit

Permalink
OSX release process ready
Browse files Browse the repository at this point in the history
  • Loading branch information
szwacz committed Apr 26, 2015
1 parent 5301ed1 commit 90a82b3
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "electron-boilerplate",
"productName": "Electron Boilerplate",
"identifier": "com.example.electron-boilerplate",
"description": "Starter for your Electron application. Out of the box ready for serious stuff.",
"version": "0.1.0",
"author": "Mr Gumby <[email protected]>",
Expand Down
1 change: 1 addition & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';

require('./tasks/build');
require('./tasks/release');
Binary file added resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions resources/osx/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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>CFBundleDisplayName</key>
<string>{{productName}}</string>
<key>CFBundleExecutable</key>
<string>Electron</string>
<key>CFBundleIconFile</key>
<string>icon.icns</string>
<key>CFBundleIdentifier</key>
<string>{{identifier}}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>{{productName}}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleVersion</key>
<string>{{version}}</string>
<key>LSMinimumSystemVersion</key>
<string>10.8.0</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>AtomApplication</string>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
</dict>
</plist>
10 changes: 10 additions & 0 deletions resources/osx/appdmg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"title": "{{productName}}",
"icon": "{{dmgIcon}}",
"background": "{{dmgBackground}}",
"icon-size": 128,
"contents": [
{ "x": 410, "y": 220, "type": "link", "path": "/Applications" },
{ "x": 130, "y": 220, "type": "file", "path": "{{appPath}}" }
]
}
Binary file added resources/osx/dmg-background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/osx/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/osx/dmg-icon.icns
Binary file not shown.
18 changes: 18 additions & 0 deletions resources/osx/helper_app/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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>CFBundleIdentifier</key>
<string>{{identifier}}.helper</string>
<key>CFBundleName</key>
<string>{{productName}} Helper</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>DTSDKName</key>
<string>macosx</string>
<key>LSUIElement</key>
<true/>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
</dict>
</plist>
Binary file added resources/osx/icon.icns
Binary file not shown.
14 changes: 14 additions & 0 deletions tasks/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

var gulp = require('gulp');
var utils = require('./utils');

var releaseForOs = {
osx: require('./release_osx'),
//linux: require('./release_linux'),
//windows: require('./release_windows'),
};

gulp.task('release', ['build'], function () {
return releaseForOs[utils.os()]();
});
105 changes: 105 additions & 0 deletions tasks/release_osx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
'use strict';

var Q = require('q');
var gulpUtil = require('gulp-util');
var childProcess = require('child_process');
var jetpack = require('fs-jetpack');
var utils = require('./utils');

var projectDir;
var releasesDir;
var tmpDir;
var finalAppDir;
var manifest;

var init = function () {
projectDir = jetpack;
tmpDir = projectDir.dir('./tmp', { empty: true });
releasesDir = projectDir.dir('./releases');
manifest = projectDir.read('app/package.json', 'json');
finalAppDir = tmpDir.cwd(manifest.productName + '.app');

return Q();
};

var copyRuntime = function () {
return projectDir.copyAsync('node_modules/electron-prebuilt/dist/Electron.app', finalAppDir.path());
};

var copyBuiltApp = function () {
return projectDir.copyAsync('build', finalAppDir.path('Contents/Resources/app'));
};

var finalize = function () {
// Prepare main Info.plist
var info = projectDir.read('resources/osx/Info.plist');
info = utils.replace(info, {
productName: manifest.productName,
identifier: manifest.identifier,
version: manifest.version
});
finalAppDir.write('Contents/Info.plist', info);

// Prepare Info.plist of Helper app
info = projectDir.read('resources/osx/helper_app/Info.plist');
info = utils.replace(info, {
productName: manifest.productName,
identifier: manifest.identifier
});
finalAppDir.write('Contents/Frameworks/Electron Helper.app/Contents/Info.plist', info);

// Copy icon
projectDir.copy('resources/osx/icon.icns', finalAppDir.path('Contents/Resources/icon.icns'));

return Q();
};

var packToDmgFile = function () {
var deferred = Q.defer();

var appdmg = require('appdmg');
var dmgName = manifest.name + '_' + manifest.version + '.dmg';

// Prepare appdmg config
var dmgManifest = projectDir.read('resources/osx/appdmg.json');
dmgManifest = utils.replace(dmgManifest, {
productName: manifest.productName,
appPath: finalAppDir.path(),
dmgIcon: projectDir.path("resources/osx/dmg-icon.icns"),
dmgBackground: projectDir.path("resources/osx/dmg-background.png")
});
tmpDir.write('appdmg.json', dmgManifest);

// Delete DMG file with this name if already exists
releasesDir.remove(dmgName);

gulpUtil.log('Packaging to DMG file...');

var readyDmgPath = releasesDir.path(dmgName);
appdmg({
source: tmpDir.path('appdmg.json'),
target: readyDmgPath
})
.on('error', function (err) {
console.error(err);
})
.on('finish', function () {
gulpUtil.log('DMG file ready!', readyDmgPath);
deferred.resolve();
});

return deferred.promise;
};

var cleanClutter = function () {
return tmpDir.removeAsync('.');
};

module.exports = function () {
return init()
.then(copyRuntime)
.then(copyBuiltApp)
.then(finalize)
.then(packToDmgFile)
.then(cleanClutter);
};

0 comments on commit 90a82b3

Please sign in to comment.