Last active
May 12, 2016 20:28
-
-
Save localnerve/6112944 to your computer and use it in GitHub Desktop.
Example of using TFS with Grunt (not that you would want to do this, but it can work). Employs the grunt-shell task so that TFS targets play well with other tasks that spawn (like grunt-contrib-compass).
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
// | |
// 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