Merge pull request #2 from drsm79/master

Add option to ignore errors from mkcouchdb if database exists
This commit is contained in:
Elf M. Sternberg 2012-12-07 09:13:24 -08:00
commit 0b295a3e15
1 changed files with 12 additions and 5 deletions

View File

@ -56,18 +56,25 @@ module.exports = function(grunt) {
});
grunt.registerMultiTask("mkcouchdb", "Delete a Couch Database", function() {
var done, parts, nano, dbname;
var done, parts, nano, dbname, _this;
_this = this;
done = this.async();
parts = urls.parse(this.data.db);
dbname = parts.pathname.replace(/^\//, '');
try {
nano = require('nano')(parts.protocol + '//' + parts.host);
nano.db.create(dbname, function(err) {
if (err) {
grunt.warn(err);
if (_this.data.options && _this.data.options.okay_if_exists) {
if (err){
grunt.log.writeln("Database " + dbname + " exists, skipping");
}
return done(null, null);
} else {
if (err){
grunt.warn(err);
}
return done(err, null);
}
return done(err, null);
});
} catch (e) {
grunt.warn(e);