function__spreadArrays(){for(vars=0,i=0,il=arguments.length;i<il;i++)s+=arguments[i].length;varr=Array(s),k=0;for(i=0;i<il;i++)for(vara=arguments[i],j=0,jl=a.length;j<jl;j++,k++)r[k]=a[j];returnr}vargetRandomValues="undefined"!=typeofcrypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeofmsCrypto&&"function"==typeofmsCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto),rnds8=newUint8Array(16);functionrng(){if(!getRandomValues)thrownewError("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");returngetRandomValues(rnds8)}for(varbyteToHex=[],i=0;i<256;++i)byteToHex[i]=(i+256).toString(16).substr(1);functionv4(options,buf,offset){vari=buf&&offset||0;"string"==typeofoptions&&(buf="binary"===options?newArray(16):null,options=null);varrnds=(options=options||{}).random||(options.rng||rng)();if(rnds[6]=15&rnds[6]|64,rnds[8]=63&rnds[8]|128,buf)for(varii=0;ii<16;++ii)buf[i+ii]=rnds[ii];returnbuf||function(buf,offset){vari=offset||0,bth=byteToHex;return[bth[buf[i++]],bth[buf[i++]],bth[buf[i++]],bth[buf[i++]],"-",bth[buf[i++]],bth[buf[i++]],"-",bth[buf[i++]],bth[buf[i++]],"-",bth[buf[i++]],bth[buf[i++]],"-",bth[buf[i++]],bth[buf[i++]],bth[buf[i++]],bth[buf[i++]],bth[buf[i++]],bth[buf[i++]]].join("")}(rnds)}varhasOwnProperty=Object.prototype.hasOwnProperty,isArray=Array.isArray,PATH_RE=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;functiongetPaths(path,data){if(isArray(path))returnpath;if(data&&(val=data,key=path,hasOwnProperty.call(val,key)))return[path];varval,key,res=[];returnpath.replace(PATH_RE,(function(match,p1,offset,string){returnres.push(offset?string.replace(/\\(\\)?/g,"$1"):p1||match),string})),res}functiongetDataByPath(data,path){vardataPath,paths=getPaths(path,data);for(dataPath=paths.shift();null!=dataPath;){if(null==(data=data[dataPath]))return;dataPath=paths.shift()}returndata}varelementMap=newMap;functiontransEl(el){if(!function(el){if(el){vartagName=el.tagName;return0===tagName.indexOf("UNI-")||"BODY"===tagName}return!1}(el))throwError("no such element");varelement,elementId,elem={elementId:(element=el,elementId=element._id,elementId||(elementId=v4(),element._id=elementId,elementMap.set(elementId,{id:elementId,element:element})),elementId),tagName:el.tagName.toLocaleLowerCase().replace("uni-","")},vm=el.__vue__;returnvm&&(vm.$parent&&vm.$parent.$el===el&&(vm=vm.$parent),vm&&!vm.$options.isReserved&&(elem.nodeId=function(vm){if(vm._$weex)returnvm._uid;if(vm._$id)returnvm._$id;varparent_1=function(vm){for(varparent=vm.$parent;parent;){if(parent._$id)returnparent;parent=parent.$parent}}(vm);if(!vm.$parent)return"-1";varvnode=vm.$vnode,context=vnode.context;returncontext&&context!==parent_1&&context._$id?context._$id+";"+parent_1._$id+","+vnode.data.attrs._i:parent_1._$id+","+vnode.data.attrs._i}(vm))),"video"===elem.tagName&&(elem.videoId=elem.nodeId),elem}varFUNCTIONS={input:{input:function(el,value){varvm=el.__vue__;vm.valueSync=value,vm.$triggerInput({},{value:value})}},textarea:{input:function(el,value){varvm=el.__vue__;vm.valueSync=value,vm.$triggerInput({},{value:value})}},"scroll-view":{scrollTo:function(el,x,y){varmain=el.__vue__.$refs.main;main.scrollLeft=x,main.scrollTop=y},scrollTop:function(el){returnel.__vue__.$refs.main.scrollTop},scrollLeft:function(el){returnel.__vue__.$refs.main.scrollLeft},scrollWidth:function(el){returnel.__vue__.$refs.main.scrollWidth},scrollHeight:function(el){returnel.__vue__.$refs.main.scrollHeight}},swiper:{swipeTo:function(el,index){el.__vue__.current=index}},"movable-view":{moveTo:function(el,x,y){el.__vue__._animationTo(x,y)}},switch:{tap:function(el){el.click()}},slider:{slideTo:function(el,value){varvm=el.__vue__,slider=vm.$refs["uni-slider"],offsetWidth=slider.offsetWidth,boxLeft=slider.getBoundingClientRect().left;vm.value=value,vm._onClick({x:(value-vm.min)*offsetWidth/(vm.max-vm.min)+boxLeft})}}};functioncreateTouchList(touchInits){var_a,touches=touchInits.map((function(touch){returnfunction(touch){if(document.createTouch)returndocument.createTouch(window,touch.target,touch.identifier,touch.pageX,touch.pageY,touch.screenX,touch.screenY);returnnewTouch(touch)}(touch)}));returndocument.createTouchList?(_a=document).createTouchList.apply(_a,touches):touches}varWebAdapter={getWindow:function(pageId){returnwindow},getDocument:function(pageId){returndocument},getEl:function(elementId){varelement=elementMap.get(elementId);if(!element)throwError("element destroyed");returnelement.element},getOffset:function(node){varrect=node.getBoundingClientRect();returnPromise.resolve({left:rect.left+window.pageXOffset,top:rect.top+window.pageYOffset})},querySelector:function(context,selector){return"page"===selector&&(selector="body"),Promise.resolve(transEl(context.querySelector(selector)))},querySelectorAll:function(context,selector){varelements=[],nodeList=document.querySelectorAll(selector);return[].forEach.call(nodeList,(function(node){try{elements.push(transEl(node))}catch(e){}})),Promise.resolve({elements:elements})},queryProperties:function(context,names){returnPromise.resolve({properties:names.map((function(name){varvalue=getDataByPath(context,name);return"document.documentElement.scrollTop"===name&&0===value&&(value=getDataByPath(context,"document.body.scrollTop")),value}))})},queryAttributes:function(context,names){returnPromise.resolve({attributes:names.map((function(name){returnString(context.getAttribute(name))}))})},queryStyles:function(context,names){varstyle=getComputedStyle(context);returnPromise.resolve({styles:names.map((function(name){returnstyle[name]}))})},queryHTML:function(context,type){returnPromise.resolve({html:(html="outer"===type?context.outerHTML:context.innerHTML,html.replace(/\n/g,"").replace(/(<uni-text[^>]*>)(<span[^>]*>[^<]*<\/span>)(.*?<\/uni-text>)/g,"$1$3").replace(/<\/?[^>]*>/g,(function(replacement){return-1<replacement.indexOf("<body")?"<page>":"</body>"===replacement?"</page>":0!==replacement.indexOf("<uni-")&&0!==replacement.indexOf("</uni-")?"":replacement.replace(/uni-/g,"").replace(/ role=""/g,"").replace(/ aria-label=""/g,"")})))});varhtml},dispatchTapEvent:function(el){returnel.click(),Promise.resolve()},dispatchLongpressEvent:function(el){returnPromise.resolve()},dispatchTouchEvent:function(el,type,eventInitDict){eventInitDict||(eventInitDict={}),eventInitDict.touches||(eventInitDict.touches=[]),eventInitDict.changedTouches||(eventInitDict.changedTouches=[]),eventInitDict.touches.length||eventInitDict.touches.push({identifier:Date.now(),target:el});vartouches=createTouchList(eventInitDict.touches),changedTouches=createTouchList(eventInitDict.changedTouches),targetTouches=createTouchList([]);returnel.dispatchEvent(newTouchEvent(type,{cancelable:!0,bubbles:!0,touches:touches,targetTouches:targetTouches,changedTouches:changedTouches})),Promise.resolve()},callFunction:function(el,functionName,args){varfn=getDataByPath(FUNCTIONS,functionName);returnfn?Promise.resolve({result:fn.apply(null,__spreadArrays([el],args))}):Promise.reject(Error(functionName+" not exists"))},triggerEvent:function(el,type,detail){varvm=el.__vue__;returnvm.$trigger&&vm.$trigger(type,{},detail),Promise.resolve()}};varApi=Object.assign({},function(adapter){return{"Page.getElement":function(params){returnadapter.querySelector(adapter.getDocument(params.pageId),params.selector)},"Page.getElements":function(params){returnadapter.querySelectorAll(adapter.getDocument(params.pageId),params.selector)},"Page.getWindowProperties":function(params){returnadapter.queryProperties(adapter.getWindow(params.pageId),params.names)}}}(WebAdapter),function(adapter){vargetEl=function(params){returnadapter.getEl(params.elementId,params.pageId)};return{"Element.getElement":function(params){returnadapter.querySelector(getEl(params),params.selector)},"Element.getElements":function(params){returnadapter.querySelectorAll(getEl(params),params.selector)},"Element.getDOMProperties":function(params){returnadapter.queryProperties(getEl(params),params.names)},"Element.getProperties":function(params){varel=getEl(params),ctx=el.__vue__||el.attr||{};returnadapter.queryProperties(ctx,params.names)},"Element.getOffset":function(params){returnadapter.getOffset(getEl(params))},"Element.getAttributes":function(params){returnadapter.queryAttributes(getEl(params),params.names)},"Element.getStyles":function(params){returnadapter.queryStyles(getEl(params),params.names)},"Element.getHTML":function(params){returnadapter.queryHTML(getEl(params),params.type)},"Element.tap":function(params){returnadapter.dispatchTapEvent(getEl(params))},"Element.longpress":function(params){returnadapter.dispatchLongpressEvent(getEl(params))},"Element.touchstart":function(params){returnadapter.dispatchTouchEvent(getEl(params),"touchstart",params)},"Element.touchmove":function(params){returnadapter.dispatchTouchEvent(getEl(params),"touchmove",params)},"Element.touchend":function(params){returnadapter.dispatchTouchEvent(getEl(params),"touchend",params)},"Element.callFunction":function(params){returnadapter.callFunction(getEl(params),params.functionName,params.args)},"Element.triggerEvent":function(params){returnadapter.triggerEvent(getEl(params),params.type,params.detail)}}}(WebAdapter));functionsend(data){returnUniViewJSBridge.publishHandler("onAutoMessageReceive",data)}UniViewJSBridge.subscribe("sendAutoMessage",(function(_a){varid=_a.id,method=_a.method,params=_a.params,data={id:id},fn=Api[method];if(!fn)returndata.error={message:method+" unimplemented"},send(data);try{fn(params).then((function(res){res&&(data.result=res)})).catch((function(err){data.error={message:err.message}})).finally((function(){send(data)}))}catch(err){data.error={message:err.message},send(data)}}));
function__spreadArrays(){for(vars=0,i=0,il=arguments.length;i<il;i++)s+=arguments[i].length;varr=Array(s),k=0;for(i=0;i<il;i++)for(vara=arguments[i],j=0,jl=a.length;j<jl;j++,k++)r[k]=a[j];returnr}vargetRandomValues="undefined"!=typeofcrypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeofmsCrypto&&"function"==typeofmsCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto),rnds8=newUint8Array(16);functionrng(){if(!getRandomValues)thrownewError("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");returngetRandomValues(rnds8)}for(varbyteToHex=[],i=0;i<256;++i)byteToHex[i]=(i+256).toString(16).substr(1);functionv4(options,buf,offset){vari=buf&&offset||0;"string"==typeofoptions&&(buf="binary"===options?newArray(16):null,options=null);varrnds=(options=options||{}).random||(options.rng||rng)();if(rnds[6]=15&rnds[6]|64,rnds[8]=63&rnds[8]|128,buf)for(varii=0;ii<16;++ii)buf[i+ii]=rnds[ii];returnbuf||function(buf,offset){vari=offset||0,bth=byteToHex;return[bth[buf[i++]],bth[buf[i++]],bth[buf[i++]],bth[buf[i++]],"-",bth[buf[i++]],bth[buf[i++]],"-",bth[buf[i++]],bth[buf[i++]],"-",bth[buf[i++]],bth[buf[i++]],"-",bth[buf[i++]],bth[buf[i++]],bth[buf[i++]],bth[buf[i++]],bth[buf[i++]],bth[buf[i++]]].join("")}(rnds)}varhasOwnProperty=Object.prototype.hasOwnProperty,isArray=Array.isArray,PATH_RE=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;functiongetPaths(path,data){if(isArray(path))returnpath;if(data&&(val=data,key=path,hasOwnProperty.call(val,key)))return[path];varval,key,res=[];returnpath.replace(PATH_RE,(function(match,p1,offset,string){returnres.push(offset?string.replace(/\\(\\)?/g,"$1"):p1||match),string})),res}functiongetDataByPath(data,path){vardataPath,paths=getPaths(path,data);for(dataPath=paths.shift();null!=dataPath;){if(null==(data=data[dataPath]))return;dataPath=paths.shift()}returndata}functiongetVmNodeId(vm){if(vm._$weex)returnvm._uid;if(vm._$id)returnvm._$id;varparent_1=function(vm){for(varparent=vm.$parent;parent;){if(parent._$id)returnparent;parent=parent.$parent}}(vm);if(!vm.$parent)return"-1";varvnode=vm.$vnode,context=vnode.context;returncontext&&context!==parent_1&&context._$id?context._$id+";"+parent_1._$id+","+vnode.data.attrs._i:parent_1._$id+","+vnode.data.attrs._i}varelementMap=newMap;functiontransEl(el){var_a;if(!function(el){if(el){vartagName=el.tagName;return0===tagName.indexOf("UNI-")||"BODY"===tagName}return!1}(el))throwError("no such element");varelement,elementId,vm,elem={elementId:(element=el,elementId=element._id,elementId||(elementId=v4(),element._id=elementId,elementMap.set(elementId,{id:elementId,element:element})),elementId),tagName:el.tagName.toLocaleLowerCase().replace("uni-","")};el.__vue__?(vm=el.__vue__)&&(vm.$parent&&vm.$parent.$el===el&&(vm=vm.$parent),vm&&!(null===(_a=vm.$options)||void0===_a?void0:_a.isReserved)&&(elem.nodeId=getVmNodeId(vm))):(vm=el.__vnode)&&(vm.el===el&&(vm=vm.ctx.parent),vm&&(elem.nodeId=getVmNodeId(vm)));return"video"===elem.tagName&&(elem.videoId=elem.nodeId),elem}varFUNCTIONS={input:{input:function(el,value){varvm=el.__vue__;vm.valueSync=value,vm.$triggerInput({},{value:value})}},textarea:{input:function(el,value){varvm=el.__vue__;vm.valueSync=value,vm.$triggerInput({},{value:value})}},"scroll-view":{scrollTo:function(el,x,y){varmain=el.__vue__.$refs.main;main.scrollLeft=x,main.scrollTop=y},scrollTop:function(el){returnel.__vue__.$refs.main.scrollTop},scrollLeft:function(el){returnel.__vue__.$refs.main.scrollLeft},scrollWidth:function(el){returnel.__vue__.$refs.main.scrollWidth},scrollHeight:function(el){returnel.__vue__.$refs.main.scrollHeight}},swiper:{swipeTo:function(el,index){el.__vue__.current=index}},"movable-view":{moveTo:function(el,x,y){el.__vue__._animationTo(x,y)}},switch:{tap:function(el){el.click()}},slider:{slideTo:function(el,value){varvm=el.__vue__,slider=vm.$refs["uni-slider"],offsetWidth=slider.offsetWidth,boxLeft=slider.getBoundingClientRect().left;vm.value=value,vm._onClick({x:(value-vm.min)*offsetWidth/(vm.max-vm.min)+boxLeft})}}};functioncreateTouchList(touchInits){var_a,touches=touchInits.map((function(touch){returnfunction(touch){if(document.createTouch)returndocument.createTouch(window,touch.target,touch.identifier,touch.pageX,touch.pageY,touch.screenX,touch.screenY);returnnewTouch(touch)}(touch)}));returndocument.createTouchList?(_a=document).createTouchList.apply(_a,touches):touches}varWebAdapter={getWindow:function(pageId){returnwindow},getDocument:function(pageId){returndocument},getEl:function(elementId){varelement=elementMap.get(elementId);if(!element)throwError("element destroyed");returnelement.element},getOffset:function(node){varrect=node.getBoundingClientRect();returnPromise.resolve({left:rect.left+window.pageXOffset,top:rect.top+window.pageYOffset})},querySelector:function(context,selector){return"page"===selector&&(selector="body"),Promise.resolve(transEl(context.querySelector(selector)))},querySelectorAll:function(context,selector){varelements=[],nodeList=document.querySelectorAll(selector);return[].forEach.call(nodeList,(function(node){try{elements.push(transEl(node))}catch(e){}})),Promise.resolve({elements:elements})},queryProperties:function(context,names){returnPromise.resolve({properties:names.map((function(name){varvalue=getDataByPath(context,name);return"document.documentElement.scrollTop"===name&&0===value&&(value=getDataByPath(context,"document.body.scrollTop")),value}))})},queryAttributes:function(context,names){returnPromise.resolve({attributes:names.map((function(name){returnString(context.getAttribute(name))}))})},queryStyles:function(context,names){varstyle=getComputedStyle(context);returnPromise.resolve({styles:names.map((function(name){returnstyle[name]}))})},queryHTML:function(context,type){returnPromise.resolve({html:(html="outer"===type?context.outerHTML:context.innerHTML,html.replace(/\n/g,"").replace(/(<uni-text[^>]*>)(<span[^>]*>[^<]*<\/span>)(.*?<\/uni-text>)/g,"$1$3").replace(/<\/?[^>]*>/g,(function(replacement){return-1<replacement.indexOf("<body")?"<page>":"</body>"===replacement?"</page>":0!==replacement.indexOf("<uni-")&&0!==replacement.indexOf("</uni-")?"":replacement.replace(/uni-/g,"").replace(/ role=""/g,"").replace(/ aria-label=""/g,"")})))});varhtml},dispatchTapEvent:function(el){returnel.click(),Promise.resolve()},dispatchLongpressEvent:function(el){returnPromise.resolve()},dispatchTouchEvent:function(el,type,eventInitDict){eventInitDict||(eventInitDict={}),eventInitDict.touches||(eventInitDict.touches=[]),eventInitDict.changedTouches||(eventInitDict.changedTouches=[]),eventInitDict.touches.length||eventInitDict.touches.push({identifier:Date.now(),target:el});vartouches=createTouchList(eventInitDict.touches),changedTouches=createTouchList(eventInitDict.changedTouches),targetTouches=createTouchList([]);returnel.dispatchEvent(newTouchEvent(type,{cancelable:!0,bubbles:!0,touches:touches,targetTouches:targetTouches,changedTouches:changedTouches})),Promise.resolve()},callFunction:function(el,functionName,args){varfn=getDataByPath(FUNCTIONS,functionName);returnfn?Promise.resolve({result:fn.apply(null,__spreadArrays([el],args))}):Promise.reject(Error(functionName+" not exists"))},triggerEvent:function(el,type,detail){varvm=el.__vue__;returnvm.$trigger&&vm.$trigger(type,{},detail),Promise.resolve()}};varApi=Object.assign({},function(adapter){return{"Page.getElement":function(params){returnadapter.querySelector(adapter.getDocument(params.pageId),params.selector)},"Page.getElements":function(params){returnadapter.querySelectorAll(adapter.getDocument(params.pageId),params.selector)},"Page.getWindowProperties":function(params){returnadapter.queryProperties(adapter.getWindow(params.pageId),params.names)}}}(WebAdapter),function(adapter){vargetEl=function(params){returnadapter.getEl(params.elementId,params.pageId)};return{"Element.getElement":function(params){returnadapter.querySelector(getEl(params),params.selector)},"Element.getElements":function(params){returnadapter.querySelectorAll(getEl(params),params.selector)},"Element.getDOMProperties":function(params){returnadapter.queryProperties(getEl(params),params.names)},"Element.getProperties":function(params){varel=getEl(params),ctx=el.__vue__||el.attr||{};returnadapter.queryProperties(ctx,params.names)},"Element.getOffset":function(params){returnadapter.getOffset(getEl(params))},"Element.getAttributes":function(params){returnadapter.queryAttributes(getEl(params),params.names)},"Element.getStyles":function(params){returnadapter.queryStyles(getEl(params),params.names)},"Element.getHTML":function(params){returnadapter.queryHTML(getEl(params),params.type)},"Element.tap":function(params){returnadapter.dispatchTapEvent(getEl(params))},"Element.longpress":function(params){returnadapter.dispatchLongpressEvent(getEl(params))},"Element.touchstart":function(params){returnadapter.dispatchTouchEvent(getEl(params),"touchstart",params)},"Element.touchmove":function(params){returnadapter.dispatchTouchEvent(getEl(params),"touchmove",params)},"Element.touchend":function(params){returnadapter.dispatchTouchEvent(getEl(params),"touchend",params)},"Element.callFunction":function(params){returnadapter.callFunction(getEl(params),params.functionName,params.args)},"Element.triggerEvent":function(params){returnadapter.triggerEvent(getEl(params),params.type,params.detail)}}}(WebAdapter));functionsend(data){returnUniViewJSBridge.publishHandler("onAutoMessageReceive",data)}UniViewJSBridge.subscribe("sendAutoMessage",(function(_a){varid=_a.id,method=_a.method,params=_a.params,data={id:id},fn=Api[method];if(!fn)returndata.error={message:method+" unimplemented"},send(data);try{fn(params).then((function(res){res&&(data.result=res)})).catch((function(err){data.error={message:err.message}})).finally((function(){send(data)}))}catch(err){data.error={message:err.message},send(data)}}));
"use strict";vare=require("os"),t=require("path"),s=require("debug"),r=require("licia/isWindows"),a=require("fs"),n=require("child_process"),o=require("licia/sleep"),i=require("licia/toStr"),c=require("licia/waitUntil"),l=require("licia/concat"),u=require("licia/getPort"),p=require("licia/dateFormat"),d=require("ws"),m=require("events"),f=require("licia/uuid"),h=require("licia/stringify");functiong(e){returne&&"object"==typeofe&&"default"ine?e:{default:e}}varw=g(e),y=g(t),v=g(s),E=g(r),b=g(a),P=g(n),j=g(o),M=g(i),$=g(c),O=g(l),A=g(u),q=g(p),C=g(d),S=g(f),T=g(h);constH=/(^[a-z][a-z0-9-]*)/i,L=/^navigator/i,R=/^swan-nav$/i;varN;!function(e){e.SELECTOR="selector",e.TAGNAME="tagName"}(N||(N={}));constk={[N.SELECTOR]:[{test:L,processor:e=>e.replace(L,"nav")},{test:H,processor:e=>`swan-${e}`}],[N.TAGNAME]:[{test:R,processor:e=>e.replace(R,"swan-navigator")},{test:H,processor:e=>e.toLocaleLowerCase().replace("swan-","")}]},D=e=>t=>{consts=(k[e]||[]).filter((e=>e.test.test(t)));for(consteofs)t=e.processor(t);returnt},x=D(N.SELECTOR),I=D(N.TAGNAME),F=e=>Object.assign({},e,{type:"id",info:{id:e.elementId}});/^win/.test(process.platform);class_extendsm.EventEmitter{constructor(e){super(),this.ws=e,this.ws.addEventListener("message",(e=>{this.emit("message",e.data)})),this.ws.addEventListener("close",(()=>{this.emit("close")}))}send(e){this.ws.send(e)}close(){this.ws.close()}}constU=newMap,W=newMap,B="Connection closed";classGextendsm.EventEmitter{constructor(e,t,s){super(),this.puppet=t,this.namespace=s,this.callbacks=newMap,this.transport=e,this.isAlive=!0,this.id=Date.now(),this.debug=v.default("automator:protocol:"+this.namespace),this.onMessage=e=>{vart,s;if(this.isAlive=!0,"true"===process.env.UNI_APP_X&&e.includes("pong"))return;this.debug(`${q.default("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${e}`);const{id:r,method:a,error:n,result:o,params:i}=JSON.parse(e);if(null===(t=null==o?void0:o.method)||void0===t?void0:t.startsWith("on"))returnvoid((e,t)=>{consts=U.get(e.method);(null==s?void0:s.has(t))&&s.get(t)(e.data)})(o,r);if(null===(s=null==o?void0:o.method)||void0===s?void0:s.startsWith("Socket.")){returnvoid((e,t,s)=>{constr=W.get(t);(null==r?void0:r.has(e))&&r.get(e)(s)})(o.method.replace("Socket.",""),o.id,o.data)}if(!r)returnthis.puppet.emit(a,i);const{callbacks:c}=this;if(r&&c.has(r)){conste=c.get(r);c.delete(r),n?e.reject(Error(n.message||n.detailMessage||n.errMsg)):e.resolve(o)}},this.onClose=()=>{this.callbacks.forEach((e=>{e.reject(Error(B))}))},this.transport.on("message",this.onMessage),this.transport.on("close",this.onClose)}send(e,t={},s=!0){if(s&&this.puppet.adapter.has(e))returnthis.puppet.adapter.send(this,e,t);constr=S.default(),a=T.default({id:r,method:e,params:t});return"ping"!==e&&this.debug(`${q.default("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${a}`),newPromise(((e,t)=>{try{this.transport.send(a)}catch(e){t(Error(B))}this.callbacks.set(r,{resolve:e,reject:t})}))}dispose(){this.transport.close()}startHeartbeat(){if("true"===process.env.UNI_APP_X&&"android"===process.env.UNI_APP_PLATFORM){conste=newMap,t=function(e){try{returnrequire(e)}catch(t){returnrequire(require.resolve(e,{paths:[process.cwd()]}))}}("adbkit"),s=5e3,r=w.default.platform();leta="",n="";"darwin"===r?(a='dumpsys activity | grep "Run"',n=`logcat -b crash | grep -C 10 ${"io.dcloud.uniappx"}`):"win32"===r&&(a='dumpsys activity | findstr "Run"',n="logcat | findstr UncaughtExceptionHandler"),e.set(this.id,setInterval((async()=>{if(!this.isAlive){consts=t.createClient(),r=awaits.listDevices();if(!r.length)throwError("Device not found");consto=r[0].id;returns.shell(o,a).then((function(e){lett,s="";e.on("data",(function(e){s+=e.toString(),t&&clearTimeout(t),t=setTimeout((()=>{s.includes("io.dcloud.uniapp")||console.log("Stop the test process.")}),50)}))})),s.shell(o,n).then((e=>{lett,s="";e.on("data",(e=>{s+=e.toString(),t&&clearTimeout(t),t=setTimeout((()=>{console.log(`crash log: ${s}`)}),50)}))})),clearInterval(e.get(this.id)),e.delete(this.id),voidthis.dispose()}this.send("ping"),this.isAlive=!1}),s))}}staticcreateDevtoolConnection(e,t){returnnewPromise(((s,r)=>{consta=newC.default(e);a.addEventListener("open",(()=>{s(newG(new_(a),t,"devtool"))})),a.addEventListener("error",r)}))}staticcreateRuntimeConnection(e,t,s){returnnewPromise(((r,a)=>{v.default("automator:runtime")(`${q.default("yyyy-mm-dd HH:MM:ss:l")} port=${e}`);constn=newC.default.Server({port:e});$.default((async()=>{if(t.runtimeConnection)return!0}),s,1e3).catch((()=>{n.close(),a("Failed to connect to runtime, please make sure the project is running")})),n.on("connection",(function(e){v.default("automator:runtime")(`${q.default("yyyy-mm-dd HH:MM:ss:l")} connected`);consts=newG(new_(e),t,"runtime");t.setRuntimeConnection(s),s.startHeartbeat(),r(s)})),t.setRuntimeServer(n)}))}}constz=v.default("automator:devtool");asyncfunctionX(e,t,s){const{port:r,cliPath:a,timeout:n,cwd:o="",account:i="",args:c=[],launch:l=!0}=t;letu=!1,p=!1;if(!1!==l){constt={stdio:"ignore"};o&&(t.cwd=o);lets=O.default(c,[]);s=O.default(s,["--auto"]),s=O.default(s,[e,"--auto-port",M.default(r)]),i&&(s=O.default(s,["--auto-account",i]));try{z("%s %o %o",a,s,t);conste=P.default.spawn(a,s,t);e.on("error",(e=>{u=!0})),e.on("exit",(()=>{setTimeout((()=>{p=!0}),15e3)})),e.unref()}catch(e){u=!1}}elsesetTimeout((()=>{p=!0}),15e3);constd=await$.default((async()=>{try{if(u||p)return!0;conste=awaitasyncfunction(e,t){lets;try{s=awaitG.createDevtoolConnection(e.wsEndpoint,t)}catch(t){throwError(`Failed connecting to ${e.wsEndpoint}, check if target project window is opened with automation enabled`)}returns}({wsEndpoint:`ws://127.0.0.1:${r}`},s);returne}catch(e){}}),n,1e3);if(u)throwError(`Failed to launch ${s.devtools.name}, please make sure cliPath is correctly specified`);if(p)throwError(`Failed to launch ${s.devtools.name} , please make sure http port is open`);returnawaitj.default(5e3),z(`${q.default("yyyy-mm-dd HH:MM:ss:l")} connected`),d}constJ=[];["","-rc"].forEach((e=>{E.default?(J.push(y.default.join(w.default.homedir(),`AppData/Local/Programs/swan-ide-gui${e}/cli.bat`)),J.push(`C:/Program Files/swan-ide-gui${e}/cli.bat`)):J.push(`/Applications/百度开发者工具${e}.app/Contents/MacOS/cli`)}));constV={devtools:{name:"Baidu DevTools",remote:!0,automator:!0,paths:J,required:["project.swan.json","app.json","app.js"],defaultPort:9430,validate:asyncfunction(e,t){consts=function(e,t){consts=t.devtools.paths.slice(0);e&&s.unshift(e);for(consteofs)if(b.default.existsSync(e))returne;throwError(`${t.devtools.name} not found, please specify executablePath option`)}(e.executablePath,t);letr=e.port||t.devtools.defaultPort;if(!1!==e.launch)try{r=awaitasyncfunction(e,t){consts=awaitA.default(e||t);if(e&&s!==e)throwError(`Port ${e} is in use, please specify another port`);returns}(r)}catch(t){e.launch=!1}else{r===awaitA.default(r)&&(e.launch=!0)}returnObject.assign(Object.assign({},e),{port:r,cliPath:s})},asynccreate(e,t,s){constr=awaitX(e,t,s);returns.compiled?v.default("automator:devtool")("Waiting for runtime automator"):(v.default("automator:devtool")("initRuntimeAutomator"),r.send("smartapp.swan",{api:"$$initRuntimeAutomator",params:[]})),r}},adapter:{"Tool.enableRemoteDebug":{reflect:asynce=>({qrCode:(awaite("Tool.enablePreview")).url})},"App.exit":{reflect:async()=>Promise.resolve()},"Page.getElement":{reflect:async(e,t)=>(awaite("Page.getElements",t)).elements[0]},"Page.getElements":{reflect:async(e,t)=>{return{elements:(awaite("smartapp.element.getBySelector",Object.assign(Object.assign({},t),{properties:["id","tagName"],selector:(s=t.selector,s.split("").map((e=>x(e))).join(""))}))).map((e=>{constt=e.properties;return{elementId:t.id,nodeId:t.id,tagName:I(t.tagName)}}))};vars}},"Page.getWindowProperties":{reflect:async(e,t)=>{consts=t.names.map((e=>e.replace("document.documentElement.",""))),r=(awaite("smartapp.element.getBySelector",{properties:s,selector:"html"}))[0];return{properties:s.map((e=>r.properties[e]))}}},"Element.getHTML":{reflect:async(e,t)=>{consts=[t.type+"HTML"];return{html:(awaite("Element.getDOMProperties",Object.assign(Object.assign({},t),{names:s}))).properties[0]}}},"Element.getElement":{reflect:async(e,t)=>(awaite("Element.getElements",t)).elements[0]},"Element.getElements":{reflect:async(e,t)=>{const{elements:s}=awaite("Page.getElements",Object.assign(Object.assign({},t),{selector:`#${t.elementId}${t.selector}`}));returns.forEach((e=>{e.nodeId=e.id})),{elements:s}}},"Element.getAttributes":{reflect:async(e,t)=>{consts=[];for(constroft.names)s.push(awaite("smartapp.element.getAttribute",Object.assign({attribute:r},t)));return{attributes:s}},params:F},"Element.getStyles":{reflect:async(e,t)=>{consts=[];for(constroft.names)s.push(awaite("smartapp.element.getComputedStyle",Object.assign({style:r},t)));return{styles:s}},params:F},"Element.getDOMProperties":{reflect:async(e,t)=>{consts=[];for(constroft.names)s.push(awaite("smartapp.element.getProperty",Object.assign({property:r},t)));return{properties:s}},params:F},"Element.getProperties":{reflect:async(e,t)=>{consts=[];for(constroft.names)s.push(awaite("smartapp.element.getAttribute",Object.assign({attribute:r},t)));return{properties:s}},params:F},"Element.getOffset":{reflect:async(e,t)=>({left:awaite("smartapp.element.getProperty",Object.assign({property:"offsetLeft"},t)),top:awaite("smartapp.element.getProperty",Object.assign({property:"offsetTop"},t))}),params:F},"Element.tap":{reflect:"smartapp.element.touch",params:F}}};module.exports=V;
"use strict";vare=require("os"),t=require("path"),s=require("debug"),r=require("licia/isWindows"),a=require("fs"),n=require("child_process"),o=require("licia/sleep"),i=require("licia/toStr"),c=require("licia/waitUntil"),l=require("licia/concat"),u=require("licia/getPort"),p=require("licia/dateFormat"),d=require("ws"),m=require("events"),f=require("licia/uuid"),h=require("licia/stringify");functiong(e){returne&&"object"==typeofe&&"default"ine?e:{default:e}}varw=g(e),y=g(t),v=g(s),E=g(r),b=g(a),P=g(n),j=g(o),M=g(i),$=g(c),O=g(l),A=g(u),q=g(p),C=g(d),S=g(f),T=g(h);constH=/(^[a-z][a-z0-9-]*)/i,L=/^navigator/i,R=/^swan-nav$/i;varN;!function(e){e.SELECTOR="selector",e.TAGNAME="tagName"}(N||(N={}));constk={[N.SELECTOR]:[{test:L,processor:e=>e.replace(L,"nav")},{test:H,processor:e=>`swan-${e}`}],[N.TAGNAME]:[{test:R,processor:e=>e.replace(R,"swan-navigator")},{test:H,processor:e=>e.toLocaleLowerCase().replace("swan-","")}]},D=e=>t=>{consts=(k[e]||[]).filter((e=>e.test.test(t)));for(consteofs)t=e.processor(t);returnt},x=D(N.SELECTOR),I=D(N.TAGNAME),F=e=>Object.assign({},e,{type:"id",info:{id:e.elementId}});/^win/.test(process.platform);class_extendsm.EventEmitter{constructor(e){super(),this.ws=e,this.ws.addEventListener("message",(e=>{this.emit("message",e.data)})),this.ws.addEventListener("close",(()=>{this.emit("close")}))}send(e){this.ws.send(e)}close(){this.ws.close()}}constU=newMap,W=newMap,B="Connection closed";classGextendsm.EventEmitter{constructor(e,t,s){super(),this.puppet=t,this.namespace=s,this.callbacks=newMap,this.transport=e,this.isAlive=!0,this.id=Date.now(),this.debug=v.default("automator:protocol:"+this.namespace),this.onMessage=e=>{vart,s;if(this.isAlive=!0,"true"===process.env.UNI_APP_X&&e.includes("pong"))return;this.debug(`${q.default("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${e}`);const{id:r,method:a,error:n,result:o,params:i}=JSON.parse(e);if(null===(t=null==o?void0:o.method)||void0===t?void0:t.startsWith("on"))returnvoid((e,t)=>{consts=U.get(e.method);(null==s?void0:s.has(t))&&s.get(t)(e.data)})(o,r);if(null===(s=null==o?void0:o.method)||void0===s?void0:s.startsWith("Socket.")){returnvoid((e,t,s)=>{constr=W.get(t);(null==r?void0:r.has(e))&&r.get(e)(s)})(o.method.replace("Socket.",""),o.id,o.data)}if(!r)returnthis.puppet.emit(a,i);const{callbacks:c}=this;if(r&&c.has(r)){conste=c.get(r);c.delete(r),n?e.reject(Error(n.message||n.detailMessage||n.errMsg)):e.resolve(o)}},this.onClose=()=>{this.callbacks.forEach((e=>{e.reject(Error(B))}))},this.transport.on("message",this.onMessage),this.transport.on("close",this.onClose)}send(e,t={},s=!0){if(s&&this.puppet.adapter.has(e))returnthis.puppet.adapter.send(this,e,t);constr=S.default(),a=T.default({id:r,method:e,params:t});return"ping"!==e&&this.debug(`${q.default("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${a}`),newPromise(((e,t)=>{try{this.transport.send(a)}catch(e){t(Error(B))}this.callbacks.set(r,{resolve:e,reject:t})}))}dispose(){this.transport.close()}startHeartbeat(){if("true"===process.env.UNI_APP_X&&"android"===process.env.UNI_APP_PLATFORM){conste=newMap,t=function(e){try{returnrequire(e)}catch(t){returnrequire(require.resolve(e,{paths:[process.cwd()]}))}}("adbkit"),s=9e3,r=w.default.platform();leta="",n="";"darwin"===r?(a='dumpsys activity | grep "Run"',n=`logcat -b crash | grep -C 10 ${"io.dcloud.uniappx"}`):"win32"===r&&(a='dumpsys activity | findstr "Run"',n="logcat | findstr UncaughtExceptionHandler"),e.set(this.id,setInterval((async()=>{if(!this.isAlive){consts=t.createClient(),r=awaits.listDevices();if(!r.length)throwError("Device not found");consto=r[0].id;returns.shell(o,a).then((function(e){lett,s="";e.on("data",(function(e){s+=e.toString(),t&&clearTimeout(t),t=setTimeout((()=>{s.includes("io.dcloud.uniapp")||console.log("Stop the test process.")}),50)}))})),s.shell(o,n).then((e=>{lett,s="";e.on("data",(e=>{s+=e.toString(),t&&clearTimeout(t),t=setTimeout((()=>{console.log(`crash log: ${s}`)}),50)}))})),clearInterval(e.get(this.id)),e.delete(this.id),voidthis.dispose()}this.send("ping"),this.isAlive=!1}),s))}}staticcreateDevtoolConnection(e,t){returnnewPromise(((s,r)=>{consta=newC.default(e);a.addEventListener("open",(()=>{s(newG(new_(a),t,"devtool"))})),a.addEventListener("error",r)}))}staticcreateRuntimeConnection(e,t,s){returnnewPromise(((r,a)=>{v.default("automator:runtime")(`${q.default("yyyy-mm-dd HH:MM:ss:l")} port=${e}`);constn=newC.default.Server({port:e});$.default((async()=>{if(t.runtimeConnection)return!0}),s,1e3).catch((()=>{n.close(),a("Failed to connect to runtime, please make sure the project is running")})),n.on("connection",(function(e){v.default("automator:runtime")(`${q.default("yyyy-mm-dd HH:MM:ss:l")} connected`);consts=newG(new_(e),t,"runtime");t.setRuntimeConnection(s),s.startHeartbeat(),r(s)})),t.setRuntimeServer(n)}))}}constz=v.default("automator:devtool");asyncfunctionX(e,t,s){const{port:r,cliPath:a,timeout:n,cwd:o="",account:i="",args:c=[],launch:l=!0}=t;letu=!1,p=!1;if(!1!==l){constt={stdio:"ignore"};o&&(t.cwd=o);lets=O.default(c,[]);s=O.default(s,["--auto"]),s=O.default(s,[e,"--auto-port",M.default(r)]),i&&(s=O.default(s,["--auto-account",i]));try{z("%s %o %o",a,s,t);conste=P.default.spawn(a,s,t);e.on("error",(e=>{u=!0})),e.on("exit",(()=>{setTimeout((()=>{p=!0}),15e3)})),e.unref()}catch(e){u=!1}}elsesetTimeout((()=>{p=!0}),15e3);constd=await$.default((async()=>{try{if(u||p)return!0;conste=awaitasyncfunction(e,t){lets;try{s=awaitG.createDevtoolConnection(e.wsEndpoint,t)}catch(t){throwError(`Failed connecting to ${e.wsEndpoint}, check if target project window is opened with automation enabled`)}returns}({wsEndpoint:`ws://127.0.0.1:${r}`},s);returne}catch(e){}}),n,1e3);if(u)throwError(`Failed to launch ${s.devtools.name}, please make sure cliPath is correctly specified`);if(p)throwError(`Failed to launch ${s.devtools.name} , please make sure http port is open`);returnawaitj.default(5e3),z(`${q.default("yyyy-mm-dd HH:MM:ss:l")} connected`),d}constJ=[];["","-rc"].forEach((e=>{E.default?(J.push(y.default.join(w.default.homedir(),`AppData/Local/Programs/swan-ide-gui${e}/cli.bat`)),J.push(`C:/Program Files/swan-ide-gui${e}/cli.bat`)):J.push(`/Applications/百度开发者工具${e}.app/Contents/MacOS/cli`)}));constV={devtools:{name:"Baidu DevTools",remote:!0,automator:!0,paths:J,required:["project.swan.json","app.json","app.js"],defaultPort:9430,validate:asyncfunction(e,t){consts=function(e,t){consts=t.devtools.paths.slice(0);e&&s.unshift(e);for(consteofs)if(b.default.existsSync(e))returne;throwError(`${t.devtools.name} not found, please specify executablePath option`)}(e.executablePath,t);letr=e.port||t.devtools.defaultPort;if(!1!==e.launch)try{r=awaitasyncfunction(e,t){consts=awaitA.default(e||t);if(e&&s!==e)throwError(`Port ${e} is in use, please specify another port`);returns}(r)}catch(t){e.launch=!1}else{r===awaitA.default(r)&&(e.launch=!0)}returnObject.assign(Object.assign({},e),{port:r,cliPath:s})},asynccreate(e,t,s){constr=awaitX(e,t,s);returns.compiled?v.default("automator:devtool")("Waiting for runtime automator"):(v.default("automator:devtool")("initRuntimeAutomator"),r.send("smartapp.swan",{api:"$$initRuntimeAutomator",params:[]})),r}},adapter:{"Tool.enableRemoteDebug":{reflect:asynce=>({qrCode:(awaite("Tool.enablePreview")).url})},"App.exit":{reflect:async()=>Promise.resolve()},"Page.getElement":{reflect:async(e,t)=>(awaite("Page.getElements",t)).elements[0]},"Page.getElements":{reflect:async(e,t)=>{return{elements:(awaite("smartapp.element.getBySelector",Object.assign(Object.assign({},t),{properties:["id","tagName"],selector:(s=t.selector,s.split("").map((e=>x(e))).join(""))}))).map((e=>{constt=e.properties;return{elementId:t.id,nodeId:t.id,tagName:I(t.tagName)}}))};vars}},"Page.getWindowProperties":{reflect:async(e,t)=>{consts=t.names.map((e=>e.replace("document.documentElement.",""))),r=(awaite("smartapp.element.getBySelector",{properties:s,selector:"html"}))[0];return{properties:s.map((e=>r.properties[e]))}}},"Element.getHTML":{reflect:async(e,t)=>{consts=[t.type+"HTML"];return{html:(awaite("Element.getDOMProperties",Object.assign(Object.assign({},t),{names:s}))).properties[0]}}},"Element.getElement":{reflect:async(e,t)=>(awaite("Element.getElements",t)).elements[0]},"Element.getElements":{reflect:async(e,t)=>{const{elements:s}=awaite("Page.getElements",Object.assign(Object.assign({},t),{selector:`#${t.elementId}${t.selector}`}));returns.forEach((e=>{e.nodeId=e.id})),{elements:s}}},"Element.getAttributes":{reflect:async(e,t)=>{consts=[];for(constroft.names)s.push(awaite("smartapp.element.getAttribute",Object.assign({attribute:r},t)));return{attributes:s}},params:F},"Element.getStyles":{reflect:async(e,t)=>{consts=[];for(constroft.names)s.push(awaite("smartapp.element.getComputedStyle",Object.assign({style:r},t)));return{styles:s}},params:F},"Element.getDOMProperties":{reflect:async(e,t)=>{consts=[];for(constroft.names)s.push(awaite("smartapp.element.getProperty",Object.assign({property:r},t)));return{properties:s}},params:F},"Element.getProperties":{reflect:async(e,t)=>{consts=[];for(constroft.names)s.push(awaite("smartapp.element.getAttribute",Object.assign({attribute:r},t)));return{properties:s}},params:F},"Element.getOffset":{reflect:async(e,t)=>({left:awaite("smartapp.element.getProperty",Object.assign({property:"offsetLeft"},t)),top:awaite("smartapp.element.getProperty",Object.assign({property:"offsetTop"},t))}),params:F},"Element.tap":{reflect:"smartapp.element.touch",params:F}}};module.exports=V;
"use strict";vare=require("debug"),t=require("licia/isWindows"),o=require("licia/getPort"),n=require("qrcode-reader"),r=require("fs"),a=require("child_process"),s=require("licia/sleep"),i=require("licia/toStr"),c=require("licia/waitUntil"),l=require("licia/concat"),u=require("licia/dateFormat"),d=require("ws"),p=require("events"),h=require("licia/uuid"),f=require("licia/stringify"),m=require("os");functionw(e){returne&&"object"==typeofe&&"default"ine?e:{default:e}}varv=w(e),g=w(t),y=w(o),b=w(n),E=w(r),q=w(a),M=w(s),P=w(i),$=w(c),j=w(l),C=w(u),x=w(d),A=w(h),H=w(f),k=w(m);/^win/.test(process.platform);classSextendsp.EventEmitter{constructor(e){super(),this.ws=e,this.ws.addEventListener("message",(e=>{this.emit("message",e.data)})),this.ws.addEventListener("close",(()=>{this.emit("close")}))}send(e){this.ws.send(e)}close(){this.ws.close()}}constT=newMap,R=newMap,D="Connection closed";classFextendsp.EventEmitter{constructor(e,t,o){super(),this.puppet=t,this.namespace=o,this.callbacks=newMap,this.transport=e,this.isAlive=!0,this.id=Date.now(),this.debug=v.default("automator:protocol:"+this.namespace),this.onMessage=e=>{vart,o;if(this.isAlive=!0,"true"===process.env.UNI_APP_X&&e.includes("pong"))return;this.debug(`${C.default("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${e}`);const{id:n,method:r,error:a,result:s,params:i}=JSON.parse(e);if(null===(t=null==s?void0:s.method)||void0===t?void0:t.startsWith("on"))returnvoid((e,t)=>{consto=T.get(e.method);(null==o?void0:o.has(t))&&o.get(t)(e.data)})(s,n);if(null===(o=null==s?void0:s.method)||void0===o?void0:o.startsWith("Socket.")){returnvoid((e,t,o)=>{constn=R.get(t);(null==n?void0:n.has(e))&&n.get(e)(o)})(s.method.replace("Socket.",""),s.id,s.data)}if(!n)returnthis.puppet.emit(r,i);const{callbacks:c}=this;if(n&&c.has(n)){conste=c.get(n);c.delete(n),a?e.reject(Error(a.message||a.detailMessage||a.errMsg)):e.resolve(s)}},this.onClose=()=>{this.callbacks.forEach((e=>{e.reject(Error(D))}))},this.transport.on("message",this.onMessage),this.transport.on("close",this.onClose)}send(e,t={},o=!0){if(o&&this.puppet.adapter.has(e))returnthis.puppet.adapter.send(this,e,t);constn=A.default(),r=H.default({id:n,method:e,params:t});return"ping"!==e&&this.debug(`${C.default("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${r}`),newPromise(((e,t)=>{try{this.transport.send(r)}catch(e){t(Error(D))}this.callbacks.set(n,{resolve:e,reject:t})}))}dispose(){this.transport.close()}startHeartbeat(){if("true"===process.env.UNI_APP_X&&"android"===process.env.UNI_APP_PLATFORM){conste=newMap,t=function(e){try{returnrequire(e)}catch(t){returnrequire(require.resolve(e,{paths:[process.cwd()]}))}}("adbkit"),o=5e3,n=k.default.platform();letr="",a="";"darwin"===n?(r='dumpsys activity | grep "Run"',a=`logcat -b crash | grep -C 10 ${"io.dcloud.uniappx"}`):"win32"===n&&(r='dumpsys activity | findstr "Run"',a="logcat | findstr UncaughtExceptionHandler"),e.set(this.id,setInterval((async()=>{if(!this.isAlive){consto=t.createClient(),n=awaito.listDevices();if(!n.length)throwError("Device not found");consts=n[0].id;returno.shell(s,r).then((function(e){lett,o="";e.on("data",(function(e){o+=e.toString(),t&&clearTimeout(t),t=setTimeout((()=>{o.includes("io.dcloud.uniapp")||console.log("Stop the test process.")}),50)}))})),o.shell(s,a).then((e=>{lett,o="";e.on("data",(e=>{o+=e.toString(),t&&clearTimeout(t),t=setTimeout((()=>{console.log(`crash log: ${o}`)}),50)}))})),clearInterval(e.get(this.id)),e.delete(this.id),voidthis.dispose()}this.send("ping"),this.isAlive=!1}),o))}}staticcreateDevtoolConnection(e,t){returnnewPromise(((o,n)=>{constr=newx.default(e);r.addEventListener("open",(()=>{o(newF(newS(r),t,"devtool"))})),r.addEventListener("error",n)}))}staticcreateRuntimeConnection(e,t,o){returnnewPromise(((n,r)=>{v.default("automator:runtime")(`${C.default("yyyy-mm-dd HH:MM:ss:l")} port=${e}`);consta=newx.default.Server({port:e});$.default((async()=>{if(t.runtimeConnection)return!0}),o,1e3).catch((()=>{a.close(),r("Failed to connect to runtime, please make sure the project is running")})),a.on("connection",(function(e){v.default("automator:runtime")(`${C.default("yyyy-mm-dd HH:MM:ss:l")} connected`);consto=newF(newS(e),t,"runtime");t.setRuntimeConnection(o),o.startHeartbeat(),n(o)})),t.setRuntimeServer(a)}))}}constL=v.default("automator:devtool");asyncfunctionO(e,t,o){const{port:n,cliPath:r,timeout:a,cwd:s="",account:i="",args:c=[],launch:l=!0}=t;letu=!1,d=!1;if(!1!==l){constt={stdio:"ignore",detached:!0};s&&(t.cwd=s);leto=j.default(c,[]);o=j.default(o,["auto","--project"]),o=j.default(o,[e,"--auto-port",P.default(n)]),i&&(o=j.default(o,["--auto-account",i]));try{L("%s %o %o",r,o,t);conste=q.default.spawn(r,o,t);e.on("error",(e=>{u=!0})),e.on("exit",(()=>{setTimeout((()=>{d=!0}),15e3)})),e.unref()}catch(e){u=!1}}elsesetTimeout((()=>{d=!0}),15e3);constp=await$.default((async()=>{try{if(u||d)return!0;conste=awaitasyncfunction(e,t){leto;try{o=awaitF.createDevtoolConnection(e.wsEndpoint,t)}catch(t){throwError(`Failed connecting to ${e.wsEndpoint}, check if target project window is opened with automation enabled`)}returno}({wsEndpoint:`ws://127.0.0.1:${n}`},o);returne}catch(e){}}),a,1e3);if(u)throwError(`Failed to launch ${o.devtools.name}, please make sure cliPath is correctly specified`);if(d)throwError(`Failed to launch ${o.devtools.name} , please make sure http port is open`);returnawaitM.default(5e3),L(`${C.default("yyyy-mm-dd HH:MM:ss:l")} connected`),p}constW={devtools:{name:"Wechat web devTools",remote:!0,automator:!0,paths:[g.default?"C:/Program Files (x86)/Tencent/微信web开发者工具/cli.bat":"/Applications/wechatwebdevtools.app/Contents/MacOS/cli"],required:["project.config.json","app.json","app.js"],defaultPort:9420,validate:asyncfunction(e,t){consto=function(e,t){consto=t.devtools.paths.slice(0);e&&o.unshift(e);for(consteofo)if(E.default.existsSync(e))returne;throwError(`${t.devtools.name} not found, please specify executablePath option`)}(e.executablePath,t);letn=e.port||t.devtools.defaultPort;if(!1!==e.launch)try{n=awaitasyncfunction(e,t){consto=awaity.default(e||t);if(e&&o!==e)throwError(`Port ${e} is in use, please specify another port`);returno}(n)}catch(t){e.launch=!1}else{n===awaity.default(n)&&(e.launch=!0)}returnObject.assign(Object.assign({},e),{port:n,cliPath:o})},asynccreate(e,t,o){constn=awaitO(e,t,o);returno.compiled?v.default("automator:devtool")("Waiting for runtime automator"):(v.default("automator:devtool")("initRuntimeAutomator"),n.send("App.callWxMethod",{method:"$$initRuntimeAutomator",args:[]})),n}},adapter:{"Tool.enableRemoteDebug":{reflect:async(e,t)=>{let{qrCode:o}=awaite("Tool.enableRemoteDebug",t,!1);returno&&(o=awaitfunction(e){constt=newBuffer(e,"base64");returnnewPromise((async(e,o)=>{constn=awaitrequire("jimp").read(t),r=newb.default;r.callback=function(t,n){if(t)returno(t);e(n.result)},r.decode(n.bitmap)}))}(o)),{qrCode:o}}},"App.callFunction":{reflect:async(e,t)=>{returne("App.callFunction",Object.assign(Object.assign({},t),{functionDeclaration:(o=t.functionDeclaration,"}"===o[o.length-1]?o.replace("{","{\nvar uni = wx;\n"):o.replace("=>","=>{\nvar uni = wx;\nreturn ")+"}")}),!1);varo}},"Element.getHTML":{reflect:async(e,t)=>({html:(awaite("Element.getWXML",t,!1)).wxml})}}};module.exports=W;
"use strict";vare=require("debug"),t=require("licia/isWindows"),o=require("licia/getPort"),n=require("qrcode-reader"),r=require("fs"),a=require("child_process"),s=require("licia/sleep"),i=require("licia/toStr"),c=require("licia/waitUntil"),l=require("licia/concat"),u=require("licia/dateFormat"),d=require("ws"),p=require("events"),h=require("licia/uuid"),f=require("licia/stringify"),m=require("os");functionw(e){returne&&"object"==typeofe&&"default"ine?e:{default:e}}varv=w(e),g=w(t),y=w(o),b=w(n),E=w(r),q=w(a),M=w(s),P=w(i),$=w(c),j=w(l),C=w(u),x=w(d),A=w(h),H=w(f),k=w(m);/^win/.test(process.platform);classSextendsp.EventEmitter{constructor(e){super(),this.ws=e,this.ws.addEventListener("message",(e=>{this.emit("message",e.data)})),this.ws.addEventListener("close",(()=>{this.emit("close")}))}send(e){this.ws.send(e)}close(){this.ws.close()}}constT=newMap,R=newMap,D="Connection closed";classFextendsp.EventEmitter{constructor(e,t,o){super(),this.puppet=t,this.namespace=o,this.callbacks=newMap,this.transport=e,this.isAlive=!0,this.id=Date.now(),this.debug=v.default("automator:protocol:"+this.namespace),this.onMessage=e=>{vart,o;if(this.isAlive=!0,"true"===process.env.UNI_APP_X&&e.includes("pong"))return;this.debug(`${C.default("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${e}`);const{id:n,method:r,error:a,result:s,params:i}=JSON.parse(e);if(null===(t=null==s?void0:s.method)||void0===t?void0:t.startsWith("on"))returnvoid((e,t)=>{consto=T.get(e.method);(null==o?void0:o.has(t))&&o.get(t)(e.data)})(s,n);if(null===(o=null==s?void0:s.method)||void0===o?void0:o.startsWith("Socket.")){returnvoid((e,t,o)=>{constn=R.get(t);(null==n?void0:n.has(e))&&n.get(e)(o)})(s.method.replace("Socket.",""),s.id,s.data)}if(!n)returnthis.puppet.emit(r,i);const{callbacks:c}=this;if(n&&c.has(n)){conste=c.get(n);c.delete(n),a?e.reject(Error(a.message||a.detailMessage||a.errMsg)):e.resolve(s)}},this.onClose=()=>{this.callbacks.forEach((e=>{e.reject(Error(D))}))},this.transport.on("message",this.onMessage),this.transport.on("close",this.onClose)}send(e,t={},o=!0){if(o&&this.puppet.adapter.has(e))returnthis.puppet.adapter.send(this,e,t);constn=A.default(),r=H.default({id:n,method:e,params:t});return"ping"!==e&&this.debug(`${C.default("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${r}`),newPromise(((e,t)=>{try{this.transport.send(r)}catch(e){t(Error(D))}this.callbacks.set(n,{resolve:e,reject:t})}))}dispose(){this.transport.close()}startHeartbeat(){if("true"===process.env.UNI_APP_X&&"android"===process.env.UNI_APP_PLATFORM){conste=newMap,t=function(e){try{returnrequire(e)}catch(t){returnrequire(require.resolve(e,{paths:[process.cwd()]}))}}("adbkit"),o=9e3,n=k.default.platform();letr="",a="";"darwin"===n?(r='dumpsys activity | grep "Run"',a=`logcat -b crash | grep -C 10 ${"io.dcloud.uniappx"}`):"win32"===n&&(r='dumpsys activity | findstr "Run"',a="logcat | findstr UncaughtExceptionHandler"),e.set(this.id,setInterval((async()=>{if(!this.isAlive){consto=t.createClient(),n=awaito.listDevices();if(!n.length)throwError("Device not found");consts=n[0].id;returno.shell(s,r).then((function(e){lett,o="";e.on("data",(function(e){o+=e.toString(),t&&clearTimeout(t),t=setTimeout((()=>{o.includes("io.dcloud.uniapp")||console.log("Stop the test process.")}),50)}))})),o.shell(s,a).then((e=>{lett,o="";e.on("data",(e=>{o+=e.toString(),t&&clearTimeout(t),t=setTimeout((()=>{console.log(`crash log: ${o}`)}),50)}))})),clearInterval(e.get(this.id)),e.delete(this.id),voidthis.dispose()}this.send("ping"),this.isAlive=!1}),o))}}staticcreateDevtoolConnection(e,t){returnnewPromise(((o,n)=>{constr=newx.default(e);r.addEventListener("open",(()=>{o(newF(newS(r),t,"devtool"))})),r.addEventListener("error",n)}))}staticcreateRuntimeConnection(e,t,o){returnnewPromise(((n,r)=>{v.default("automator:runtime")(`${C.default("yyyy-mm-dd HH:MM:ss:l")} port=${e}`);consta=newx.default.Server({port:e});$.default((async()=>{if(t.runtimeConnection)return!0}),o,1e3).catch((()=>{a.close(),r("Failed to connect to runtime, please make sure the project is running")})),a.on("connection",(function(e){v.default("automator:runtime")(`${C.default("yyyy-mm-dd HH:MM:ss:l")} connected`);consto=newF(newS(e),t,"runtime");t.setRuntimeConnection(o),o.startHeartbeat(),n(o)})),t.setRuntimeServer(a)}))}}constL=v.default("automator:devtool");asyncfunctionO(e,t,o){const{port:n,cliPath:r,timeout:a,cwd:s="",account:i="",args:c=[],launch:l=!0}=t;letu=!1,d=!1;if(!1!==l){constt={stdio:"ignore",detached:!0};s&&(t.cwd=s);leto=j.default(c,[]);o=j.default(o,["auto","--project"]),o=j.default(o,[e,"--auto-port",P.default(n)]),i&&(o=j.default(o,["--auto-account",i]));try{L("%s %o %o",r,o,t);conste=q.default.spawn(r,o,t);e.on("error",(e=>{u=!0})),e.on("exit",(()=>{setTimeout((()=>{d=!0}),15e3)})),e.unref()}catch(e){u=!1}}elsesetTimeout((()=>{d=!0}),15e3);constp=await$.default((async()=>{try{if(u||d)return!0;conste=awaitasyncfunction(e,t){leto;try{o=awaitF.createDevtoolConnection(e.wsEndpoint,t)}catch(t){throwError(`Failed connecting to ${e.wsEndpoint}, check if target project window is opened with automation enabled`)}returno}({wsEndpoint:`ws://127.0.0.1:${n}`},o);returne}catch(e){}}),a,1e3);if(u)throwError(`Failed to launch ${o.devtools.name}, please make sure cliPath is correctly specified`);if(d)throwError(`Failed to launch ${o.devtools.name} , please make sure http port is open`);returnawaitM.default(5e3),L(`${C.default("yyyy-mm-dd HH:MM:ss:l")} connected`),p}constW={devtools:{name:"Wechat web devTools",remote:!0,automator:!0,paths:[g.default?"C:/Program Files (x86)/Tencent/微信web开发者工具/cli.bat":"/Applications/wechatwebdevtools.app/Contents/MacOS/cli"],required:["project.config.json","app.json","app.js"],defaultPort:9420,validate:asyncfunction(e,t){consto=function(e,t){consto=t.devtools.paths.slice(0);e&&o.unshift(e);for(consteofo)if(E.default.existsSync(e))returne;throwError(`${t.devtools.name} not found, please specify executablePath option`)}(e.executablePath,t);letn=e.port||t.devtools.defaultPort;if(!1!==e.launch)try{n=awaitasyncfunction(e,t){consto=awaity.default(e||t);if(e&&o!==e)throwError(`Port ${e} is in use, please specify another port`);returno}(n)}catch(t){e.launch=!1}else{n===awaity.default(n)&&(e.launch=!0)}returnObject.assign(Object.assign({},e),{port:n,cliPath:o})},asynccreate(e,t,o){constn=awaitO(e,t,o);returno.compiled?v.default("automator:devtool")("Waiting for runtime automator"):(v.default("automator:devtool")("initRuntimeAutomator"),n.send("App.callWxMethod",{method:"$$initRuntimeAutomator",args:[]})),n}},adapter:{"Tool.enableRemoteDebug":{reflect:async(e,t)=>{let{qrCode:o}=awaite("Tool.enableRemoteDebug",t,!1);returno&&(o=awaitfunction(e){constt=newBuffer(e,"base64");returnnewPromise((async(e,o)=>{constn=awaitrequire("jimp").read(t),r=newb.default;r.callback=function(t,n){if(t)returno(t);e(n.result)},r.decode(n.bitmap)}))}(o)),{qrCode:o}}},"App.callFunction":{reflect:async(e,t)=>{returne("App.callFunction",Object.assign(Object.assign({},t),{functionDeclaration:(o=t.functionDeclaration,"}"===o[o.length-1]?o.replace("{","{\nvar uni = wx;\n"):o.replace("=>","=>{\nvar uni = wx;\nreturn ")+"}")}),!1);varo}},"Element.getHTML":{reflect:async(e,t)=>({html:(awaite("Element.getWXML",t,!1)).wxml})}}};module.exports=W;