diff --git a/README.md b/README.md index e07590b..ba68fa6 100644 --- a/README.md +++ b/README.md @@ -70,8 +70,7 @@ possible to write in your configuration file: }); -Note, however, that if you call 'rmcouchdb' without a sub-argument, in -keeping with grunt's standards, it will drop *all* of your databases! +Note that if you call `rmcouchdb` without a sub-argument, it will not delete any databases. ## Demo diff --git a/tasks/couchapp.js b/tasks/couchapp.js index 4c106bb..916265a 100755 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -67,21 +67,26 @@ module.exports = function(grunt) { db = genDB(this.data.db); try { nano = require('nano')(db.url); - nano.db.destroy(db.name, function(err) { - if (err) { - if (err.status_code && err.status_code === 404) { - if (_this.data.options && _this.data.options.okay_if_missing) { - grunt.log.writeln("Database " + dbname + " not present... skipping."); - return done(null, null) ; + if (db.name) { + nano.db.destroy(db.name, function(err) { + if (err) { + if (err.status_code && err.status_code === 404) { + if (_this.data.options && _this.data.options.okay_if_missing) { + grunt.log.writeln("Database " + db.name + " not present... skipping."); + return done(null, null) ; + } else { + grunt.warn("Database " + db.name + " does not exist."); + } } else { - grunt.warn("Database " + dbname + " does not exist."); + grunt.warn(err); } - } else { - grunt.warn(err); } - } - return done(err, null); - }); + return done(err, null); + }); + } else { + grunt.log.writeln("No database specified... skipping."); + return done(null, null); + } } catch (e) { grunt.warn(e); done(e, null); @@ -96,20 +101,26 @@ module.exports = function(grunt) { parts = urls.parse(this.data.db); db = genDB(this.data.db); try { - nano = require('nano')(db.url); - nano.db.create(db.name, function(err) { - if (_this.data.options && _this.data.options.okay_if_exists) { - if (err){ - grunt.log.writeln("Database " + dbname + " exists, skipping"); + if (db.name) { + nano = require('nano')(db.url); + nano.db.create(db.name, function(err) { + if (_this.data.options && _this.data.options.okay_if_exists) { + if (err){ + grunt.log.writeln("Database " + db.name + " exists, skipping"); + } + return done(null, null); + } else { + if (err){ + grunt.warn(err); + } + return done(err, null); } - return done(null, null); - } else { - if (err){ - grunt.warn(err); - } - return done(err, null); - } - }); + }); + } else { + var err_msg = "No database specified to create!"; + grunt.warn(err_msg); + return done(new Error(err_msg), null); + } } catch (e) { grunt.warn(e); done(e, null);