From 81f490a1f5bc0cf01ac0ecda4cf9e27e38165323 Mon Sep 17 00:00:00 2001 From: skiqh Date: Wed, 3 Jul 2013 18:44:49 +0200 Subject: [PATCH 1/2] 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 2/2] 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() {