Permalink
Browse files

Added dmg creation to packager. #188

  • Loading branch information...
1 parent e86c031 commit e43e878d2020aead89db917925f000ac0476a080 @Thomas101 committed Aug 16, 2016
Showing with 88 additions and 4 deletions.
  1. +1 −0 .gitignore
  2. +1 −0 package.json
  3. +79 −0 packager/Distribution.js
  4. +1 −0 packager/ElectronBuilder.js
  5. BIN packager/dmg/background.png
  6. +6 −4 packager/index.js
View
@@ -1,6 +1,7 @@
credentials.js
node_modules
bin
+dist
WMail-darwin-x64
WMail-linux-ia32/
WMail-linux-x64/
View
@@ -21,6 +21,7 @@
"repository": "https://github.com/Thomas101/wmail",
"main": "bin/app/index.js",
"dependencies": {
+ "appdmg": "^0.4.5",
"babel": "6.5.2",
"babel-core": "6.13.2",
"babel-loader": "6.2.4",
View
@@ -0,0 +1,79 @@
+const appdmg = require('appdmg')
+const path = require('path')
+const { ROOT_PATH } = require('./constants')
+const fs = require('fs-extra')
+const TaskLogger = require('./TaskLogger')
+
+class Distribution {
+
+ /**
+ * Distributes the darin version of the app
+ * @param pkg: the package info
+ * @return promise
+ */
+ static distributeDarwin (pkg) {
+ if (process.platform !== 'darwin') {
+ return Promise.reject(new Error('Darwin distribution only supported from darwin'))
+ }
+
+ return new Promise((resolve, reject) => {
+ const task = TaskLogger.start('OSX DMG')
+ const filename = `WMail_${pkg.version.replace(/\./g, '_')}${pkg.prerelease ? '_prerelease' : ''}.dmg`
+ const distPath = path.join(ROOT_PATH, 'dist')
+ const targetPath = path.join(distPath, filename)
+ fs.mkdirsSync(distPath)
+ try {
+ fs.unlinkSync(targetPath)
+ } catch (ex) { /* no-op */ }
+
+ const dmgCreate = appdmg({
+ target: targetPath,
+ basepath: ROOT_PATH,
+ specification: {
+ title: `WMail ${pkg.version} ${pkg.prerelease ? 'Prerelease' : ''}`,
+ format: 'UDBZ',
+ icon: 'assets/icons/app.ico',
+ 'background-color': '#CCCCCC',
+ background: path.join(__dirname, 'dmg/background.png'),
+ 'icon-size': 100,
+ window: {
+ size: { width: 600, height: 500 }
+ },
+ contents: [
+ { x: 150, y: 100, type: 'file', path: 'WMail-darwin-x64/WMail.app' },
+ { x: 450, y: 100, type: 'link', path: '/Applications' },
+ { x: 150, y: 400, type: 'file', path: 'WMail-darwin-x64/Installing on OSX.html' },
+ { x: 300, y: 400, type: 'file', path: 'WMail-darwin-x64/LICENSE' },
+ { x: 450, y: 400, type: 'file', path: 'WMail-darwin-x64/vendor-licenses' }
+ ]
+ }
+ })
+ dmgCreate.on('finish', () => {
+ task.finish()
+ resolve()
+ })
+ dmgCreate.on('error', (err) => {
+ task.fail()
+ reject(err)
+ })
+ })
+ }
+
+ /**
+ * Distributes the app for the given platforms
+ * @param platforms: the platforms to distribute for
+ * @param pkg: the package info
+ * @return promise
+ */
+ static distribute (platforms, pkg) {
+ return Promise.all(platforms.map((platform) => {
+ if (platform === 'darwin') {
+ return Distribution.distributeDarwin(pkg)
+ } else {
+ return Promise.resolve()
+ }
+ }))
+ }
+}
+
+module.exports = Distribution
@@ -17,6 +17,7 @@ class ElectronBuilder {
'/release',
'/src',
'/packager',
+ '/dist',
// Files
'/.editorconfig',
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -3,19 +3,21 @@ const Licenses = require('./Licenses')
const JSBuilder = require('./JSBuilder')
const ElectronBuilder = require('./ElectronBuilder')
const ReleaseAssets = require('./ReleaseAssets')
+const Distribution = require('./Distribution')
const argv = require('yargs').argv
const argvPlatform = (Array.isArray(argv.platform) ? new Set(argv.platform) : new Set([argv.platform || 'all']))
const platforms = argvPlatform.has('all') ? ['darwin', 'linux', 'win32'] : Array.from(argvPlatform)
-const distribution = argv.distribution
+const dist = argv.distribution
Promise.resolve()
- .then(() => distribution ? JSBuilder.pruneNPM() : Promise.resolve())
+ .then(() => dist ? JSBuilder.pruneNPM() : Promise.resolve())
.then(JSBuilder.runWebpack)
.then(() => ElectronBuilder.packageApp(platforms, pkg))
- .then(() => distribution ? Licenses.buildLicensesIntoReleases(platforms) : Promise.resolve())
- .then(() => distribution ? ReleaseAssets.copyAssetsIntoReleases(platforms) : Promise.resolve())
+ .then(() => dist ? Licenses.buildLicensesIntoReleases(platforms) : Promise.resolve())
+ .then(() => dist ? ReleaseAssets.copyAssetsIntoReleases(platforms) : Promise.resolve())
+ .then(() => dist ? Distribution.distribute(platforms, pkg) : Promise.resolve())
.then(
() => { },
(err) => {

0 comments on commit e43e878

Please sign in to comment.