Skip to content

Commit

Permalink
Merge pull request #42 from loopline-systems/feature/22-create-output…
Browse files Browse the repository at this point in the history
…-directory-if-not-present

create output directory if not present - fix #22
  • Loading branch information
stefanjudis committed Oct 6, 2015
2 parents c3b4677 + 3e7b53a commit 6b1ed58
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 9 deletions.
15 changes: 13 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

var platforms = require( './lib/platforms' );
var path = require( 'path' );
var fs = require( 'fs' );

/**
* Prototype for electron-builder
Expand All @@ -26,12 +27,22 @@ var Builder = {
options.log = options.log || console.log;
options.out = options.out ? path.resolve( process.cwd(), options.out ) : process.cwd();

// make sure the output directory
// ends with a slash


// make sure the output
// directory ends with a slash
if ( options.out[ options.out.length - 1 ] !== path.sep ) {
options.out += path.sep;
}

// make sure the output
// directory exists
if ( !fs.existsSync( options.out ) ) {
options.log( '- Ouput directory ´' + options.out + '´ does not exist ' );
fs.mkdirSync( options.out );
options.log( '- Created ´' + options.out + '´ ' );
}

// FAIL when not all required options are set
if ( !options.appPath || !options.platform || !options.config ) {
return callback( new Error( 'Required option not set' ) );
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"proxyquire": "^1.5.0",
"tap-nyan": "0.0.2",
"tap-spec": "^3.0.0",
"tape": "^4.0.0"
"tape": "^4.0.0",
"tmp": "0.0.28"
}
}
59 changes: 53 additions & 6 deletions test/index_spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
'use strict';

/*
* electron-builder
* https://github.com/loopline-systems/electron-builder
*
* Licensed under the MIT license.
*/

var test = require( 'tape' );
var proxyquire = require( 'proxyquire' );
var proxyquireStrict = proxyquire.noCallThru();
var test = require( 'tape' );
var tmp = require( 'tmp' );
var fs = require( 'fs' );
var proxyquire = require( 'proxyquire' );
var proxyquireStrict = proxyquire.noCallThru();

test( 'Builder.init', function( t ) {
t.plan( 2 );
Expand All @@ -24,6 +28,8 @@ test( 'Builder.init', function( t ) {
} );

test( 'Builder.init().build - call the correct platform', function( t ) {
t.plan( 2 );

var Builder = proxyquireStrict(
'../',
{
Expand All @@ -32,7 +38,7 @@ test( 'Builder.init().build - call the correct platform', function( t ) {
init : function() {
return {
build : function( options, callback ) {
t.end();
callback( null, 'foo' )
}
}
}
Expand All @@ -47,7 +53,49 @@ test( 'Builder.init().build - call the correct platform', function( t ) {
platform : 'bar',
config : {}
},
function() {}
function( error, result ) {
t.equal( error, null );
t.equal( result, 'foo' );
t.end();
}
);
} );

test( 'Builder.init().build - create output directory if not present', function( t ) {
t.plan( 1 );

var tmpDir = tmp.dirSync( { unsafeCleanup : true } );
var Builder = proxyquireStrict(
'../',
{
'./lib/platforms' : {
bar : {
init : function() {
return {
build : function( options, callback ) {
callback( null, 'foo' )
}
}
}
}
}
}
);

Builder.init().build(
{
appPath : 'foo',
platform : 'bar',
config : {},
out : tmpDir.name + '/foo'
},
function( error, result ) {
t.equal( fs.existsSync( tmpDir.name + '/foo' ), true );

tmpDir.removeCallback();

t.end();
}
);
} );

Expand Down Expand Up @@ -136,4 +184,3 @@ test( 'Builder.init().build - check for required options', function( t ) {
}
);
} );

0 comments on commit 6b1ed58

Please sign in to comment.