Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/linux dmg support #6

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 103 additions & 41 deletions lib/macos.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,99 @@ var path = require( 'path' );
var writeConfigFile = require( './helper/writeConfigFile' );
var assign = require( 'lodash.assign' );
var os = require( 'os' );
var childProcess = require( 'child_process' );

/**
* Build the installer for macos using appdmg, when on the darwin platform
*
* @param {Object} options options
* @param {Function} callback callback
*/
function buildDarwin( options, callback ) {

options.log( 'Writing temporary ´appdmg.json´' );

options.config.macos.background = path.join( options.basePath, options.config.macos.background );
options.config.macos.icon = path.join( options.basePath, options.config.macos.icon );
options.config.macos.contents[ 1 ].path = options.appPath;

var configFilePath = path.join( os.tmpDir(), 'appdmg.json' );

fs.writeFileSync(
configFilePath,
JSON.stringify( options.config.macos ),
{
encoding : 'utf8'
}
);

options.log( 'Wrote temporary ´appdmg.json´' );
options.log( 'Kicking off ´appdmg´' );

var appdmg = require( 'appdmg' );
var ee = appdmg( {
source : configFilePath,
target : path.join( options.out, options.config.macos.title + '.dmg' )
} );

ee.on( 'progress', function ( info ) {
if ( info.type === 'step-begin' ) {
options.log( 'appdmg: [' + info.current + '] ' + info.title );
}
} );

ee.on('finish', function () {
options.log( 'Finished ´appdmg´' );
callback();
} );

ee.on( 'error', function ( error ) {
callback( error );
} );

}

/**
* Build the installer for macos using genisoimage, when on the linux platform
*
* @param {Object} options options
* @param {Function} callback callback
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire red block was simply moved up above, verbatim, into the function buildDarwin.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jup. 👍

*/
function buildLinux( options, callback ) {

options.log( 'Kicking off ´genisoimage´' );

var title = options.config.macos.title
var genisoimage = childProcess.spawn(
'genisoimage',
[ '-V', title, '-D', '-R', '-apple', '-no-pad', '-o', path.join(options.out, title + '.dmg'), '-graft-points', title + '.app=' + options.appPath ],
{
env : process.env
}
);

genisoimage.stdout.on( 'data', function ( data ) {
options.log( 'genisoimage: ' + data );
});

genisoimage.on( 'error', function ( err ) {
return callback(err);
});

genisoimage.on( 'close', function ( code ) {
options.log( 'Finished genisoimage with code ' + code );

if ( code > 0 ) {
return callback( new Error( 'genisoimage failed' ) );
}

callback();
});

if ( genisoimage.error || genisoimage.status > 0 ) {
return callback( genisoimage.error || new Error( 'genisoimage failed' ) );
}
}

/**
* Prototype for the macos installer builder
Expand All @@ -24,49 +117,18 @@ var MacosBuilder = {
*/
build : function( options, callback ) {

if ( process.platform !== 'darwin' ) return callback( new Error( 'Invalid platform.' ) )

options.log( '- Starting build for ´' + options.platform + '´ - ' );

options.log( 'Writing temporary ´appdmg.json´' );

options.config.macos.background = path.join( options.basePath, options.config.macos.background );
options.config.macos.icon = path.join( options.basePath, options.config.macos.icon );
options.config.macos.contents[ 1 ].path = options.appPath;

var configFilePath = path.join( os.tmpDir(), 'appdmg.json' );

fs.writeFileSync(
configFilePath,
JSON.stringify( options.config.macos ),
{
encoding : 'utf8'
}
);

options.log( 'Wrote temporary ´appdmg.json´' );
options.log( 'Kicking off ´appdmg´' );

var appdmg = require( 'appdmg' );
var ee = appdmg( {
source : configFilePath,
target : path.join( options.out, options.config.macos.title + '.dmg' )
} );

ee.on( 'progress', function ( info ) {
if ( info.type === 'step-begin' ) {
options.log( 'appdmg: [' + info.current + '] ' + info.title );
}
} );

ee.on('finish', function () {
options.log( 'Finished ´appdmg´' );
callback();
} );

ee.on( 'error', function ( error ) {
callback( error );
} );
switch( process.platform ) {
case 'darwin':
buildDarwin(options, callback);
break;
case 'linux':
buildLinux(options, callback);
break;
default:
return callback( new Error( 'Invalid platform.' ) ); // win32 not currently supported.
}
}
};

Expand Down
1 change: 1 addition & 0 deletions lib/platforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

module.exports = {
macos : require( './macos' ),
darwin: require( './macos' ),
win : require( './win' ),
win32 : require( './win' )
};