Merge pull request #7 from samhiatt/master
Improved error checking and added support for new-style (directory-based) couchapps.
This commit is contained in:
commit
dbc7e34225
|
@ -3,3 +3,4 @@
|
||||||
*~
|
*~
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
node_modules/*
|
node_modules/*
|
||||||
|
.idea
|
||||||
|
|
|
@ -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
|
Permission is hereby granted, free of charge, to any person
|
||||||
obtaining a copy of this software and associated documentation
|
obtaining a copy of this software and associated documentation
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# grunt-couchapp
|
# 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
|
## Getting Started
|
||||||
|
|
||||||
|
|
23
package.json
23
package.json
|
@ -1,18 +1,23 @@
|
||||||
{
|
{
|
||||||
"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.2.1",
|
"version": "0.2.2",
|
||||||
"homepage": "https://github.com/garbados/grunt-couchapp",
|
"homepage": "https://github.com/garbados/grunt-couchapp",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Ken Elf Mathieu Sternberg",
|
"name":"Sam Hiatt",
|
||||||
"email": "elf.sternberg@gmail.com",
|
"email": "sam.hiatt@weather.com"
|
||||||
"url": "http://elfsternberg.com"
|
|
||||||
},
|
},
|
||||||
"contributors": [{
|
"contributors": [
|
||||||
"name": "Max Thayer",
|
{
|
||||||
"email": "garbados@gmail.com",
|
"name": "Ken Elf Mathieu Sternberg",
|
||||||
"url": "http://maxthayer.org"
|
"email": "elf.sternberg@gmail.com",
|
||||||
}],
|
"url": "http://elfsternberg.com"
|
||||||
|
},{
|
||||||
|
"name": "Max Thayer",
|
||||||
|
"email": "garbados@gmail.com",
|
||||||
|
"url": "http://maxthayer.org"
|
||||||
|
}
|
||||||
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git://github.com/garbados/grunt-couchapp.git"
|
"url": "git://github.com/garbados/grunt-couchapp.git"
|
||||||
|
|
|
@ -32,8 +32,11 @@ module.exports = function(grunt) {
|
||||||
grunt.registerMultiTask("couchapp", "Install Couchapp", function() {
|
grunt.registerMultiTask("couchapp", "Install Couchapp", function() {
|
||||||
var appobj, done;
|
var appobj, done;
|
||||||
done = this.async();
|
done = this.async();
|
||||||
|
if (require("fs").lstatSync(this.data.app).isDirectory()) { // if new-style (directory-based) couchapp app
|
||||||
appobj = require(path.join(process.cwd(), path.normalize(this.data.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 couchapp.createApp(appobj, this.data.db, function(app) {
|
||||||
return app.push(done);
|
return app.push(done);
|
||||||
|
@ -55,13 +58,14 @@ module.exports = function(grunt) {
|
||||||
grunt.log.writeln("Database " + db.name + " not present... skipping.");
|
grunt.log.writeln("Database " + db.name + " not present... skipping.");
|
||||||
return done(null, null) ;
|
return done(null, null) ;
|
||||||
} else {
|
} else {
|
||||||
grunt.warn("Database " + db.name + " does not exist.");
|
throw ("Database " + db.name + " does not exist.");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
grunt.warn(err);
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return done(err, null);
|
// remove db was a success
|
||||||
|
return done();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
grunt.log.writeln("No database specified... skipping.");
|
grunt.log.writeln("No database specified... skipping.");
|
||||||
|
@ -69,7 +73,7 @@ module.exports = function(grunt) {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
grunt.warn(e);
|
grunt.warn(e);
|
||||||
done(e, null);
|
return done(e, null);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
@ -86,26 +90,40 @@ module.exports = function(grunt) {
|
||||||
nano = require('nano')(db.url);
|
nano = require('nano')(db.url);
|
||||||
nano.db.create(db.name, function(err, res) {
|
nano.db.create(db.name, function(err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (_this.data.options && _this.data.options.okay_if_exists) {
|
if (err.error && err.error=="unauthorized") {
|
||||||
grunt.log.writeln("Database " + db.name + " exists, skipping");
|
grunt.warn(err.reason);
|
||||||
return done(null, null);
|
throw err;
|
||||||
} else {
|
} else if (err.code && err.description) { // probably connection error
|
||||||
grunt.warn("Database " + db.name + " exists, aborting.");
|
throw err;
|
||||||
return done(err, null);
|
|
||||||
}
|
}
|
||||||
} else {
|
else if (err.error && err.error=="file_exists") {
|
||||||
grunt.log.writeln("Database " + db.name + " created.");
|
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 {
|
||||||
|
console.warn("Unrecognized error.");
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
} else if (res && res.ok==true) {
|
||||||
|
grunt.log.ok("Database " + db.name + " created.");
|
||||||
return done(null, null);
|
return done(null, null);
|
||||||
|
} else {
|
||||||
|
console.log("Unexpected response received.");
|
||||||
|
console.dir(res);
|
||||||
|
throw "Unexpected response";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var err_msg = "No database specified to create!";
|
var err_msg = "No database specified to create!";
|
||||||
grunt.warn(err_msg);
|
throw err_msg;
|
||||||
return done(new Error(err_msg), null);
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
grunt.warn(e);
|
grunt.warn(e);
|
||||||
done(e, null);
|
return done(e, null);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue