Skip to content

Commit

Permalink
load platform builders independendly - fix #132
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanjudis committed Feb 9, 2016
1 parent 38aef30 commit 4abb95a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
11 changes: 4 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,11 @@ var Builder = {
// Make sure appPath is absolute
options.appPath = path.resolve( options.appPath );

// FAIL when set platform is not available
if ( !platforms[ options.platform ] ) {
return callback(
new Error( 'Building for ´' + options.platform + '´ is not supported' )
);
try {
platforms( options.platform ).init().build( options, callback );
} catch( error ) {
return callback( error );
}

platforms[ options.platform ].init().build( options, callback );
}
};

Expand Down
32 changes: 18 additions & 14 deletions index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ test( 'Builder.init().build - call the correct platform', function( t ) {
var Builder = proxyquireStrict(
'./index.js',
{
'./lib/platforms' : {
bar : {
init : function() {
return {
build : function( options, callback ) {
callback( null, 'foo' )
'./lib/platforms' : function( platform ) {
if ( platform === 'bar' ) {
return {
init : function() {
return {
build : function( options, callback ) {
callback( null, 'foo' )
}
}
}
}
};
}
}
}
Expand Down Expand Up @@ -70,15 +72,17 @@ test( 'Builder.init().build - create output directory if not present', function(
var Builder = proxyquireStrict(
'./index.js',
{
'./lib/platforms' : {
bar : {
init : function() {
return {
build : function( options, callback ) {
callback( null, 'foo' )
'./lib/platforms' : function( platform ) {
if ( platform === 'bar' ) {
return {
init : function() {
return {
build : function( options, callback ) {
callback( null, 'foo' )
}
}
}
}
};
}
}
}
Expand Down
20 changes: 15 additions & 5 deletions lib/platforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@
* Licensed under the MIT license.
*/

module.exports = {
osx : require( './osx' ),
win : require( './win' ),
win32 : require( './win' ),
linux : require( './linux' )
var mapping = {
osx : './osx',
win : './win',
win32 : './win',
linux : './linux'
};

module.exports = function( platform ) {
if ( ! mapping[ platform ] ) {
throw new Error(
'Building for ´' + platform + '´ is not supported'
);
}

return require( mapping[ platform ] );
};

0 comments on commit 4abb95a

Please sign in to comment.