merged various branches; demo passes

This commit is contained in:
Max Thayer 2013-09-08 23:59:17 -04:00
parent d636e472b0
commit eb0e451e38
2 changed files with 59 additions and 68 deletions

View File

@ -1,43 +1,43 @@
{ {
"name": "grunt-couchapp", "name": "grunt-couchapp",
"description": "A grunt plugin for building and uploading couchapps", "description": "A grunt plugin for building and uploading couchapps",
"version": "0.1.0", "version": "0.1.0",
"homepage": "https://github.com/elf/grunt-couchapp", "homepage": "https://github.com/elf/grunt-couchapp",
"author": { "author": {
"name": "Ken Elf Mathieu Sternberg", "name": "Ken Elf Mathieu Sternberg",
"email": "elf.sternberg@gmail.com", "email": "elf.sternberg@gmail.com",
"url": "http://elfsternberg.com" "url": "http://elfsternberg.com"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/elf/grunt-couchapp.git" "url": "git://github.com/elf/grunt-couchapp.git"
}, },
"bugs": { "bugs": {
"url": "https://github.com/elf/grunt-couchapp/issues" "url": "https://github.com/elf/grunt-couchapp/issues"
}, },
"licenses": [ "licenses": [
{ {
"type": "MIT", "type": "MIT",
"url": "https://github.com/elf/grunt-couchapp/blob/master/LICENSE-MIT" "url": "https://github.com/elf/grunt-couchapp/blob/master/LICENSE-MIT"
} }
], ],
"main": "grunt.js", "main": "grunt.js",
"bin": "bin/grunt-couchapp", "bin": "bin/grunt-couchapp",
"engines": { "engines": {
"node": "*" "node": "*"
}, },
"scripts": { "scripts": {
"test": "grunt test" "test": "grunt test"
}, },
"dependencies": { "dependencies": {
"couchapp": "0.10.*", "couchapp": "0.10.*",
"grunt": "~0.3.12", "grunt": "~0.3.12",
"nano": "3.3.0" "nano": "3.3.0"
}, },
"devDependencies": { "devDependencies": {
"grunt": "~0.3.12" "grunt": "~0.3.12"
}, },
"keywords": [ "keywords": [
"gruntplugin" "gruntplugin"
] ]
} }

View File

@ -5,12 +5,11 @@
* Licensed under the MIT license. * Licensed under the MIT license.
*/ */
var path, couchapp, nanolib, urls, async; var path, couchapp, nanolib, urls;
path = require('path'); path = require('path');
couchapp = require('couchapp'); couchapp = require('couchapp');
urls = require('url'); urls = require('url');
async = require('async');
var genDB = function(db) { var genDB = function(db) {
var parts, dbname, auth; var parts, dbname, auth;
@ -41,23 +40,14 @@ module.exports = function(grunt) {
// ========================================================================== // ==========================================================================
grunt.registerMultiTask("couchapp", "Install Couchapp", function() { grunt.registerMultiTask("couchapp", "Install Couchapp", function() {
var task = this; var appobj, done;
var done = this.async(); done = this.async();
async.each(this.files, function(file, cb) { appobj = require(path.join(process.cwd(), path.normalize(this.data.app)));
var appobj, apppath
apppath = path.join(process.cwd(), path.normalize(file.src[0])) return couchapp.createApp(appobj, this.data.db, function(app) {
try { return app.push(done);
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() { grunt.registerMultiTask("rmcouchdb", "Delete a Couch Database", function() {
@ -103,17 +93,18 @@ module.exports = function(grunt) {
try { try {
if (db.name) { 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, res) {
if (_this.data.options && _this.data.options.okay_if_exists) { if (err) {
if (err){ if (_this.data.options && _this.data.options.okay_if_exists) {
grunt.log.writeln("Database " + db.name + " exists, skipping"); 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 { } else {
if (err){ grunt.log.writeln("Database " + db.name + " created.");
grunt.warn(err); return done(null, null);
}
return done(err, null);
} }
}); });
} else { } else {