UNPKG

788 BJavaScriptView Raw
1const e=require("lodash"),r=require("fs"),i=require("./files.js"),o=require("./credentials"),t=require("./files"),a=require("bluebird"),s=require("./api"),n=require("path");var l=module.exports={};l.setHistory=a.coroutine(function*(e,t,a){var l=a?n.join(config.APP_DIR,a,".history.json"):n.join(config.APP_DIR,".history.json"),c={};try{c=yield i.getIndex()}catch(e){}var d=c.appId,y=yield o.checkCredentials();if(yield i.createHistoryFile(l),d&&y){var u={body:{history:{operation:e,message:t,created_at:Date.now()}},headers:{accesstoken:y},method:"POST"};yield s.makeApiCall("/app/"+d.toString()+"/history",u)}else{var h={operation:e,message:t,created_at:Date.now()};r.appendFileSync(l,"\n"+JSON.stringify(h),{},function(e){if(e)return console.err("Error while saving history file")})}});
\No newline at end of file