Last active
December 24, 2015 01:29
-
-
Save shama/6723769 to your computer and use it in GitHub Desktop.
Grunt example setting config from a db
This file contains hidden or 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
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