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(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
@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 ?