From 840b93e7d24bb5817ff3d9a372428f7183d61db8 Mon Sep 17 00:00:00 2001 From: Simon Metson Date: Tue, 30 Oct 2012 19:17:55 +0000 Subject: [PATCH] Add okay_if_exists option to mkcouchdb --- tasks/couchapp.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tasks/couchapp.js b/tasks/couchapp.js index e28a6bb..6b7811f 100644 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -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);