Skip to content

Instantly share code, notes, and snippets.

@mikepugh
Forked from localnerve/tfscheckout
Created April 29, 2014 14:19
Show Gist options
  • Save mikepugh/11401771 to your computer and use it in GitHub Desktop.
Save mikepugh/11401771 to your computer and use it in GitHub Desktop.
//
// Example showing how to use TFS with grunt.
// Plays well with grunt-contrib-compass and other tasks that spawn processes.
// This example only shows tf checkout, but you could reuse this pattern to add more tf commands.
//
// Gist by https://github.com/localnerve, http://www.localnerve.com
//
var path = require("path");
module.exports = function(grunt) {
// Load all grunt dev deps, including grunt-shell
require("matchdep").filterDev("grunt-*").forEach(grunt.loadNpmTasks);
// The project config
var projectConfig = {
// the style directory
styles: "styles",
// the scripts directory
scripts: "scripts",
// the markup directory
markup: "markup",
// the current working directory for TF.exe
// shown here is 32bit, vs2012. For 64bit, use program files (x86)
tfcwd: "c:/Program Files/Microsoft Visual Studio 11.0/Common7/IDE",
// the tf command for checkout
tfcheckout: "tf.exe checkout"
};
// Configure grunt tasks
grunt.initConfig({
project: projectConfig,
// grunt-shell used for TFS
// task provided by https://github.com/sindresorhus/grunt-shell
shell: {
// task options
options: {
stdout: true,
stderr: true,
failOnError: true,
execOptions: {
cwd: "<%= project.tfcwd %>"
}
},
// target to checkout all css
"checkout-css": {
command: grunt.util._.map([
path.resolve("<%= project.styles %>")+path.sep+"*.css"//,
// add other paths here
], function(p) {
// for each path, run the checkout command, could add /recursive flag too
return "<%= project.tfcheckout %> "+p;
}).join(" && ")
// && sequentially runs commands, if there is a failure, it stops
},
// target to checkout all js
"checkout-js": {
command: grunt.util._.map([
path.resolve("<%= project.scripts %>")+path.sep+"*.js"//,
// add other paths here
], function(p) {
// for each path, run the checkout command, could add /recursive flag too
return "<%= project.tfcheckout %> "+p;
}).join(" && ")
// && sequentially runs commands, if there is a failure, it stops
},
// target to checkout all markup
"checkout-markup": {
command: grunt.util._.map([
path.resolve("<%= project.markup %>")+path.sep+"*.aspx"//,
// add other paths here
], function(p) {
// for each path, run the checkout command, could add /recursive flag too
return "<%= project.tfcheckout %> "+p;
}).join(" && ")
// && sequentially runs commands, if there is a failure, it stops
}//,
// add other TFS targets/commands, etc
}//,
// add other task configs, etc
});
// checkout all
grunt.registerTask("default", ["shell"]);
// checkout css
grunt.registerTask("css", ["shell:checkout-css"]);
// checkout js
grunt.registerTask("js", ["shell:checkout-js"]);
// checkout markup
grunt.registerTask("markup", ["shell:checkout-markup"]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment