/** * jibo-sync - Sync an entire a directory over HTTP; including incremental changes * @version v0.2.8 * @license Copyright (c) 2017, Jibo, Inc. All rights reserved. * All use of the Jibo SDK is subject to the Jibo SDK End User License Agreement (EULA) * distributed herewith. If you did not receive a copy of the EULA, you may view a * copy at https://developers.jibo.com/license. */ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.jiboSync=e()}}(function(){return function e(t,n,o){function r(a,u){if(!n[a]){if(!t[a]){var s="function"==typeof require&&require;if(!u&&s)return s(a,!0);if(i)return i(a,!0);var l=new Error("Cannot find module '"+a+"'");throw l.code="MODULE_NOT_FOUND",l}var f=n[a]={exports:{}};t[a][0].call(f.exports,function(e){var n=t[a][1][e];return r(n?n:e)},f,f.exports,e,t,n,o)}return n[a].exports}for(var i="function"==typeof require&&require,a=0;a0){v.default.log("\nDeleting "+n.length+" files");var r=JSON.stringify({deleteList:n}),i={host:e,port:t,path:"/delete",method:"POST",headers:{"Content-Type":"application/json","Content-Length":r.length}},a=l.request(i,function(e){var t="";e.on("data",function(e){t+=e}),e.on("end",function(){o("ERROR"===e.status?t:null)})});a.on("error",function(e){o(e)}),a.write(r),a.end()}else o(null)}function s(e,t,n,o,r){if(n.length>0){v.default.log("\nUpdating "+n.length+" files from "+o);var i="http://"+e+":"+t+"/upload",a=p.post(i),u=new d,s=new d,l=c.pack(o,{entries:n,dereference:!0}),g=l.pipe(u).pipe(f.createGzip({level:9})).pipe(s).pipe(a);m.once("stop",function(){g.abort(),r(h.default.STOPPED)}),g.on("end",function(e){r(e,u.bytes,s.bytes)}),g.on("error",function(e){r(e,null,null)})}else r(null,0,0)}var l=e("http"),f=e("zlib"),c=e("tar-fs"),d=e("stream-meter"),p=e("request"),v=e("./Common"),h=e("./FailErrors"),g=e("./Stopper"),m=new g.default,O=function(){function e(){}return e.push=function(e,t,n,u){v.default.setVerbose(n);var s=v.default.getHostPort(e);if(!s)return void u("Error parsing url into host:port");var l=s.host,f=s.port,c=o(t),d=Date.now();r(l,f).then(function(e){return i(c,e)}).then(function(e){var t=e.updateList,n=e.deleteList;return a(l,f,c,t,n)}).then(function(){u(null,"Done in "+(Date.now()-d)/1e3+" seconds")}).catch(function(e){u(e)})},e.done=function(e,t){var n=v.default.getHostPort(e);if(!n)return void t("Error parsing url into host:port",null);var o={host:n.host,port:n.port,path:"/close",method:"POST"},r=l.request(o,function(e){var n="";e.on("data",function(e){n+=e}),e.on("end",function(){var o;try{o=JSON.parse(n)}catch(t){return e.writeHead(200,{"Content-Type":"text/html"}),e.write(JSON.stringify({Status:"ERROR",Message:"Invalid request to close sync server. Request body is not valid JSON"})),void e.end()}"ERROR"===o.Status?t(o.Message,null):t(null,o.Message)})});r.end()},e}();O.FAIL_ERRORS=h.default,Object.defineProperty(n,"__esModule",{value:!0}),n.default=O},{"./Common":4,"./FailErrors":5,"./Stopper":7,http:void 0,request:void 0,"stream-meter":void 0,"tar-fs":void 0,zlib:void 0}],3:[function(e,t,n){"use strict";var o=e("./API"),r=e("path"),i=function(){function t(e){this.allowedCommands=[["create-server","[port] [dest] [--verbose]","Create a sync server on current IP with specified port and designated destination directory"],["start","[url] [source] [--verbose]","Sync source directory to specified server url (ip:port)"]],this.allowedOptions=[["-h","--help","Output usage information"],["-V","--version","Output the version number"]],this.rootPath=r.dirname(e),this.parse()}return t.prototype.parse=function(){var t=this,n=!1,o=process.argv[2];o!==this.allowedOptions[0][0]&&o!==this.allowedOptions[0][1]||(n=!0,this.printUsage());var i=e(r.join(this.rootPath,"package.json"));if(o!==this.allowedOptions[1][0]&&o!==this.allowedOptions[1][1]||(n=!0,console.log("\n"+i.version+"\n")),!n)for(var a=this.allowedCommands.length,u=0;u