Skip to content

Instantly share code, notes, and snippets.

@shama
Last active December 24, 2015 01:29
Show Gist options
  • Save shama/6723769 to your computer and use it in GitHub Desktop.
Save shama/6723769 to your computer and use it in GitHub Desktop.
Grunt example setting config from a db
grunt.initConfig({
db: {
// Books will be populated when setfromdb is ran
books: []
},
other: {
target: {
options: {
// Now when other:target is ran it will consume db.books
books: '<%= db.books %>'
}
}
}
});
grunt.registerTask('setfromdb', function() {
var done = this.async();
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/my_database');
var Book = mongoose.model('Book');
Book.find({}, function(err, books) {
grunt.config('db.books', books);
done();
});
});
grunt.registerTask('default', ['setfromdb', 'other', 'tasks']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment