Merge 81e65c734c
into 0b295a3e15
This commit is contained in:
commit
5604e604a3
|
@ -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
|
||||||
|
|
13
README.md
13
README.md
|
@ -10,9 +10,7 @@ grunt-couchapp`
|
||||||
|
|
||||||
Then add this line to your project's `grunt.js` gruntfile:
|
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
|
[grunt]: https://github.com/cowboy/grunt
|
||||||
[getting_started]: https://github.com/cowboy/grunt/blob/master/docs/getting_started.md
|
[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: {
|
mkcouchdb: {
|
||||||
demo: {
|
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',
|
db: 'http://localhost:5984/grunt-couchapp-demo',
|
||||||
app: './demo/app.js',
|
app: './demo/app.js',
|
||||||
options: {
|
options: {
|
||||||
okay_if_missing: true
|
okay_if_missing: true,
|
||||||
|
okay_if_exists: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,8 +70,7 @@ possible to write in your configuration file:
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
Note, however, that if you call 'rmcouchdb' without a sub-argument, in
|
Note that if you call `rmcouchdb` without a sub-argument, it will not delete any databases.
|
||||||
keeping with grunt's standards, it will drop *all* of your databases!
|
|
||||||
|
|
||||||
## Demo
|
## Demo
|
||||||
|
|
||||||
|
|
27
package.json
27
package.json
|
@ -1,24 +1,35 @@
|
||||||
{
|
{
|
||||||
"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.2.2",
|
||||||
"homepage": "https://github.com/elf/grunt-couchapp",
|
"homepage": "https://github.com/garbados/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"
|
||||||
},
|
},
|
||||||
|
"contributors": [
|
||||||
|
{
|
||||||
|
"name": "Max Thayer",
|
||||||
|
"email": "garbados@gmail.com",
|
||||||
|
"url": "http://maxthayer.org"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name":"Sam Hiatt",
|
||||||
|
"email": "sam.hiatt@weather.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git://github.com/elf/grunt-couchapp.git"
|
"url": "git://github.com/garbados/grunt-couchapp.git"
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/elf/grunt-couchapp/issues"
|
"url": "https://github.com/garbados/grunt-couchapp/issues"
|
||||||
},
|
},
|
||||||
"licenses": [
|
"licenses": [
|
||||||
{
|
{
|
||||||
"type": "MIT",
|
"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",
|
"main": "grunt.js",
|
||||||
|
@ -30,7 +41,7 @@
|
||||||
"test": "grunt test"
|
"test": "grunt test"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"couchapp": "0.9.1",
|
"couchapp": "~0.11.0",
|
||||||
"grunt": "~0.3.12",
|
"grunt": "~0.3.12",
|
||||||
"nano": "3.3.0"
|
"nano": "3.3.0"
|
||||||
},
|
},
|
||||||
|
@ -38,6 +49,8 @@
|
||||||
"grunt": "~0.3.12"
|
"grunt": "~0.3.12"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"gruntplugin"
|
"gruntplugin",
|
||||||
|
"couchdb",
|
||||||
|
"couchapp"
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -11,6 +11,18 @@ path = require('path');
|
||||||
couchapp = require('couchapp');
|
couchapp = require('couchapp');
|
||||||
urls = require('url');
|
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) {
|
module.exports = function(grunt) {
|
||||||
|
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
@ -20,66 +32,103 @@ 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();
|
||||||
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);
|
||||||
|
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)))
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
grunt.registerMultiTask("rmcouchdb", "Delete a Couch Database", function() {
|
grunt.registerMultiTask("rmcouchdb", "Delete a Couch Database", function() {
|
||||||
var done, parts, nano, dbname, _this;
|
var done, parts, nano, dbname, _this, db;
|
||||||
_this = this;
|
_this = this;
|
||||||
done = this.async();
|
done = this.async();
|
||||||
parts = urls.parse(this.data.db);
|
db = genDB(this.data.db);
|
||||||
dbname = parts.pathname.replace(/^\//, '');
|
|
||||||
try {
|
try {
|
||||||
nano = require('nano')(parts.protocol + '//' + parts.host);
|
nano = require('nano')(db.url);
|
||||||
nano.db.destroy(dbname, function(err) {
|
if (db.name) {
|
||||||
|
nano.db.destroy(db.name, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
if (err.status_code && err.status_code === 404) {
|
if (err.status_code && err.status_code === 404) {
|
||||||
if (_this.data.options && _this.data.options.okay_if_missing) {
|
if (_this.data.options && _this.data.options.okay_if_missing) {
|
||||||
grunt.log.writeln("Database " + dbname + " 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 " + dbname + " 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 {
|
||||||
|
grunt.log.writeln("No database specified... skipping.");
|
||||||
|
return done(null, null);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
grunt.warn(e);
|
grunt.warn(e);
|
||||||
done(e, null);
|
return done(e, null);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
grunt.registerMultiTask("mkcouchdb", "Delete a Couch Database", function() {
|
grunt.registerMultiTask("mkcouchdb", "Make a Couch Database", function() {
|
||||||
var done, parts, nano, dbname, _this;
|
var done, parts, nano, dbname, _this, db;
|
||||||
_this = this;
|
_this = this;
|
||||||
|
|
||||||
done = this.async();
|
done = this.async();
|
||||||
parts = urls.parse(this.data.db);
|
parts = urls.parse(this.data.db);
|
||||||
dbname = parts.pathname.replace(/^\//, '');
|
db = genDB(this.data.db);
|
||||||
try {
|
try {
|
||||||
nano = require('nano')(parts.protocol + '//' + parts.host);
|
if (db.name) {
|
||||||
nano.db.create(dbname, function(err) {
|
nano = require('nano')(db.url);
|
||||||
if (_this.data.options && _this.data.options.okay_if_exists) {
|
nano.db.create(db.name, function(err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
grunt.log.writeln("Database " + dbname + " exists, skipping");
|
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 (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);
|
return done(null, null);
|
||||||
} else {
|
} else {
|
||||||
if (err){
|
grunt.warn("Database " + db.name + " exists and okay_if_exists set to false. Aborting.");
|
||||||
grunt.warn(err);
|
throw err;
|
||||||
}
|
}
|
||||||
return done(err, null);
|
} else {
|
||||||
|
console.warn("Unrecognized error.");
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
} 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!";
|
||||||
|
throw err_msg;
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
grunt.warn(e);
|
grunt.warn(e);
|
||||||
done(e, null);
|
return done(e, null);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue