Skip to content

Commit

Permalink
Checkout if workspace exists but is empty (removes one manual setup s…
Browse files Browse the repository at this point in the history
…tep)
  • Loading branch information
Ghislain Seguin committed Sep 6, 2012
1 parent cb7fa62 commit d66321f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
49 changes: 44 additions & 5 deletions lib/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ function cleanup( project, callback ) {
], callback );
}

function _checkout( project, callback ) {
// Workspace
var workDir = getWorkspaceDirSync( project );

return async.waterfall([
function( next ) {
project.getRepoDir( next );
},
function( dir, next ) {
Git( dir, workDir );
Git.exec( [ "checkout", "-f", project.getRef() ], next );
}
], callback );
}

function checkout( project, force, callback ){
if ( typeof force === "function" ) {
callback = force;
Expand All @@ -63,11 +78,7 @@ function checkout( project, force, callback ){
});
},
function( next ) {
project.getRepoDir( next );
},
function( dir, next ) {
Git( dir, workDir );
Git.exec( [ "checkout", "-f", project.getRef() ], next );
_checkout( project, next );
}
], callback );
} else {
Expand All @@ -76,6 +87,30 @@ function checkout( project, force, callback ){
});
}

function checkoutIfEmpty( project, callback ){
// Workspace
var workDir = getWorkspaceDirSync( project );

fs.exists( workDir, function( exists ) {
if ( exists ) {
async.waterfall([
function( next ) {
fs.readdir( workDir, next );
},
function( files, next ) {
if ( files.length == 0 ) {
_checkout( project, function() { next(); } );
} else {
next();
}
}
], callback );
} else {
callback( "Workspace for " + project.getRepo() + "/" + project.getRef() + " has not been created" );
}
});
}

function getFirstExistingDir( candidates, callback ) {
var dir = candidates.shift();
fs.exists( dir , function( exists ) {
Expand Down Expand Up @@ -148,6 +183,10 @@ Project.prototype.checkout = function( force, callback ) {
return checkout( this, force, callback );
}

Project.prototype.checkoutIfEmpty = function( callback ) {
return checkoutIfEmpty( this, callback );
}

Project.prototype.cleanup = function( callback ) {
return cleanup( this, callback );
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name":"amd-builder",
"description":"A service that builds bundles from AMD projects resources",
"version":"0.3.2",
"version":"0.3.3",
"keywords":[
"jquery mobile",
"amd",
Expand Down
3 changes: 3 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ function buildDependencyMap( project, baseUrl, include ) {
};

async.waterfall([
function( next ) {
project.checkoutIfEmpty( next );
},
function( next ) {
// logger.log( "buildDependencyMap["+id+"](): step 1" );
// If no name is provided, scan the baseUrl for js files and return the dep map for all JS objects in baseUrl
Expand Down

0 comments on commit d66321f

Please sign in to comment.