From 81f490a1f5bc0cf01ac0ecda4cf9e27e38165323 Mon Sep 17 00:00:00 2001 From: skiqh Date: Wed, 3 Jul 2013 18:44:49 +0200 Subject: [PATCH 01/34] use grunt's dynamic filenames. --- tasks/couchapp.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) mode change 100644 => 100755 tasks/couchapp.js diff --git a/tasks/couchapp.js b/tasks/couchapp.js old mode 100644 new mode 100755 index 6b7811f..c613704 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -10,6 +10,8 @@ var path, couchapp, nanolib, urls; path = require('path'); couchapp = require('couchapp'); urls = require('url'); +console.log(__dirname) +var async = require('async') module.exports = function(grunt) { @@ -18,12 +20,17 @@ module.exports = function(grunt) { // ========================================================================== grunt.registerMultiTask("couchapp", "Install Couchapp", function() { - var appobj, done; - done = this.async(); - appobj = require(path.join(process.cwd(), path.normalize(this.data.app))); - return couchapp.createApp(appobj, this.data.db, function(app) { - return app.push(done); - }); + + var task = this + var done = this.async() + + async.each(this.files, function(file, cb) { + var pth = path.join(process.cwd(), path.normalize(file.src[0])) + var appobj = require(pth) + couchapp.createApp(appobj, task.data.db, function(app) { + app.push( cb ) + }); + }, done) }); grunt.registerMultiTask("rmcouchdb", "Delete a Couch Database", function() { From af73a33070e19dc55287f6bb7f394ba329a096b9 Mon Sep 17 00:00:00 2001 From: skiqh Date: Wed, 3 Jul 2013 19:27:18 +0200 Subject: [PATCH 02/34] cleanup and error catching --- tasks/couchapp.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/tasks/couchapp.js b/tasks/couchapp.js index c613704..1382875 100755 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -5,13 +5,12 @@ * Licensed under the MIT license. */ -var path, couchapp, nanolib, urls; +var path, couchapp, nanolib, urls, async; path = require('path'); couchapp = require('couchapp'); urls = require('url'); -console.log(__dirname) -var async = require('async') +async = require('async'); module.exports = function(grunt) { @@ -20,17 +19,23 @@ module.exports = function(grunt) { // ========================================================================== grunt.registerMultiTask("couchapp", "Install Couchapp", function() { - - var task = this - var done = this.async() + var task = this; + var done = this.async(); async.each(this.files, function(file, cb) { - var pth = path.join(process.cwd(), path.normalize(file.src[0])) - var appobj = require(pth) - couchapp.createApp(appobj, task.data.db, function(app) { - app.push( cb ) - }); - }, done) + var appobj, apppath + apppath = path.join(process.cwd(), path.normalize(file.src[0])) + try { + appobj = require(apppath) + couchapp.createApp(appobj, task.data.db, function(app) { + app.push(cb); + }); + } catch(ex) { + grunt.log.error(ex); + grunt.log.warn('Could not load couchapp from ' + apppath + '.'); + cb(); + } + }, done); }); grunt.registerMultiTask("rmcouchdb", "Delete a Couch Database", function() { From 5365bbd9a4b5f45dfc76fcf60f172c28645f7011 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 16 Aug 2013 13:50:29 -0400 Subject: [PATCH 03/34] Update couchapp version Improves debugging. --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8fb8f01..ff57124 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "test": "grunt test" }, "dependencies": { - "couchapp": "0.9.1", + "couchapp": "0.10.1", "grunt": "~0.3.12", "nano": "3.3.0" }, @@ -40,4 +40,4 @@ "keywords": [ "gruntplugin" ] -} \ No newline at end of file +} From 3e68f281922397a31f4a461367eae5b77a56e603 Mon Sep 17 00:00:00 2001 From: Russell Branca Date: Fri, 16 Nov 2012 16:50:59 -0800 Subject: [PATCH 04/34] Add in support for basic auth and add genDB helper --- tasks/couchapp.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tasks/couchapp.js b/tasks/couchapp.js index 6b7811f..93a36d2 100644 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -11,6 +11,17 @@ path = require('path'); couchapp = require('couchapp'); 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) { // ========================================================================== @@ -30,11 +41,10 @@ module.exports = function(grunt) { var done, parts, nano, dbname, _this; _this = this; done = this.async(); - parts = urls.parse(this.data.db); - dbname = parts.pathname.replace(/^\//, ''); + db = genDB(this.data.db); try { - nano = require('nano')(parts.protocol + '//' + parts.host); - nano.db.destroy(dbname, function(err) { + 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) { @@ -56,13 +66,14 @@ module.exports = function(grunt) { }); grunt.registerMultiTask("mkcouchdb", "Delete a Couch Database", function() { - var done, parts, nano, dbname, _this; + var done, parts, nano, dbname, auth, _this; _this = this; + done = this.async(); parts = urls.parse(this.data.db); - dbname = parts.pathname.replace(/^\//, ''); + db = genDB(this.data.db); try { - nano = require('nano')(parts.protocol + '//' + parts.host); + nano = require('nano')(db.url); nano.db.create(dbname, function(err) { if (_this.data.options && _this.data.options.okay_if_exists) { if (err){ From 4189d8e88810b98d8f06cdfc94eaa9338842e5e6 Mon Sep 17 00:00:00 2001 From: Max Thayer Date: Fri, 12 Jul 2013 16:15:58 -0400 Subject: [PATCH 05/34] typo --- tasks/couchapp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/couchapp.js b/tasks/couchapp.js index 93a36d2..c3c3415 100644 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -74,7 +74,7 @@ module.exports = function(grunt) { db = genDB(this.data.db); try { nano = require('nano')(db.url); - nano.db.create(dbname, function(err) { + 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"); From d4025db1e0f5e483a0d7406df52e7e9a4660c412 Mon Sep 17 00:00:00 2001 From: Max Thayer Date: Wed, 21 Aug 2013 23:49:53 -0400 Subject: [PATCH 06/34] fixed typo --- tasks/couchapp.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tasks/couchapp.js b/tasks/couchapp.js index c3c3415..acbaa5b 100644 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -5,11 +5,12 @@ * Licensed under the MIT license. */ -var path, couchapp, nanolib, urls; +var path, couchapp, nanolib, urls, auth; path = require('path'); couchapp = require('couchapp'); urls = require('url'); +auth = require('../lib/auth'); var genDB = function(db) { var parts, dbname, auth; @@ -65,8 +66,13 @@ module.exports = function(grunt) { } }); +<<<<<<< HEAD grunt.registerMultiTask("mkcouchdb", "Delete a Couch Database", function() { var done, parts, nano, dbname, auth, _this; +======= + grunt.registerMultiTask("mkcouchdb", "Make a Couch Database", function() { + var done, parts, nano, dbname, _this; +>>>>>>> fixed typo _this = this; done = this.async(); From ba25597292a581b77fdec5c9e176b48ce75f76ea Mon Sep 17 00:00:00 2001 From: Max Thayer Date: Wed, 21 Aug 2013 23:54:28 -0400 Subject: [PATCH 07/34] added auth lib --- lib/auth.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 lib/auth.js diff --git a/lib/auth.js b/lib/auth.js new file mode 100644 index 0000000..16fe02d --- /dev/null +++ b/lib/auth.js @@ -0,0 +1,12 @@ +exports.getCookie = function(opts, cb){ + var db = nano(opts.db.url); + nano.auth(opts.username, opts.password, function(err, body, headers){ + if(err){ + cb(err); + }else{ + if(headers && headers['set-cookie']){ + cb(null, headers['set-cookie']); + } + } + }); +} \ No newline at end of file From afffe75a73c9fa58db450575eefc9619b70370ca Mon Sep 17 00:00:00 2001 From: Max Thayer Date: Wed, 21 Aug 2013 23:54:41 -0400 Subject: [PATCH 08/34] well, i clearly did something --- tasks/couchapp.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tasks/couchapp.js b/tasks/couchapp.js index acbaa5b..1d94ce7 100644 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -66,13 +66,8 @@ module.exports = function(grunt) { } }); -<<<<<<< HEAD - grunt.registerMultiTask("mkcouchdb", "Delete a Couch Database", function() { - var done, parts, nano, dbname, auth, _this; -======= grunt.registerMultiTask("mkcouchdb", "Make a Couch Database", function() { var done, parts, nano, dbname, _this; ->>>>>>> fixed typo _this = this; done = this.async(); From 5bda4b82c75ed60e6171455082dbb03cc36ef479 Mon Sep 17 00:00:00 2001 From: Max Thayer Date: Wed, 21 Aug 2013 23:58:19 -0400 Subject: [PATCH 09/34] removed auth lib --- lib/auth.js | 12 ------------ tasks/couchapp.js | 1 - 2 files changed, 13 deletions(-) delete mode 100644 lib/auth.js diff --git a/lib/auth.js b/lib/auth.js deleted file mode 100644 index 16fe02d..0000000 --- a/lib/auth.js +++ /dev/null @@ -1,12 +0,0 @@ -exports.getCookie = function(opts, cb){ - var db = nano(opts.db.url); - nano.auth(opts.username, opts.password, function(err, body, headers){ - if(err){ - cb(err); - }else{ - if(headers && headers['set-cookie']){ - cb(null, headers['set-cookie']); - } - } - }); -} \ No newline at end of file diff --git a/tasks/couchapp.js b/tasks/couchapp.js index 1d94ce7..55c07dc 100644 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -10,7 +10,6 @@ var path, couchapp, nanolib, urls, auth; path = require('path'); couchapp = require('couchapp'); urls = require('url'); -auth = require('../lib/auth'); var genDB = function(db) { var parts, dbname, auth; From e80eb462c9dff8ca44bb34a57faf39001b292991 Mon Sep 17 00:00:00 2001 From: Max Thayer Date: Fri, 6 Sep 2013 08:07:49 -0400 Subject: [PATCH 10/34] update couchapp version number so it can install --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ff57124..0355b45 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "test": "grunt test" }, "dependencies": { - "couchapp": "0.10.1", + "couchapp": "0.10.*", "grunt": "~0.3.12", "nano": "3.3.0" }, From 617fbaeddac0547d5c410158eaa31fbfbd1b734c Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 6 Sep 2013 09:38:51 -0400 Subject: [PATCH 11/34] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ff57124..189f77d 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "test": "grunt test" }, "dependencies": { - "couchapp": "0.10.1", + "couchapp": "0.10.0", "grunt": "~0.3.12", "nano": "3.3.0" }, From 9513ba168e8657373759699baa1c83a2c2a6857b Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 16 Aug 2013 13:50:29 -0400 Subject: [PATCH 12/34] Update couchapp version Improves debugging. --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8fb8f01..ff57124 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "test": "grunt test" }, "dependencies": { - "couchapp": "0.9.1", + "couchapp": "0.10.1", "grunt": "~0.3.12", "nano": "3.3.0" }, @@ -40,4 +40,4 @@ "keywords": [ "gruntplugin" ] -} \ No newline at end of file +} From 4fe15a7769acd9437a49e18556d056591703784a Mon Sep 17 00:00:00 2001 From: Russell Branca Date: Fri, 16 Nov 2012 16:50:59 -0800 Subject: [PATCH 13/34] Add in support for basic auth and add genDB helper --- tasks/couchapp.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tasks/couchapp.js b/tasks/couchapp.js index 6b7811f..93a36d2 100644 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -11,6 +11,17 @@ path = require('path'); couchapp = require('couchapp'); 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) { // ========================================================================== @@ -30,11 +41,10 @@ module.exports = function(grunt) { var done, parts, nano, dbname, _this; _this = this; done = this.async(); - parts = urls.parse(this.data.db); - dbname = parts.pathname.replace(/^\//, ''); + db = genDB(this.data.db); try { - nano = require('nano')(parts.protocol + '//' + parts.host); - nano.db.destroy(dbname, function(err) { + 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) { @@ -56,13 +66,14 @@ module.exports = function(grunt) { }); grunt.registerMultiTask("mkcouchdb", "Delete a Couch Database", function() { - var done, parts, nano, dbname, _this; + var done, parts, nano, dbname, auth, _this; _this = this; + done = this.async(); parts = urls.parse(this.data.db); - dbname = parts.pathname.replace(/^\//, ''); + db = genDB(this.data.db); try { - nano = require('nano')(parts.protocol + '//' + parts.host); + nano = require('nano')(db.url); nano.db.create(dbname, function(err) { if (_this.data.options && _this.data.options.okay_if_exists) { if (err){ From 14fca52c6445c9db92b4d0e8bfa4b9a128e84bb3 Mon Sep 17 00:00:00 2001 From: Max Thayer Date: Fri, 12 Jul 2013 16:15:58 -0400 Subject: [PATCH 14/34] typo --- tasks/couchapp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/couchapp.js b/tasks/couchapp.js index 93a36d2..c3c3415 100644 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -74,7 +74,7 @@ module.exports = function(grunt) { db = genDB(this.data.db); try { nano = require('nano')(db.url); - nano.db.create(dbname, function(err) { + 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"); From 8bd3f97cc0d7fac3f21aa69100953a06a127ac5a Mon Sep 17 00:00:00 2001 From: Max Thayer Date: Wed, 21 Aug 2013 23:49:53 -0400 Subject: [PATCH 15/34] fixed typo --- tasks/couchapp.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tasks/couchapp.js b/tasks/couchapp.js index c3c3415..acbaa5b 100644 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -5,11 +5,12 @@ * Licensed under the MIT license. */ -var path, couchapp, nanolib, urls; +var path, couchapp, nanolib, urls, auth; path = require('path'); couchapp = require('couchapp'); urls = require('url'); +auth = require('../lib/auth'); var genDB = function(db) { var parts, dbname, auth; @@ -65,8 +66,13 @@ module.exports = function(grunt) { } }); +<<<<<<< HEAD grunt.registerMultiTask("mkcouchdb", "Delete a Couch Database", function() { var done, parts, nano, dbname, auth, _this; +======= + grunt.registerMultiTask("mkcouchdb", "Make a Couch Database", function() { + var done, parts, nano, dbname, _this; +>>>>>>> fixed typo _this = this; done = this.async(); From 7a9d8f85cabc3b3c748eed57170b727a843a3d8a Mon Sep 17 00:00:00 2001 From: Max Thayer Date: Wed, 21 Aug 2013 23:54:28 -0400 Subject: [PATCH 16/34] added auth lib --- lib/auth.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 lib/auth.js diff --git a/lib/auth.js b/lib/auth.js new file mode 100644 index 0000000..16fe02d --- /dev/null +++ b/lib/auth.js @@ -0,0 +1,12 @@ +exports.getCookie = function(opts, cb){ + var db = nano(opts.db.url); + nano.auth(opts.username, opts.password, function(err, body, headers){ + if(err){ + cb(err); + }else{ + if(headers && headers['set-cookie']){ + cb(null, headers['set-cookie']); + } + } + }); +} \ No newline at end of file From 535902a71a4141feaa1fafa8d28051b6d4e8c11a Mon Sep 17 00:00:00 2001 From: Max Thayer Date: Wed, 21 Aug 2013 23:54:41 -0400 Subject: [PATCH 17/34] well, i clearly did something --- tasks/couchapp.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tasks/couchapp.js b/tasks/couchapp.js index acbaa5b..1d94ce7 100644 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -66,13 +66,8 @@ module.exports = function(grunt) { } }); -<<<<<<< HEAD - grunt.registerMultiTask("mkcouchdb", "Delete a Couch Database", function() { - var done, parts, nano, dbname, auth, _this; -======= grunt.registerMultiTask("mkcouchdb", "Make a Couch Database", function() { var done, parts, nano, dbname, _this; ->>>>>>> fixed typo _this = this; done = this.async(); From 820eb50878c4d123db405f15b894934a82c2ad34 Mon Sep 17 00:00:00 2001 From: Max Thayer Date: Wed, 21 Aug 2013 23:58:19 -0400 Subject: [PATCH 18/34] removed auth lib --- lib/auth.js | 12 ------------ tasks/couchapp.js | 1 - 2 files changed, 13 deletions(-) delete mode 100644 lib/auth.js diff --git a/lib/auth.js b/lib/auth.js deleted file mode 100644 index 16fe02d..0000000 --- a/lib/auth.js +++ /dev/null @@ -1,12 +0,0 @@ -exports.getCookie = function(opts, cb){ - var db = nano(opts.db.url); - nano.auth(opts.username, opts.password, function(err, body, headers){ - if(err){ - cb(err); - }else{ - if(headers && headers['set-cookie']){ - cb(null, headers['set-cookie']); - } - } - }); -} \ No newline at end of file diff --git a/tasks/couchapp.js b/tasks/couchapp.js index 1d94ce7..55c07dc 100644 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -10,7 +10,6 @@ var path, couchapp, nanolib, urls, auth; path = require('path'); couchapp = require('couchapp'); urls = require('url'); -auth = require('../lib/auth'); var genDB = function(db) { var parts, dbname, auth; From 6d078f72de05c2a3422655f482b46b948212d3bf Mon Sep 17 00:00:00 2001 From: Max Thayer Date: Fri, 6 Sep 2013 09:49:38 -0400 Subject: [PATCH 19/34] updated readme --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f043944..e07590b 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,7 @@ grunt-couchapp` Then add this line to your project's `grunt.js` gruntfile: -```javascript -grunt.loadNpmTasks('grunt-couchapp'); -``` + grunt.loadNpmTasks('grunt-couchapp'); [grunt]: https://github.com/cowboy/grunt [getting_started]: https://github.com/cowboy/grunt/blob/master/docs/getting_started.md @@ -26,7 +24,10 @@ which installs a specified couchapp into the database. mkcouchdb: { demo: { - db: 'http://localhost:5984/grunt-couchapp-demo' + db: 'http://localhost:5984/grunt-couchapp-demo', + options: { + okay_if_exists: true + } } }, @@ -54,7 +55,8 @@ possible to write in your configuration file: db: 'http://localhost:5984/grunt-couchapp-demo', app: './demo/app.js', options: { - okay_if_missing: true + okay_if_missing: true, + okay_if_exists: true } } } From a41ae8efac9403a428672e8638be0b9d2ac687aa Mon Sep 17 00:00:00 2001 From: Max Thayer Date: Fri, 6 Sep 2013 10:02:16 -0400 Subject: [PATCH 20/34] rmcouchdb doesn't drop everything if dbname is absent; mkcouchdb reports helpful error message if dbname is absent --- README.md | 3 +-- tasks/couchapp.js | 61 ++++++++++++++++++++++++++++------------------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index f043944..30c09d1 100644 --- a/README.md +++ b/README.md @@ -68,8 +68,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 1382875..464b63f 100755 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -46,21 +46,26 @@ module.exports = function(grunt) { dbname = parts.pathname.replace(/^\//, ''); try { nano = require('nano')(parts.protocol + '//' + parts.host); - nano.db.destroy(dbname, 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 (dbname) { + nano.db.destroy(dbname, 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) ; + } else { + grunt.warn("Database " + dbname + " 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); @@ -74,20 +79,26 @@ module.exports = function(grunt) { 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 (_this.data.options && _this.data.options.okay_if_exists) { - if (err){ - grunt.log.writeln("Database " + dbname + " exists, skipping"); + if (dbname) { + nano = require('nano')(parts.protocol + '//' + parts.host); + nano.db.create(dbname, function(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(null, null); - } else { - if (err){ - grunt.warn(err); - } - return done(err, null); - } - }); + }); + } else { + var err_msg = "No database specified... skipping."; + grunt.warn(err_msg); + return done(new Error(err_msg), null); + } } catch (e) { grunt.warn(e); done(e, null); From b957e5a1c1823e714364ef88f934b39808c0f4e4 Mon Sep 17 00:00:00 2001 From: Max Thayer Date: Fri, 6 Sep 2013 10:04:20 -0400 Subject: [PATCH 21/34] more helpful error message --- tasks/couchapp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/couchapp.js b/tasks/couchapp.js index 464b63f..9df6922 100755 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -95,7 +95,7 @@ module.exports = function(grunt) { } }); } else { - var err_msg = "No database specified... skipping."; + var err_msg = "No database specified to create!"; grunt.warn(err_msg); return done(new Error(err_msg), null); } From eb0e451e380e4385aedd7ba62dbbdc584470353e Mon Sep 17 00:00:00 2001 From: Max Thayer Date: Sun, 8 Sep 2013 23:59:17 -0400 Subject: [PATCH 22/34] merged various branches; demo passes --- package.json | 82 +++++++++++++++++++++++------------------------ tasks/couchapp.js | 45 +++++++++++--------------- 2 files changed, 59 insertions(+), 68 deletions(-) diff --git a/package.json b/package.json index 0355b45..da0e34f 100644 --- a/package.json +++ b/package.json @@ -1,43 +1,43 @@ { - "name": "grunt-couchapp", - "description": "A grunt plugin for building and uploading couchapps", - "version": "0.1.0", - "homepage": "https://github.com/elf/grunt-couchapp", - "author": { - "name": "Ken Elf Mathieu Sternberg", - "email": "elf.sternberg@gmail.com", - "url": "http://elfsternberg.com" - }, - "repository": { - "type": "git", - "url": "git://github.com/elf/grunt-couchapp.git" - }, - "bugs": { - "url": "https://github.com/elf/grunt-couchapp/issues" - }, - "licenses": [ - { - "type": "MIT", - "url": "https://github.com/elf/grunt-couchapp/blob/master/LICENSE-MIT" - } - ], - "main": "grunt.js", - "bin": "bin/grunt-couchapp", - "engines": { - "node": "*" - }, - "scripts": { - "test": "grunt test" - }, - "dependencies": { - "couchapp": "0.10.*", - "grunt": "~0.3.12", - "nano": "3.3.0" - }, - "devDependencies": { - "grunt": "~0.3.12" - }, - "keywords": [ - "gruntplugin" - ] + "name": "grunt-couchapp", + "description": "A grunt plugin for building and uploading couchapps", + "version": "0.1.0", + "homepage": "https://github.com/elf/grunt-couchapp", + "author": { + "name": "Ken Elf Mathieu Sternberg", + "email": "elf.sternberg@gmail.com", + "url": "http://elfsternberg.com" + }, + "repository": { + "type": "git", + "url": "git://github.com/elf/grunt-couchapp.git" + }, + "bugs": { + "url": "https://github.com/elf/grunt-couchapp/issues" + }, + "licenses": [ + { + "type": "MIT", + "url": "https://github.com/elf/grunt-couchapp/blob/master/LICENSE-MIT" + } + ], + "main": "grunt.js", + "bin": "bin/grunt-couchapp", + "engines": { + "node": "*" + }, + "scripts": { + "test": "grunt test" + }, + "dependencies": { + "couchapp": "0.10.*", + "grunt": "~0.3.12", + "nano": "3.3.0" + }, + "devDependencies": { + "grunt": "~0.3.12" + }, + "keywords": [ + "gruntplugin" + ] } diff --git a/tasks/couchapp.js b/tasks/couchapp.js index 916265a..1c39b97 100755 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -5,12 +5,11 @@ * Licensed under the MIT license. */ -var path, couchapp, nanolib, urls, async; +var path, couchapp, nanolib, urls; path = require('path'); couchapp = require('couchapp'); urls = require('url'); -async = require('async'); var genDB = function(db) { var parts, dbname, auth; @@ -41,23 +40,14 @@ module.exports = function(grunt) { // ========================================================================== grunt.registerMultiTask("couchapp", "Install Couchapp", function() { - var task = this; - var done = this.async(); - - async.each(this.files, function(file, cb) { - var appobj, apppath - apppath = path.join(process.cwd(), path.normalize(file.src[0])) - try { - appobj = require(apppath) - couchapp.createApp(appobj, task.data.db, function(app) { - app.push(cb); - }); - } catch(ex) { - grunt.log.error(ex); - grunt.log.warn('Could not load couchapp from ' + apppath + '.'); - cb(); - } - }, done); + var appobj, done; + done = this.async(); + + appobj = require(path.join(process.cwd(), path.normalize(this.data.app))); + + return couchapp.createApp(appobj, this.data.db, function(app) { + return app.push(done); + }); }); grunt.registerMultiTask("rmcouchdb", "Delete a Couch Database", function() { @@ -103,17 +93,18 @@ module.exports = function(grunt) { try { 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){ + nano.db.create(db.name, function(err, res) { + if (err) { + if (_this.data.options && _this.data.options.okay_if_exists) { grunt.log.writeln("Database " + db.name + " exists, skipping"); + return done(null, null); + } else { + grunt.warn("Database " + db.name + " exists, aborting."); + return done(err, null); } - return done(null, null); } else { - if (err){ - grunt.warn(err); - } - return done(err, null); + grunt.log.writeln("Database " + db.name + " created."); + return done(null, null); } }); } else { From d0f8fb3d213378a7c7d058b5e6597140f914e086 Mon Sep 17 00:00:00 2001 From: Max Thayer Date: Mon, 9 Sep 2013 00:02:27 -0400 Subject: [PATCH 23/34] bump version number, switch maintainer urls --- package.json | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index da0e34f..1e229b9 100644 --- a/package.json +++ b/package.json @@ -1,24 +1,29 @@ { "name": "grunt-couchapp", "description": "A grunt plugin for building and uploading couchapps", - "version": "0.1.0", - "homepage": "https://github.com/elf/grunt-couchapp", + "version": "0.2.0", + "homepage": "https://github.com/garbados/grunt-couchapp", "author": { "name": "Ken Elf Mathieu Sternberg", "email": "elf.sternberg@gmail.com", "url": "http://elfsternberg.com" }, + "contributors": [{ + "name": "Max Thayer", + "email": "garbados@gmail.com", + "url": "http://maxthayer.org" + }], "repository": { "type": "git", - "url": "git://github.com/elf/grunt-couchapp.git" + "url": "git://github.com/garbados/grunt-couchapp.git" }, "bugs": { - "url": "https://github.com/elf/grunt-couchapp/issues" + "url": "https://github.com/garbados/grunt-couchapp/issues" }, "licenses": [ { "type": "MIT", - "url": "https://github.com/elf/grunt-couchapp/blob/master/LICENSE-MIT" + "url": "https://github.com/garbados/grunt-couchapp/blob/master/LICENSE-MIT" } ], "main": "grunt.js", @@ -38,6 +43,8 @@ "grunt": "~0.3.12" }, "keywords": [ - "gruntplugin" + "gruntplugin", + "couchdb", + "couchapp" ] } From 179a8766152ce9801ec9734b89083f0b35b40af8 Mon Sep 17 00:00:00 2001 From: "James E. Marca" Date: Wed, 16 Oct 2013 12:32:43 -0700 Subject: [PATCH 24/34] genDB was repeated. deleted the second one --- tasks/couchapp.js | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/tasks/couchapp.js b/tasks/couchapp.js index 1c39b97..80bc15c 100755 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -22,16 +22,6 @@ var genDB = function(db) { }; }; -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) { @@ -72,7 +62,7 @@ module.exports = function(grunt) { } } return done(err, null); - }); + }); } else { grunt.log.writeln("No database specified... skipping."); return done(null, null); @@ -106,7 +96,7 @@ module.exports = function(grunt) { grunt.log.writeln("Database " + db.name + " created."); return done(null, null); } - }); + }); } else { var err_msg = "No database specified to create!"; grunt.warn(err_msg); From ec656e9c657acf19cf6f1357449656b829e4093d Mon Sep 17 00:00:00 2001 From: "James E. Marca" Date: Wed, 16 Oct 2013 13:17:10 -0700 Subject: [PATCH 25/34] declare 'db' var in both functions modified: tasks/couchapp.js added 'db' to the var list in grunt.registerMultiTask("rmcouchdb",...) and grunt.registerMultiTask("mkcouchdb",..). Also, Emacs got rid of some white space. Sorry about that bit of extraneous patching. --- tasks/couchapp.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tasks/couchapp.js b/tasks/couchapp.js index 1c39b97..29a43d0 100755 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -51,7 +51,7 @@ module.exports = function(grunt) { }); grunt.registerMultiTask("rmcouchdb", "Delete a Couch Database", function() { - var done, parts, nano, dbname, _this; + var done, parts, nano, dbname, _this, db; _this = this; done = this.async(); db = genDB(this.data.db); @@ -72,7 +72,7 @@ module.exports = function(grunt) { } } return done(err, null); - }); + }); } else { grunt.log.writeln("No database specified... skipping."); return done(null, null); @@ -84,7 +84,7 @@ module.exports = function(grunt) { }); grunt.registerMultiTask("mkcouchdb", "Make a Couch Database", function() { - var done, parts, nano, dbname, _this; + var done, parts, nano, dbname, _this, db; _this = this; done = this.async(); @@ -106,7 +106,7 @@ module.exports = function(grunt) { grunt.log.writeln("Database " + db.name + " created."); return done(null, null); } - }); + }); } else { var err_msg = "No database specified to create!"; grunt.warn(err_msg); From 008e268c0602285f10380dfbde37f9dd0b65397f Mon Sep 17 00:00:00 2001 From: "James E. Marca" Date: Wed, 16 Oct 2013 13:22:50 -0700 Subject: [PATCH 26/34] return null; at the end of the two main functions, add "return null;" because otherwise Emacs javascript parser whinges about not returning something from a routine. I guess it is in the standard and all that. apologies if this is noise, but that's why I'm making tiny commits...you can ignore them. --- tasks/couchapp.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tasks/couchapp.js b/tasks/couchapp.js index 1c39b97..0b91020 100755 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -72,7 +72,7 @@ module.exports = function(grunt) { } } return done(err, null); - }); + }); } else { grunt.log.writeln("No database specified... skipping."); return done(null, null); @@ -81,6 +81,7 @@ module.exports = function(grunt) { grunt.warn(e); done(e, null); } + return null; }); grunt.registerMultiTask("mkcouchdb", "Make a Couch Database", function() { @@ -106,7 +107,7 @@ module.exports = function(grunt) { grunt.log.writeln("Database " + db.name + " created."); return done(null, null); } - }); + }); } else { var err_msg = "No database specified to create!"; grunt.warn(err_msg); @@ -116,6 +117,7 @@ module.exports = function(grunt) { grunt.warn(e); done(e, null); } + return null; }); }; From 038e4123e6c4ed971529e87a705945a6805fa326 Mon Sep 17 00:00:00 2001 From: Max Thayer Date: Wed, 16 Oct 2013 21:20:07 -0400 Subject: [PATCH 27/34] version bump, thanks to jmarca :D --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1e229b9..dc2107a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "grunt-couchapp", "description": "A grunt plugin for building and uploading couchapps", - "version": "0.2.0", + "version": "0.2.1", "homepage": "https://github.com/garbados/grunt-couchapp", "author": { "name": "Ken Elf Mathieu Sternberg", From ea9462883622c29d793da98df85d21a689379849 Mon Sep 17 00:00:00 2001 From: Sam Hiatt Date: Thu, 11 Sep 2014 18:24:00 -0700 Subject: [PATCH 28/34] Added attribution and changed author to me. --- .gitignore | 1 + LICENSE-MIT | 4 +++- README.md | 3 ++- package.json | 23 ++++++++++++++--------- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index db3f887..ff0456f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ *~ npm-debug.log node_modules/* +.idea diff --git a/LICENSE-MIT b/LICENSE-MIT index 17416f9..5c43c07 100644 --- a/LICENSE-MIT +++ b/LICENSE-MIT @@ -1,4 +1,6 @@ -Copyright (c) 2012 Ken Elf Mathieu Sternberg +Copyright (c) +2012 Ken Elf Mathieu Sternberg +2014 Sam Hiatt Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation diff --git a/README.md b/README.md index ba68fa6..6bf6a29 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # grunt-couchapp -A grunt plugin for building and installing couchapps +A grunt plugin for building and installing couchapps, +forked from https://github.com/garbados/grunt-couchapp ## Getting Started diff --git a/package.json b/package.json index dc2107a..55b1807 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,23 @@ { "name": "grunt-couchapp", "description": "A grunt plugin for building and uploading couchapps", - "version": "0.2.1", + "version": "0.2.2", "homepage": "https://github.com/garbados/grunt-couchapp", "author": { - "name": "Ken Elf Mathieu Sternberg", - "email": "elf.sternberg@gmail.com", - "url": "http://elfsternberg.com" + "name":"Sam Hiatt", + "email": "sam.hiatt@weather.com" }, - "contributors": [{ - "name": "Max Thayer", - "email": "garbados@gmail.com", - "url": "http://maxthayer.org" - }], + "contributors": [ + { + "name": "Ken Elf Mathieu Sternberg", + "email": "elf.sternberg@gmail.com", + "url": "http://elfsternberg.com" + },{ + "name": "Max Thayer", + "email": "garbados@gmail.com", + "url": "http://maxthayer.org" + } + ], "repository": { "type": "git", "url": "git://github.com/garbados/grunt-couchapp.git" From 6a8ce0718db6e3449088159bf2daf8b937f7bd62 Mon Sep 17 00:00:00 2001 From: Sam Hiatt Date: Thu, 11 Sep 2014 19:30:58 -0700 Subject: [PATCH 29/34] Improved error checking for mkcouchdb and rmcouchdb tasks. --- tasks/couchapp.js | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/tasks/couchapp.js b/tasks/couchapp.js index 30482c3..94db5b5 100755 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -55,13 +55,14 @@ module.exports = function(grunt) { grunt.log.writeln("Database " + db.name + " not present... skipping."); return done(null, null) ; } else { - grunt.warn("Database " + db.name + " does not exist."); + throw ("Database " + db.name + " does not exist."); } } else { - grunt.warn(err); + throw err; } } - return done(err, null); + // remove db was a success + return done(); }); } else { grunt.log.writeln("No database specified... skipping."); @@ -69,7 +70,7 @@ module.exports = function(grunt) { } } catch (e) { grunt.warn(e); - done(e, null); + return done(e, null); } return null; }); @@ -86,26 +87,35 @@ module.exports = function(grunt) { nano = require('nano')(db.url); nano.db.create(db.name, function(err, res) { if (err) { - if (_this.data.options && _this.data.options.okay_if_exists) { + if (err.error && err.error=="unauthorized") { + grunt.warn(err.reason); + throw err; + } else if (err.code && err.description) { // probably connection error + throw err; + } + else if (_this.data.options && _this.data.options.okay_if_exists) { grunt.log.writeln("Database " + db.name + " exists, skipping"); return done(null, null); } else { - grunt.warn("Database " + db.name + " exists, aborting."); - return done(err, null); + grunt.warn("Database " + db.name + " exists and okay_if_exists set to false. Aborting."); + throw err; } - } else { - grunt.log.writeln("Database " + db.name + " created."); + } else if (res && res.ok==true) { + grunt.log.ok("Database " + db.name + " created."); return done(null, null); + } else { + console.log("Unexpected response received."); + console.dir(res); + throw "Unexpected response"; } }); } else { var err_msg = "No database specified to create!"; - grunt.warn(err_msg); - return done(new Error(err_msg), null); + throw err_msg; } } catch (e) { grunt.warn(e); - done(e, null); + return done(e, null); } return null; }); From 541539cd68544fef3806f4914d342a4310553077 Mon Sep 17 00:00:00 2001 From: Sam Hiatt Date: Thu, 11 Sep 2014 19:58:43 -0700 Subject: [PATCH 30/34] Added support for new-style (directory-based) couchapps. --- tasks/couchapp.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tasks/couchapp.js b/tasks/couchapp.js index 94db5b5..ebbc3d9 100755 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -32,8 +32,11 @@ module.exports = function(grunt) { grunt.registerMultiTask("couchapp", "Install Couchapp", function() { var appobj, done; done = this.async(); - - appobj = require(path.join(process.cwd(), path.normalize(this.data.app))); + if (require("fs").lstatSync(this.data.app).isDirectory()) { // if new-style (directory-based) couchapp app + appobj = couchapp.loadFiles(this.data.app); + } else { // otherwise, fall back to old style. + appobj = require(path.join(process.cwd(), path.normalize(this.data.app))) + } return couchapp.createApp(appobj, this.data.db, function(app) { return app.push(done); From 508e1eec96b5ee02c5cc10013842a219197b7699 Mon Sep 17 00:00:00 2001 From: Sam Hiatt Date: Fri, 12 Sep 2014 18:50:10 -0700 Subject: [PATCH 31/34] Fixes bug where 'database exists' is reported when other couchdb errors are encountered. --- tasks/couchapp.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tasks/couchapp.js b/tasks/couchapp.js index ebbc3d9..0d24d33 100755 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -96,12 +96,17 @@ module.exports = function(grunt) { } else if (err.code && err.description) { // probably connection error throw err; } - else if (_this.data.options && _this.data.options.okay_if_exists) { - grunt.log.writeln("Database " + db.name + " exists, skipping"); - return done(null, null); + else if (err.error && err.error=="file_exists") { + if (_this.data.options && _this.data.options.okay_if_exists) { + grunt.log.writeln("Database " + db.name + " exists, skipping"); + return done(null, null); + } else { + grunt.warn("Database " + db.name + " exists and okay_if_exists set to false. Aborting."); + throw err; + } } else { - grunt.warn("Database " + db.name + " exists and okay_if_exists set to false. Aborting."); - throw err; + console.warn("Unrecognized error."); + throw err } } else if (res && res.ok==true) { grunt.log.ok("Database " + db.name + " created."); From f7b70e9f5ebdd7c37be37b4efdadce8084c26a70 Mon Sep 17 00:00:00 2001 From: Sam Hiatt Date: Fri, 19 Sep 2014 17:04:05 -0700 Subject: [PATCH 32/34] Fixed bug when adding attachments to design doc that uses a directory-based app structure. --- tasks/couchapp.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tasks/couchapp.js b/tasks/couchapp.js index 0d24d33..17104c4 100755 --- a/tasks/couchapp.js +++ b/tasks/couchapp.js @@ -34,6 +34,9 @@ module.exports = function(grunt) { done = this.async(); if (require("fs").lstatSync(this.data.app).isDirectory()) { // if new-style (directory-based) couchapp app appobj = couchapp.loadFiles(this.data.app); + delete appobj._attachments; + delete appobj['']; + couchapp.loadAttachments(appobj, this.data.app+"/_attachments"); } else { // otherwise, fall back to old style. appobj = require(path.join(process.cwd(), path.normalize(this.data.app))) } From 37928a8ed6325688681295a69edd9b5ce0c64b26 Mon Sep 17 00:00:00 2001 From: Sam Hiatt Date: Fri, 19 Sep 2014 17:23:07 -0700 Subject: [PATCH 33/34] Reverting inadvertantly-committed changes to README and author/contributors in package.json. --- README.md | 3 +-- package.json | 13 +++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6bf6a29..ba68fa6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # grunt-couchapp -A grunt plugin for building and installing couchapps, -forked from https://github.com/garbados/grunt-couchapp +A grunt plugin for building and installing couchapps ## Getting Started diff --git a/package.json b/package.json index 55b1807..6ab87ca 100644 --- a/package.json +++ b/package.json @@ -4,18 +4,19 @@ "version": "0.2.2", "homepage": "https://github.com/garbados/grunt-couchapp", "author": { - "name":"Sam Hiatt", - "email": "sam.hiatt@weather.com" - }, - "contributors": [ - { "name": "Ken Elf Mathieu Sternberg", "email": "elf.sternberg@gmail.com", "url": "http://elfsternberg.com" - },{ + }, + "contributors": [ + { "name": "Max Thayer", "email": "garbados@gmail.com", "url": "http://maxthayer.org" + }, + { + "name":"Sam Hiatt", + "email": "sam.hiatt@weather.com" } ], "repository": { From ef190f56504e3b8003dfeec967ba423241b2a5a3 Mon Sep 17 00:00:00 2001 From: Robert Kowalski Date: Sun, 5 Oct 2014 15:11:23 +0200 Subject: [PATCH 34/34] couchapp@0.11.0 removes the horn sound on push, which breaks on linux --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6ab87ca..55d6745 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "test": "grunt test" }, "dependencies": { - "couchapp": "0.10.*", + "couchapp": "~0.11.0", "grunt": "~0.3.12", "nano": "3.3.0" },