Files
jibo-cli/lib/jibo-cli.js

10 lines
39 KiB
JavaScript
Raw Permalink Normal View History

/**
* jibo-cli - Command line interface, templates, simulator
* @version v3.0.7
* @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(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.jiboCli=t()}}(function(){return function t(e,o,n){function r(s,a){if(!o[s]){if(!e[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(i)return i(s,!0);var l=new Error("Cannot find module '"+s+"'");throw l.code="MODULE_NOT_FOUND",l}var c=o[s]={exports:{}};e[s][0].call(c.exports,function(t){var o=e[s][1][t];return r(o?o:t)},c,c.exports,t,e,o,n)}return o[s].exports}for(var i="function"==typeof require&&require,s=0;s<n.length;s++)r(n[s]);return r}({1:[function(t,e,o){"use strict";var n=t("commander"),r=t("../jibo-tools"),i=t("colors"),s=function(){function t(){this.tools=r.default,this.program=n,this.parse(),this.exec()}return t.prototype.parse=function(){this.program.parse(process.argv)},t.prototype.exec=function(){throw new Error("Invalid command setup")},t.prototype.fetchRobot=function(t,e){var o=this;this.tools.robots.getInfo(t,function(t,n){return t?o.error(t):void e(n)})},t.prototype.error=function(t){this.red(t),process.exit(1)},t.prototype.warn=function(t){console.log(i.yellow("\n"+t+"\n"))},t.prototype.success=function(t){t&&this.green(t),process.exit()},t.prototype.green=function(t){console.log(i.green("\n"+t+"\n"))},t.prototype.red=function(t){console.log(i.red("\n"+t+"\n"))},t.prototype.isRobotReachable=function(t,e,o){var n=this;this.getRobotInfo(t,function(t){e&&n.green(e.replace("%s",t.name)),n.tools.networks.isRobotReachable(t,function(e,r){return e?n.error(e):void(r===!1?n.error("Could not connect to "+t.name+". Make sure the robot is turned on."):o(t))})})},t.prototype.getRobotInfo=function(t,e){var o=this;"undefined"==typeof t?this.tools.robots.getDefault(function(t,n){return t?o.error(t):null===n?o.error(new Error("No default robot was set. Call 'jibo set-default-robot <robotName>' to set a default.")):void o.fetchRobot(n,e)}):this.fetchRobot(t,e)},t}();Object.defineProperty(o,"__esModule",{value:!0}),o.default=s},{"../jibo-tools":25,colors:void 0,commander:void 0}],2:[function(t,e,o){"use strict";var n=this&&this.__extends||function(t,e){function o(){this.constructor=t}for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)},r=t("../command"),i=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.exec=function(){var t=this;this.tools.robots.add(process.argv[2],process.argv[3],function(e){return e?t.error(e):void t.success(process.argv[2]+" success added.")})},e}(r.default);Object.defineProperty(o,"__esModule",{value:!0}),o.default=i},{"../command":1}],3:[function(t,e,o){"use strict";var n=this&&this.__extends||function(t,e){function o(){this.constructor=t}for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)},r=t("../command"),i=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.exec=function(){var t=this;this.isRobotReachable(process.argv[2],"Fetching the buildroot version of %s.",function(e){t.tools.buildVersion(e,function(e,o){return e?t.error(e):void t.success(o)})})},e}(r.default);Object.defineProperty(o,"__esModule",{value:!0}),o.default=i},{"../command":1}],4:[function(t,e,o){"use strict";var n=this&&this.__extends||function(t,e){function o(){this.constructor=t}for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)},r=t("../command"),i=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.exec=function(){var t=this;this.isRobotReachable(this.program.robot,null,function(e){t.tools.debug(e,null,function(e){return t.warn(e)})})},e}(r.default);Object.defineProperty(o,"__esModule",{value:!0}),o.default=i},{"../command":1}],5:[function(t,e,o){"use strict";var n=this&&this.__extends||function(t,e){functi
};g(t,A,n,o)}function v(t,e,o){var n={filter:e};g(t,I,n,o)}function m(t,e,o){var n={ids:e};g(t,C,n,function(t,e){return t||"failed"===e.status||e.error?o(t||e.reason||e.error):void o(null,e)})}function b(t){return"ws://"+t+":"+O+"/download-update"}function y(t,e,o){var n={ids:e};g(t,L,n,function(t,e){return t||"failed"===e.status||e.error?o(t||e.reason||e.error):void o(null,e)})}function g(t,e,o,n){var r=o?o:{};try{r=JSON.stringify(r)}catch(t){return void n("Attempting to send invalid data to dev shell. Request is not valid JSON",null)}var i={hostname:t,port:O,path:e,method:"POST",headers:{"Content-Type":"application/json"}},s=_.request(i,function(t){var e="";t.on("data",function(t){e+=t}),t.on("end",function(){var t=void 0;try{t=JSON.parse(e)}catch(t){return void n("Invalid request to dev shell. Request body is not valid JSON: "+e,null)}"ERROR"===t.Status?n(t.Message,null):n(null,t.Message)})});s.on("error",function(){n("Dev shell is not available on "+t,null)}),s.write(r),s.end()}var _=t("http"),w=t("jibo-sync"),O=8686,k=8989,j="/sync-skill",P="/run",x="/stop",S="/diskspace",R="/reboot",E="/poweroff",N="/version",D="/index",M="/setvolume",T="/getvolume",A="/delete-skill",I="/check-update",C="/download-update",L="/install-update";o.syncSkill=n,o.stopSync=r,o.runSkill=i,o.stopSkill=s,o.getBuildVersion=a,o.getVolume=u,o.setVolume=l,o.getDiskSpace=c,o.rebootRobot=d,o.powerOffRobot=p,o.indexRobot=f,o.deleteSkill=h,o.checkForUpdates=v,o.downloadUpdates=m,o.getOTASocketUrl=b,o.installUpdates=y},{http:void 0,"jibo-sync":void 0}],33:[function(t,e,o){"use strict";function n(t,e){r.getDiskSpace(t.ip,function(t,o){e(t,o)})}var r=t("./dev-shell");Object.defineProperty(o,"__esModule",{value:!0}),o.default=n},{"./dev-shell":32}],34:[function(t,e,o){"use strict";function n(t,e){r.indexRobot(t.ip,function(t,o){e(t,o)})}var r=t("./dev-shell");Object.defineProperty(o,"__esModule",{value:!0}),o.default=n},{"./dev-shell":32}],35:[function(t,e,o){"use strict";var n=t("child_process"),r={isRobotReachable:function(t,e){var o=!1,r="-t 10";"win32"===process.platform&&(r="-4");var i=n.spawn("ping",[r,t.ip],["pipe"]),s="";i.on("close",function(){o||(i.kill("SIGKILL"),e(null,!1),o=!0)}),i.on("exit",function(){o||(i.kill("SIGKILL"),e(null,!1),o=!0)}),i.stderr.on("data",function(t){if(s+=t.toString(),s.search("No route to host")!==-1||s.search("Host is down")!==-1)return void(o||(i.kill("SIGKILL"),e(null,!1),o=!0))});var a="";i.stdout.on("data",function(t){a+=t.toString();var n="bytes from";if("win32"===process.platform&&(n="bytes="),a.search(n)!==-1)return void(o||(i.kill("SIGKILL"),e(null,!0),o=!0))})}};Object.defineProperty(o,"__esModule",{value:!0}),o.default=r},{child_process:void 0}],36:[function(t,e,o){"use strict";function n(t,e){r.powerOffRobot(t.ip,function(t,o){e(t,o)})}var r=t("./dev-shell");Object.defineProperty(o,"__esModule",{value:!0}),o.default=n},{"./dev-shell":32}],37:[function(t,e,o){"use strict";function n(t,e){r.rebootRobot(t.ip,function(t,o){e(t,o)})}var r=t("./dev-shell");Object.defineProperty(o,"__esModule",{value:!0}),o.default=n},{"./dev-shell":32}],38:[function(t,e,o){"use strict";function n(t){var e=new i.default;e.load(function(o){return o?void t(o):void t(null,e)})}function r(t){return!!t}var i=t("./config"),s=t("lodash"),a={list:function(t){n(function(e,o){if(e)return void t(e);var n=o.get("robots");return Array.isArray(n)?void t(null,n):void t(null,[])})},add:function(t,e,o){n(function(n,i){if(n)return void o(n);if(!t||0===t.length)return void o(new Error("Robot's name must be at least one character long"));if(r(e)===!1)return void o(new Error("IP address is not a valid ("+e+")"));var a=i.get("robots");return"undefined"!=typeof a&&Array.isArray(a)!==!1||(a=[]),s.findIndex(a,function(e){return e.name===t})!==-1?void o(new Error("A robot with the name "+t+" already exists. Delete it first if you want to update it's information ")):(a.push({name:t,ip:e}),a.sort(function(t,e){return t>e}),i.set("robots",a),i.set("defaultRobot",t),void i.save(function(t){o(t)}))})},remove:function(t,e){console.log(""),n(function(o,n){if(