fa-toolkit
Version:
a devtool for fast app
1 lines • 11.2 kB
JavaScript
"use strict";function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.aaptExecutor=aaptExecutor,exports.add=add,exports.crunch=crunch,exports.dump=dump,exports.getApkInfo=getApkInfo,exports.list=list,exports.packageCmd=packageCmd,exports.remove=remove,exports.singleCrunch=singleCrunch;var _path=_interopRequireDefault(require("path")),_fs=_interopRequireDefault(require("fs")),_util=_interopRequireDefault(require("util")),_child_process=require("child_process");function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _regeneratorRuntime(){_regeneratorRuntime=function(){return i};var i={},t=Object.prototype,c=t.hasOwnProperty,s=Object.defineProperty||function(t,r,e){t[r]=e.value},r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",e=r.asyncIterator||"@@asyncIterator",o=r.toStringTag||"@@toStringTag";function a(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{a({},"")}catch(t){a=function(t,r,e){return t[r]=e}}function u(t,r,e,n){var o,a,i,u,r=r&&r.prototype instanceof p?r:p,r=Object.create(r.prototype),n=new x(n||[]);return s(r,"_invoke",{value:(o=t,a=e,i=n,u="suspendedStart",function(t,r){if("executing"===u)throw new Error("Generator is already running");if("completed"===u){if("throw"===t)throw r;return E()}for(i.method=t,i.arg=r;;){var e=i.delegate;if(e){var n=function t(r,e){var n=e.method,o=r.iterator[n];if(void 0===o)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=void 0,t(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),f;o=l(o,r.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,f;var o=o.arg;return o?o.done?(e[r.resultName]=o.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}(e,i);if(n){if(n===f)continue;return n}}if("next"===i.method)i.sent=i._sent=i.arg;else if("throw"===i.method){if("suspendedStart"===u)throw u="completed",i.arg;i.dispatchException(i.arg)}else"return"===i.method&&i.abrupt("return",i.arg);u="executing";n=l(o,a,i);if("normal"===n.type){if(u=i.done?"completed":"suspendedYield",n.arg===f)continue;return{value:n.arg,done:i.done}}"throw"===n.type&&(u="completed",i.method="throw",i.arg=n.arg)}})}),r}function l(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}i.wrap=u;var f={};function p(){}function h(){}function y(){}var d={};a(d,n,function(){return this});r=Object.getPrototypeOf,r=r&&r(r(b([])));r&&r!==t&&c.call(r,n)&&(d=r);var m=y.prototype=p.prototype=Object.create(d);function v(t){["next","throw","return"].forEach(function(r){a(t,r,function(t){return this._invoke(r,t)})})}function g(i,u){var r;s(this,"_invoke",{value:function(e,n){function t(){return new u(function(t,r){!function r(t,e,n,o){t=l(i[t],i,e);if("throw"!==t.type){var a=t.arg,e=a.value;return e&&"object"==_typeof(e)&&c.call(e,"__await")?u.resolve(e.__await).then(function(t){r("next",t,n,o)},function(t){r("throw",t,n,o)}):u.resolve(e).then(function(t){a.value=t,n(a)},function(t){return r("throw",t,n,o)})}o(t.arg)}(e,n,t,r)})}return r=r?r.then(t,t):t()}})}function _(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function w(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function x(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(_,this),this.reset(!0)}function b(r){if(r){var t=r[n];if(t)return t.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var e=-1,t=function t(){for(;++e<r.length;)if(c.call(r,e))return t.value=r[e],t.done=!1,t;return t.value=void 0,t.done=!0,t};return t.next=t}}return{next:E}}function E(){return{value:void 0,done:!0}}return s(m,"constructor",{value:h.prototype=y,configurable:!0}),s(y,"constructor",{value:h,configurable:!0}),h.displayName=a(y,o,"GeneratorFunction"),i.isGeneratorFunction=function(t){t="function"==typeof t&&t.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))},i.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,y):(t.__proto__=y,a(t,o,"GeneratorFunction")),t.prototype=Object.create(m),t},i.awrap=function(t){return{__await:t}},v(g.prototype),a(g.prototype,e,function(){return this}),i.AsyncIterator=g,i.async=function(t,r,e,n,o){void 0===o&&(o=Promise);var a=new g(u(t,r,e,n),o);return i.isGeneratorFunction(r)?a:a.next().then(function(t){return t.done?t.value:a.next()})},v(m),a(m,o,"Generator"),a(m,n,function(){return this}),a(m,"toString",function(){return"[object Generator]"}),i.keys=function(t){var r,e=Object(t),n=[];for(r in e)n.push(r);return n.reverse(),function t(){for(;n.length;){var r=n.pop();if(r in e)return t.value=r,t.done=!1,t}return t.done=!0,t}},i.values=b,x.prototype={constructor:x,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(w),!t)for(var r in this)"t"===r.charAt(0)&&c.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var n=this;function t(t,r){return a.type="throw",a.arg=e,n.next=t,r&&(n.method="next",n.arg=void 0),!!r}for(var r=this.tryEntries.length-1;0<=r;--r){var o=this.tryEntries[r],a=o.completion;if("root"===o.tryLoc)return t("end");if(o.tryLoc<=this.prev){var i=c.call(o,"catchLoc"),u=c.call(o,"finallyLoc");if(i&&u){if(this.prev<o.catchLoc)return t(o.catchLoc,!0);if(this.prev<o.finallyLoc)return t(o.finallyLoc)}else if(i){if(this.prev<o.catchLoc)return t(o.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return t(o.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;0<=e;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&c.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}var a=(o=o&&("break"===t||"continue"===t)&&o.tryLoc<=r&&r<=o.finallyLoc?null:o)?o.completion:{};return a.type=t,a.arg=r,o?(this.method="next",this.next=o.finallyLoc,f):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),f},finish:function(t){for(var r=this.tryEntries.length-1;0<=r;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),w(e),f}},catch:function(t){for(var r=this.tryEntries.length-1;0<=r;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n,o=e.completion;return"throw"===o.type&&(n=o.arg,w(e)),n}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,e){return this.delegate={iterator:b(t),resultName:r,nextLoc:e},"next"===this.method&&(this.arg=void 0),f}},i}function _toConsumableArray(t){return _arrayWithoutHoles(t)||_iterableToArray(t)||_unsupportedIterableToArray(t)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(t,r){if(t){if("string"==typeof t)return _arrayLikeToArray(t,r);var e=Object.prototype.toString.call(t).slice(8,-1);return"Map"===(e="Object"===e&&t.constructor?t.constructor.name:e)||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?_arrayLikeToArray(t,r):void 0}}function _iterableToArray(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}function _arrayWithoutHoles(t){if(Array.isArray(t))return _arrayLikeToArray(t)}function _arrayLikeToArray(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}function asyncGeneratorStep(t,r,e,n,o,a,i){try{var u=t[a](i),c=u.value}catch(t){return void e(t)}u.done?r(c):Promise.resolve(c).then(n,o)}function _asyncToGenerator(u){return function(){var t=this,i=arguments;return new Promise(function(r,e){var n=u.apply(t,i);function o(t){asyncGeneratorStep(n,r,e,o,a,"next",t)}function a(t){asyncGeneratorStep(n,r,e,o,a,"throw",t)}o(void 0)})}}var execFileAsync=_util.default.promisify(_child_process.execFile),REGEXP_DUMP_INFO=/name='([^']+)'[\s]*versionCode='(\d+)'[\s]*versionName='([^']+)/,REGEXP_DUMP_INFO_NAME=/application: label='([^']+)'[\s]*icon='([^']+)/,aaptBinPath=_path.default.resolve(__dirname,"bin",process.arch,process.platform,"aapt");function aaptExecutor(t){return _aaptExecutor.apply(this,arguments)}function _aaptExecutor(){return(_aaptExecutor=_asyncToGenerator(_regeneratorRuntime().mark(function t(r){var e,n=arguments;return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e=1<n.length&&void 0!==n[1]?n[1]:2048e3,t.next=3,execFileAsync(aaptBinPath,r,{maxBuffer:e});case 3:return e=t.sent,t.abrupt("return",e);case 5:case"end":return t.stop()}},t)}))).apply(this,arguments)}function list(t){return aaptExecutor(["l"].concat(_toConsumableArray(1<arguments.length&&void 0!==arguments[1]?arguments[1]:[]),[t]))}function dump(t,r){return aaptExecutor(["d",r,t])}function packageCmd(t,r){return aaptExecutor(["p",r,t])}function remove(t,r){if(!Array.isArray(r))throw new Error("args files must be Array!");return aaptExecutor(["r",t].concat(_toConsumableArray(r)))}function add(t,r){if(!Array.isArray(r))throw new Error("args files must be Array!");return aaptExecutor(["a",t].concat(_toConsumableArray(r)))}function crunch(t,r){if(!Array.isArray(t))throw new Error("args files must be Array!");return aaptExecutor(["c","-S"].concat(_toConsumableArray(t),["-C",r]))}function singleCrunch(t,r){return aaptExecutor(["s","-i",t,"-o",r])}function getApkInfo(t){return _getApkInfo.apply(this,arguments)}function _getApkInfo(){return(_getApkInfo=_asyncToGenerator(_regeneratorRuntime().mark(function t(r){var e,n;return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(_fs.default.existsSync(r)){t.next=2;break}throw new Error("Parsing the APK, the file does not exist:"+r);case 2:return t.next=4,dump(r,"badging");case 4:if(n=t.sent,e=n.stdout,n=e.match(REGEXP_DUMP_INFO),e=e.match(REGEXP_DUMP_INFO_NAME),(n={package:n[1],name:e[1],icon:e[2],version:n[3]}).name||console.warn("apk name get error! please use : aapt d xmltree..."),n.version&&n.package){t.next=12;break}throw new Error("Invalid Apk File.");case 12:return t.abrupt("return",n);case 13:case"end":return t.stop()}},t)}))).apply(this,arguments)}"win32"===process.platform?aaptBinPath+=".exe":_fs.default.chmodSync(aaptBinPath,"755"),_fs.default.accessSync(aaptBinPath,_fs.default.constants.F_OK);