Skip to content

Instantly share code, notes, and snippets.

@loktar00
Created October 17, 2014 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loktar00/345d071d5086fec957ab to your computer and use it in GitHub Desktop.
Save loktar00/345d071d5086fec957ab to your computer and use it in GitHub Desktop.
Checkout only changed files from TFS using gulp and gulp-changed.
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();
});
}
@vijender1256
Copy link

@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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment