1 line
2.1 KiB
JavaScript
1 line
2.1 KiB
JavaScript
"use strict";var e=function(e){return e&&e.__esModule?e["default"]:e},t=function(){function e(e,t){for(var r in t){var n=t[r];n.configurable=!0,n.value&&(n.writable=!0)}Object.defineProperties(e,t)}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),r=function g(e,t,r){var n=Object.getOwnPropertyDescriptor(e,t);if(void 0===n){var o=Object.getPrototypeOf(e);return null===o?void 0:g(o,t,r)}if("value"in n&&n.writable)return n.value;var i=n.get;if(void 0!==i)return i.call(r)},n=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(e.__proto__=t)},o=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},i=e(require("fs")),u=e(require("path")),s=require("events").EventEmitter,a=e(require("ensureDir")),l=e(require("osenv")),f=u.resolve(l.home(),".jibo/cli.json"),c=function(e){function s(){o(this,s),r(Object.getPrototypeOf(s.prototype),"constructor",this).call(this),this.settings={}}return n(s,e),t(s,{load:{value:function(e){var t=this;i.readFile(f,function(r,n){if(r)return t.settings={},void e(null);try{var o=JSON.parse(n);t.settings=o}catch(i){console.log("parse error"),console.log(i),e(i)}e(null)})}},save:{value:function(e){var t=this;a(u.dirname(f),null,function(){i.writeFile(f,JSON.stringify(t.settings,null," "),function(t){e(t)})})}},get:{value:function(){if(0===arguments.length)return this.settings;for(var e=this.settings,t=0;t<arguments.length;t++){if("undefined"==typeof e[arguments[t]])return;e=e[arguments[t]]}return e}},set:{value:function(e){if(0===arguments.length)throw new Error("No value was provided to Config.set()");1===arguments.length&&(this.settings=e);for(var t=this.settings,r=0;r<arguments.length-2;r++)console.log("path "+arguments[r]),("undefined"==typeof t[arguments[r]]||Array.isArray(t[arguments[r]]))&&(t[arguments[r]]={}),t=t[arguments[r]];t[arguments[arguments.length-2]]=arguments[arguments.length-1]}}}),s}(s);module.exports=c; |