Add in support for basic auth and add genDB helper
This commit is contained in:
parent
b514a1e27e
commit
d6d654d2c0
|
@ -11,6 +11,17 @@ path = require('path');
|
||||||
couchapp = require('couchapp');
|
couchapp = require('couchapp');
|
||||||
urls = require('url');
|
urls = require('url');
|
||||||
|
|
||||||
|
var genDB = function(db) {
|
||||||
|
var parts, dbname, auth;
|
||||||
|
parts = urls.parse(db);
|
||||||
|
dbname = parts.pathname.replace(/^\//, '');
|
||||||
|
auth = parts.auth ? (parts.auth + '@') : '';
|
||||||
|
return {
|
||||||
|
name: dbname,
|
||||||
|
url: parts.protocol + '//' + auth + parts.host
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = function(grunt) {
|
module.exports = function(grunt) {
|
||||||
|
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
@ -30,11 +41,10 @@ module.exports = function(grunt) {
|
||||||
var done, parts, nano, dbname, _this;
|
var done, parts, nano, dbname, _this;
|
||||||
_this = this;
|
_this = this;
|
||||||
done = this.async();
|
done = this.async();
|
||||||
parts = urls.parse(this.data.db);
|
db = genDB(this.data.db);
|
||||||
dbname = parts.pathname.replace(/^\//, '');
|
|
||||||
try {
|
try {
|
||||||
nano = require('nano')(parts.protocol + '//' + parts.host);
|
nano = require('nano')(db.url);
|
||||||
nano.db.destroy(dbname, 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) {
|
||||||
|
@ -56,14 +66,14 @@ module.exports = function(grunt) {
|
||||||
});
|
});
|
||||||
|
|
||||||
grunt.registerMultiTask("mkcouchdb", "Delete a Couch Database", function() {
|
grunt.registerMultiTask("mkcouchdb", "Delete a Couch Database", function() {
|
||||||
var done, parts, nano, dbname;
|
var done, parts, nano, dbname, auth;
|
||||||
|
|
||||||
done = this.async();
|
done = this.async();
|
||||||
parts = urls.parse(this.data.db);
|
parts = urls.parse(this.data.db);
|
||||||
dbname = parts.pathname.replace(/^\//, '');
|
db = genDB(this.data.db);
|
||||||
try {
|
try {
|
||||||
nano = require('nano')(parts.protocol + '//' + parts.host);
|
nano = require('nano')(db.url);
|
||||||
nano.db.create(dbname, function(err) {
|
nano.db.create(db.name, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
grunt.warn(err);
|
grunt.warn(err);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue