merged rmcouchdb

This commit is contained in:
Max Thayer 2013-09-08 22:11:23 -04:00
commit 36abc1ad4e
2 changed files with 37 additions and 27 deletions

View File

@ -70,8 +70,7 @@ possible to write in your configuration file:
}); });
Note, however, that if you call 'rmcouchdb' without a sub-argument, in Note that if you call `rmcouchdb` without a sub-argument, it will not delete any databases.
keeping with grunt's standards, it will drop *all* of your databases!
## Demo ## Demo

View File

@ -67,14 +67,15 @@ module.exports = function(grunt) {
db = genDB(this.data.db); db = genDB(this.data.db);
try { try {
nano = require('nano')(db.url); nano = require('nano')(db.url);
if (db.name) {
nano.db.destroy(db.name, function(err) { nano.db.destroy(db.name, function(err) {
if (err) { if (err) {
if (err.status_code && err.status_code === 404) { if (err.status_code && err.status_code === 404) {
if (_this.data.options && _this.data.options.okay_if_missing) { if (_this.data.options && _this.data.options.okay_if_missing) {
grunt.log.writeln("Database " + dbname + " not present... skipping."); grunt.log.writeln("Database " + db.name + " not present... skipping.");
return done(null, null) ; return done(null, null) ;
} else { } else {
grunt.warn("Database " + dbname + " does not exist."); grunt.warn("Database " + db.name + " does not exist.");
} }
} else { } else {
grunt.warn(err); grunt.warn(err);
@ -82,6 +83,10 @@ module.exports = function(grunt) {
} }
return done(err, null); return done(err, null);
}); });
} else {
grunt.log.writeln("No database specified... skipping.");
return done(null, null);
}
} catch (e) { } catch (e) {
grunt.warn(e); grunt.warn(e);
done(e, null); done(e, null);
@ -96,11 +101,12 @@ module.exports = function(grunt) {
parts = urls.parse(this.data.db); parts = urls.parse(this.data.db);
db = genDB(this.data.db); db = genDB(this.data.db);
try { try {
if (db.name) {
nano = require('nano')(db.url); nano = require('nano')(db.url);
nano.db.create(db.name, function(err) { nano.db.create(db.name, function(err) {
if (_this.data.options && _this.data.options.okay_if_exists) { if (_this.data.options && _this.data.options.okay_if_exists) {
if (err){ if (err){
grunt.log.writeln("Database " + dbname + " exists, skipping"); grunt.log.writeln("Database " + db.name + " exists, skipping");
} }
return done(null, null); return done(null, null);
} else { } else {
@ -110,6 +116,11 @@ module.exports = function(grunt) {
return done(err, null); 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) { } catch (e) {
grunt.warn(e); grunt.warn(e);
done(e, null); done(e, null);