16 lines
31 KiB
JavaScript
16 lines
31 KiB
JavaScript
|
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("fs"),e=require("path"),n=require("debug"),s=require("merge"),o=require("jsonc-parser"),i=require("licia/isRelative"),r=require("ws"),a=require("events"),c=require("licia/uuid"),p=require("licia/stringify"),l=require("licia/dateFormat"),u=require("licia/waitUntil"),h=require("licia/fs"),d=require("licia/isFn"),m=require("licia/trim"),g=require("licia/isStr"),y=require("licia/startWith"),f=require("licia/isNum"),v=require("licia/sleep"),w=require("licia/isUndef"),P=require("address"),M=require("default-gateway"),k=require("licia/getPort"),E=require("qrcode-terminal"),I=require("child_process"),b=require("licia/toStr");function C(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var A=C(t),S=C(e),T=C(n),D=C(i),N=C(r),U=C(c),_=C(p),R=C(l),O=C(u),j=C(h),x=C(d),$=C(m),q=C(g),L=C(y),F=C(f),W=C(v),B=C(w),H=C(P),X=C(M),J=C(k),V=C(E),G=C(b);class z extends a.EventEmitter{constructor(t){super(),this.ws=t,this.ws.addEventListener("message",(t=>{this.emit("message",t.data)})),this.ws.addEventListener("close",(()=>{this.emit("close")}))}send(t){this.ws.send(t)}close(){this.ws.close()}}const K=new Map,Y=["onCompassChange","onThemeChange","onUserCaptureScreen","onWindowResize","onMemoryWarning","onAccelerometerChange","onKeyboardHeightChange","onNetworkStatusChange","onPushMessage","onLocationChange","onGetWifiList","onWifiConnected","onWifiConnectedWithPartialInfo","onSocketOpen","onSocketError","onSocketMessage","onSocketClose"];const Q=new Map;function Z(t,e){(null==t?void 0:t.success)&&"function"==typeof(null==t?void 0:t.success)&&(e?t.success(e):t.success()),(null==t?void 0:t.complete)&&"function"==typeof(null==t?void 0:t.complete)&&(e?t.complete(e):t.complete())}function tt(t,e){(null==t?void 0:t.fail)&&"function"==typeof(null==t?void 0:t.fail)&&(e?t.fail(e):t.fail()),(null==t?void 0:t.complete)&&"function"==typeof(null==t?void 0:t.complete)&&(e?t.complete(e):t.complete())}const et="Connection closed";class nt extends a.EventEmitter{constructor(t,e,n){super(),this.puppet=e,this.namespace=n,this.callbacks=new Map,this.transport=t,this.debug=T.default("automator:protocol:"+this.namespace),this.onMessage=t=>{var e,n;this.debug(`${R.default("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${t}`);const{id:s,method:o,error:i,result:r,params:a}=JSON.parse(t);if(null===(e=null==r?void 0:r.method)||void 0===e?void 0:e.startsWith("on"))return void((t,e)=>{const n=K.get(t.method);(null==n?void 0:n.has(e))&&n.get(e)(t.data)})(r,s);if(null===(n=null==r?void 0:r.method)||void 0===n?void 0:n.startsWith("Socket.")){return void((t,e,n)=>{const s=Q.get(e);(null==s?void 0:s.has(t))&&s.get(t)(n)})(r.method.replace("Socket.",""),r.id,r.data)}if(!s)return this.puppet.emit(o,a);const{callbacks:c}=this;if(s&&c.has(s)){const t=c.get(s);c.delete(s),i?t.reject(Error(i.message||i.detailMessage||i.errMsg)):t.resolve(r)}},this.onClose=()=>{this.callbacks.forEach((t=>{t.reject(Error(et))}))},this.transport.on("message",this.onMessage),this.transport.on("close",this.onClose)}send(t,e={},n=!0){if(n&&this.puppet.adapter.has(t))return this.puppet.adapter.send(this,t,e);const s=U.default(),o=_.default({id:s,method:t,params:e});return this.debug(`${R.default("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${o}`),new Promise(((t,e)=>{try{this.transport.send(o)}catch(t){e(Error(et))}this.callbacks.set(s,{resolve:t,reject:e})}))}dispose(){this.transport.close()}static createDevtoolConnection(t,e){return new Promise(((n,s)=>{const o=new N.default(t);o.addEventListener("open",(()=>{n(new nt(new z(o),e,"devtool"))})),o.addEventListener("error",s)}))}static createRuntimeConnection(t,e,n){return new Promise(((s,o)=>{T.default("automator:runtime")(`${R.default("yyyy-mm-dd HH:MM:ss:l")} port=${t}`);const i=new N.default.Server({port:t});O.default((async()=>{if(e.runtimeConnection)return!0}),n,1e3).catch((()=>{i.close(),o("Failed to connect to runtime, please make sure the project is running")})),i.on("connection",(function(t){T.default("automator:runtime")(`${R.default("yyyy-mm-dd HH:MM:ss:l")} connected`);con
|
||
|
/*! *****************************************************************************
|
||
|
Copyright (c) Microsoft Corporation.
|
||
|
|
||
|
Permission to use, copy, modify, and/or distribute this software for any
|
||
|
purpose with or without fee is hereby granted.
|
||
|
|
||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||
|
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||
|
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||
|
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||
|
PERFORMANCE OF THIS SOFTWARE.
|
||
|
***************************************************************************** */function it(t,e,n,s){var o,i=arguments.length,r=i<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,n):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,n,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(i<3?o(r):i>3?o(e,n,r):o(e,n))||r);return i>3&&r&&Object.defineProperty(e,n,r),r}var rt;function at(t,e){const n=e.value;return e.value=async function(e){return(await(null==n?void 0:n.call(this,e)))(t)},e}function ct(t,e,n){return at(rt.RUNTIME,n)}function pt(t,e,n){return at(rt.DEVTOOL,n)}/^win/.test(process.platform),function(t){t.RUNTIME="runtime",t.DEVTOOL="devtool"}(rt||(rt={}));class lt{constructor(t){this.puppet=t}invoke(t,e){return async n=>this.puppet.devtoolConnection?(n===rt.DEVTOOL?this.puppet.devtoolConnection:this.puppet.runtimeConnection).send(t,e):this.puppet.runtimeConnection.send(t,e)}on(t,e){this.puppet.on(t,e)}}class ut extends lt{constructor(t,e){super(t),this.id=e.elementId,this.pageId=e.pageId,this.nodeId=e.nodeId,this.videoId=e.videoId}async getData(t){return this.invokeMethod("Element.getData",t)}async setData(t){return this.invokeMethod("Element.setData",t)}async callMethod(t){return this.invokeMethod("Element.callMethod",t)}async getElement(t){return this.invokeMethod("Element.getElement",t)}async getElements(t){return this.invokeMethod("Element.getElements",t)}async getOffset(){return this.invokeMethod("Element.getOffset")}async getHTML(t){return this.invokeMethod("Element.getHTML",t)}async getAttributes(t){return this.invokeMethod("Element.getAttributes",t)}async getStyles(t){return this.invokeMethod("Element.getStyles",t)}async getDOMProperties(t){return this.invokeMethod("Element.getDOMProperties",t)}async getProperties(t){return this.invokeMethod("Element.getProperties",t)}async tap(){return this.invokeMethod("Element.tap")}async longpress(){return this.invokeMethod("Element.longpress")}async touchstart(t){return this.invokeMethod("Element.touchstart",t)}async touchmove(t){return this.invokeMethod("Element.touchmove",t)}async touchend(t){return this.invokeMethod("Element.touchend",t)}async triggerEvent(t){return this.invokeMethod("Element.triggerEvent",t)}async callFunction(t){return this.invokeMethod("Element.callFunction",t)}async callContextMethod(t){return this.invokeMethod("Element.callContextMethod",t)}invokeMethod(t,e={}){return e.elementId=this.id,e.pageId=this.pageId,this.nodeId&&(e.nodeId=this.nodeId),this.videoId&&(e.videoId=this.videoId),this.invoke(t,e)}}it([ct],ut.prototype,"getData",null),it([ct],ut.prototype,"setData",null),it([ct],ut.prototype,"callMethod",null),it([pt],ut.prototype,"getElement",null),it([pt],ut.prototype,"getElements",null),it([pt],ut.prototype,"getOffset",null),it([pt],ut.prototype,"getHTML",null),it([pt],ut.prototype,"getAttributes",null),it([pt],ut.prototype,"getStyles",null),it([pt],ut.prototype,"getDOMProperties",null),it([pt],ut.prototype,"getProperties",null),it([pt],ut.prototype,"tap",null),it([pt],ut.prototype,"longpress",null),it([pt],ut.prototype,"touchstart",null),it([pt],ut.prototype,"touchmove",null),it([pt],ut.prototype,"touchend",null),it([pt],ut.prototype,"triggerEvent",null),it([pt],ut.prototype,"callFunction",null),it([pt],ut.prototype,"callContextMethod",null);const ht=Object.prototype.hasOwnProperty,dt=Array.isArray,mt=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;function gt(t,e){if(dt(t))return t;if(e&&(n=e,s=t,ht.call(n,s)))return[t];var n,s;const o=[];return t.replace(mt,(function(t,e,n,s){return o.push(n?s.replace(/\\(\\)?/g,"$1"):e||t),s})),o}function yt(t,e){const n=gt(e,t);let s;for(s=n.shift();null!=s;){if(null==(t=t[s]))return;s=n.shift()}return t}const ft=require("util");class vt{constructor(t,e,n){this.puppet=t,this.id=e.elementId,this.pageId=e.pageId,this.nodeId=e.nodeId||null,this.videoId=e.videoId||null,this.tagName=e.tagName,this.nvue=e.nvue,this.elementMap=n,"body"!==this.tagName&&"page-body"!==this.tagName||(this.tagName="page"),this.api=new ut(
|