From ea9462883622c29d793da98df85d21a689379849 Mon Sep 17 00:00:00 2001 From: Sam Hiatt Date: Thu, 11 Sep 2014 18:24:00 -0700 Subject: [PATCH 1/4] 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 2/4] 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 3/4] 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 4/4] 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.");