Skip to content

Instantly share code, notes, and snippets.

@bomsy
Created December 7, 2012 15:34
Show Gist options
  • Save bomsy/4233999 to your computer and use it in GitHub Desktop.
Save bomsy/4233999 to your computer and use it in GitHub Desktop.
Sharing data between tasks
In the scenario below task2 depends on the result from task1 which is stored
in value property of the meta object(this is just an example) which does not initially exist but is created from within
task1. task2 can later have access to the value using <%= meta.value %> at a later time.
This way two tasks can share data..
There may be better ways of doing this, if you have come across please share
//sample of a task created
module.exports = function(grunt){
grunt.registerMultiTask('task1','', function(){
var data = this.data,
value = data.value;
//process value
grunt.config.set('meta.value', value); //sets a property called value on the grunt.config object
});
}
//In the main gruntfile (grunt.js)
grunt.initConfig({
pkg:'<json: package.json>',
meta: {
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' +
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */'
},
...
task1: {
bar:{
value: 'foo'
}
},
task2:{
barbar:{
value: '<%= meta.value %>' //contains value passed from task1
}
}
...
grunt.registerTask('default', 'task1:bar task2:barbar')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment