decentralized-internet
Version:
An NPM library of programs to create decentralized web and distributed computing projects
1 lines • 1.7 kB
JavaScript
var request=require("request"),fs=require("fs"),Promise=require("bluebird"),path=require("path");module.exports=function(e,o,n){return(r=e,new Promise(function(e,o){request.put(r,function(n,i,t){if(n)o(n.message);else try{"not_found"===JSON.parse(t).error?request.put(r,function(o,n,r){e(JSON.parse(r))}):e(JSON.parse(t))}catch(e){console.error(r),console.error(e),o(e)}})})).then(function(r){return function(e,o){var r=fs.readdirSync(o);return Promise.map(r,function(r){return new Promise(function(i,t){try{-1===r.indexOf(".json")?t(r):fs.readFile(path.join(o,r),function(s,u){if(s)throw s;var c=JSON.parse(u),f={uri:e+"/"+c._id};request(f,function(s,u,f){var a=JSON.parse(f);if(JSON.stringify(c.views)!==JSON.stringify(a.views))if(n&&"not_found"!==a.error)console.info("You have two different design documents in the views directory and the couchdb instance:"),console.info("You should 'migrateUp' the DB or 'update' the document in the view's folder to get rid of this message."),console.info("Run the following command to migrate the view in couchdb"),console.info("node couchUpdateViews.js --migrate --viewsDir",o,"--couchDB",e),console.info("Run the following command to update in your directory"),console.info("node couchUpdateViews.js --update",path.basename(r),"--viewsDir",o,"--couchDB",e),i({message:"Documents differ.",couchDB:e,view:o+r});else{"not_found"===a.error&&console.info("Design document not found."),console.info("Deploying design document: ",c);var d=e+"/"+c._id;a._rev&&(c._rev=a._rev,d+="?rev="+c._rev),request({uri:d,method:"PUT",json:c},function(e,o,n){e?t(e.message):i(n)})}else i({message:"No changes in document.",couchDB:e,view:o+r})})})}catch(e){t(e)}})})}(e,o)});var r};