Created
October 17, 2014 16:23
-
-
Save loktar00/345d071d5086fec957ab to your computer and use it in GitHub Desktop.
Checkout only changed files from TFS using gulp and gulp-changed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
// ignore missing file error | |
function fsOperationFailed(stream, sourceFile, err) { | |
if (err) { | |
if (err.code !== 'ENOENT') { | |
stream.emit('error', new gutil.PluginError('gulp-changed', err, { | |
fileName: sourceFile.path | |
})); | |
} | |
stream.push(sourceFile); | |
} | |
return err; | |
} | |
// Checkout the changed file. | |
function checkoutFile(stream, sourceFile, targetPath, cb){ | |
var exec = require('child_process').exec; | |
exec('tf checkout ' + targetPath + ' /recursive /lock:none', function (error, stdout, stderr) { | |
console.log('Checking out ' + stdout); | |
stream.push(sourceFile); | |
cb(); | |
}); | |
} | |
exports.checkOutSingle = function(stream, cb, sourceFile, targetPath, targetFile){ | |
fs.stat(targetPath, function (err, targetStat) { | |
if (!fsOperationFailed(stream, sourceFile, err)) { | |
if (sourceFile.stat.mtime > targetStat.mtime) { | |
return checkoutFile(stream, sourceFile, targetFile, cb); | |
} | |
} | |
cb(); | |
}); | |
} | |
// only checkout changed files | |
exports.checkChanged = function(stream, cb, sourceFile, targetPath){ | |
fs.stat(targetPath, function (err, targetStat) { | |
if (!fsOperationFailed(stream, sourceFile, err)) { | |
if (sourceFile.stat.mtime > targetStat.mtime) { | |
return checkoutFile(stream, sourceFile, targetPath, cb); | |
} | |
} | |
cb(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@loktar00 How do i use above functions in my gulp task, and what is "exports" is it a keyword ? when i paste above code in gulp.js how do I call that fuctions to checkout files on TFS. Please provide more info of how to use it, can you provide example or something ?