varn,e=Object.prototype.hasOwnProperty,t=Array.isArray,r=function(n){vare=Object.create(null);returnfunction(t){returne[t]||(e[t]=n(t))}},o=/-(\w)/g,u=r((function(n){returnn.replace(o,(function(n,e){returne?e.toUpperCase():""}))})),i=r((function(n){returnn.charAt(0).toUpperCase()+n.slice(1)})),a=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;functionc(n,r){if(t(n))returnn;if(r&&(o=r,u=n,e.call(o,u)))return[n];varo,u,i=[];returnn.replace(a,(function(n,e,t,r){returni.push(t?r.replace(/\\(\\)?/g,"$1"):e||n),r})),i}functions(n){returnn.__wxWebviewId__?n.__wxWebviewId__:n.privateProperties?n.privateProperties.slaveId:n.$page?n.$page.id:void0}functionf(n){returnn.route||n.uri}functionp(n){returnn.options||n.$page&&n.$page.options||{}}functionl(n){return{id:s(n),path:f(n),query:p(n)}}functiond(n){vare=function(n){returngetCurrentPages().find((function(e){returns(e)===n}))}(n);returne&&e.$vm}functiong(n,e){vart=d(n);returnt&&functionn(e,t){varr;returne&&(!function(n,e){returnn.$scope&&((t=n.$scope).__wxExparserNodeId__||t.nodeId||t.id)===e;vart}(e,t)?e.$children.find((function(e){returnr=n(e,t)})):r=e),r}(t,e)}functionm(n,e){vart;returnn&&(t=e?function(n,e){vart,r=c(e,n);for(t=r.shift();null!=t;){if(null==(n=n[t]))return;t=r.shift()}returnn}(n.$data,e):Object.assign({},n.$data)),Promise.resolve({data:t})}functionv(n,e){returnn&&Object.keys(e).forEach((function(t){n[t]=e[t]})),Promise.resolve()}functionh(e,t,r){returnnewPromise((function(o,u){if(!e)returnu(n.VM_NOT_EXISTS);if(!e[t])returnu(n.VM_NOT_EXISTS);vari,a=e[t].apply(e,r);!(i=a)||"object"!=typeofi&&"function"!=typeofi||"function"!=typeofi.then?o({result:a}):a.then((function(n){o({result:n})}))}))}!function(n){n.VM_NOT_EXISTS="VM_NOT_EXISTS",n.METHOD_NOT_EXISTS="METHOD_NOT_EXISTS"}(n||(n={}));var_=/Sync$/;vary={getPageStack:function(){returnPromise.resolve({pageStack:getCurrentPages().map((function(n){returnl(n)}))})},getCurrentPage:function(){varn=getCurrentPages(),e=n.length;returnnewPromise((function(t,r){e?t(l(n[e-1])):r(Error("getCurrentPages().length=0"))}))},callUniMethod:function(n){vare=n.method,t=n.args;returnnewPromise((function(n,r){if(!uni[e])returnr(Error("uni."+e+" not exists"));if(function(n){return_.test(n)}(e))returnn({result:uni[e].apply(uni,t)});varo=[Object.assign({},t[0]||{},{success:function(t){setTimeout((function(){n({result:t})}),"pageScrollTo"===e?350:0)},fail:function(n){r(Error(n.errMsg.replace(e+":fail ","")))}})];uni[e].apply(uni,o)}))}},T={getData:function(n){returnm(d(n.pageId),n.path)},setData:function(n){returnv(d(n.pageId),n.data)},callMethod:function(e){vart,r=((t={})[n.VM_NOT_EXISTS]="Page["+e.pageId+"] not exists",t[n.METHOD_NOT_EXISTS]="page."+e.method+" not exists",t);returnnewPromise((function(n,t){h(d(e.pageId),e.method,e.args).then((function(e){returnn(e)})).catch((function(n){t(Error(r[n]))}))}))}};functionO(n){returnn.nodeId||n.elementId}for(varS={getData:function(n){returnm(g(n.pageId,O(n)),n.path)},setData:function(n){returnv(g(n.pageId,O(n)),n.data)},callMethod:function(e){vart,r=O(e),o=((t={})[n.VM_NOT_EXISTS]="Component["+e.pageId+":"+r+"] not exists",t[n.METHOD_NOT_EXISTS]="component."+e.method+" not exists",t);returnnewPromise((function(n,t){h(g(e.pageId,r),e.method,e.args).then((function(e){returnn(e)})).catch((function(n){t(Error(o[n]))}))}))}},E=("undefined"!=typeofcrypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeofmsCrypto&&"function"==typeofmsCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto),[]),I=0;I<256;++I)E[I]=(I+256).toString(16).substr(1);["movable-view","picker","ad","button","checkbox-group","checkbox","form","icon","label","movable-area","navigator","picker-view-column","picker-view","progress","radio-group","radio","rich-text","u-slider","swiper-item","swiper","switch"].map((function(n){returni(u(n))}));varb={};Object.keys(y).forEach((function(n){b["App."+n]=y[n]})),Object.keys(T).forEach((function(n){b["Page."+n]=T[n]})),Object.keys(S).forEach((function(n){b["Element."+n]=S[n]}));varw,P=process.env.UNI_AUTOMATOR_WS_ENDPOINT;function$(n){w.send({data:JSON.stringify(n)})}functionM(n){vare=JSON.parse(n.data),t=e.id,r=e.method,o=e.params,u={id:t},i=b[r];if(!i&&!i)returnu.error={message:r+" unimplemented"},$(u);try{i(o).then((function(n){n&&(u.result=n)})).catch((function(n){u.error={message:n.message}})).finally((function(){$(u)}))}catch(n){u.error={message:n.message},$(u)}}swan.$$initRuntimeAutomator=function(n){void0===n&&(n={}),(w=uni.connectSocket({url:P,complete:function(){}})).onMessage(M),w.onOpen((function(e){n.success&&n.success(),console.log("已开启自动化测试...")})),w.onError((function(n){console.log("automator.onError",n)})),w.onClose((function(){n.fail&&n.fail({errMsg:"$$initRuntimeAutomator:fail"}),console.log("automator.onClose")}))},setTimeout((function(){swan.$$initRuntimeAutomator()}),500);
vare,t=Object.prototype.hasOwnProperty,n=function(e){returnnull==e},r=Array.isArray,o=function(e){vart=Object.create(null);returnfunction(n){returnt[n]||(t[n]=e(n))}},a=/-(\w)/g,i=o((function(e){returne.replace(a,(function(e,t){returnt?t.toUpperCase():""}))})),u=o((function(e){returne.charAt(0).toUpperCase()+e.slice(1)})),c=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;functions(e,n){if(r(e))returne;if(n&&(o=n,a=e,t.call(o,a)))return[e];varo,a,i=[];returne.replace(c,(function(e,t,n,r){returni.push(n?r.replace(/\\(\\)?/g,"$1"):t||e),r})),i}functionf(e){returne.__wxWebviewId__?e.__wxWebviewId__:e.privateProperties?e.privateProperties.slaveId:e.$page?e.$page.id:void0}functionp(e){returne.route||e.uri}functiond(e){returne.options||e.$page&&e.$page.options||{}}functionl(e){return{id:f(e),path:p(e),query:d(e)}}functiong(e){vart=function(e){returngetCurrentPages().find((function(t){returnf(t)===e}))}(e);returnt&&t.$vm}functionm(e,t){varn=g(e);returnn&&functione(t,n){varr;returnt&&(!function(e,t){returne.$scope&&((n=e.$scope).__wxExparserNodeId__||n.nodeId||n.id)===t;varn}(t,n)?t.$children.find((function(t){returnr=e(t,n)})):r=t),r}(n,t)}functionv(e,t){varr;returne&&(r=t?function(e,t){varr,o=s(t,e);for(r=o.shift();!n(r);){if(null==(e=e[r]))return;r=o.shift()}returne}(e.$data,t):Object.assign({},e.$data)),Promise.resolve({data:r})}functionh(e,t){returne&&Object.keys(t).forEach((function(n){e[n]=t[n]})),Promise.resolve()}functionT(t,n,r){returnnewPromise((function(o,a){if(!t)returna(e.VM_NOT_EXISTS);if(!t[n])returna(e.VM_NOT_EXISTS);vari,u=t[n].apply(t,r);!(i=u)||"object"!=typeofi&&"function"!=typeofi||"function"!=typeofi.then?o({result:u}):u.then((function(e){o({result:e})}))}))}!function(e){e.VM_NOT_EXISTS="VM_NOT_EXISTS",e.METHOD_NOT_EXISTS="METHOD_NOT_EXISTS"}(e||(e={}));var_=["stopRecord","getRecorderManager","pauseVoice","stopVoice","pauseBackgroundAudio","stopBackgroundAudio","getBackgroundAudioManager","createAudioContext","createInnerAudioContext","createVideoContext","createCameraContext","createMapContext","canIUse","startAccelerometer","stopAccelerometer","startCompass","stopCompass","hideToast","hideLoading","showNavigationBarLoading","hideNavigationBarLoading","navigateBack","createAnimation","pageScrollTo","createSelectorQuery","createCanvasContext","createContext","drawCanvas","hideKeyboard","stopPullDownRefresh","arrayBufferToBase64","base64ToArrayBuffer"],y={},O=/Sync$/,S=/^on|^off/;functionE(e){returnO.test(e)||-1!==_.indexOf(e)}varI={getPageStack:function(){returnPromise.resolve({pageStack:getCurrentPages().map((function(e){returnl(e)}))})},getCurrentPage:function(){vare=getCurrentPages(),t=e.length;returnnewPromise((function(n,r){t?n(l(e[t-1])):r(Error("getCurrentPages().length=0"))}))},callUniMethod:function(e){vart=e.method,n=e.args;returnnewPromise((function(e,r){if(!uni[t])returnr(Error("uni."+t+" not exists"));if(E(t))returne({result:uni[t].apply(uni,n)});varo=[Object.assign({},n[0]||{},{success:function(n){setTimeout((function(){e({result:n})}),"pageScrollTo"===t?350:0)},fail:function(e){r(Error(e.errMsg.replace(t+":fail ","")))}})];uni[t].apply(uni,o)}))},mockUniMethod:function(e){vart=e.method;if(!uni[t])throwError("uni."+t+" not exists");if(!function(e){return!S.test(e)}(t))throwError("You can't mock uni."+t);varr=e.result;if(n(r))returny[t]&&(uni[t]=y[t],deletey[t]),Promise.resolve();varo=E(t)?function(){returnr}:function(e){setTimeout((function(){r.errMsg&&-1!==r.errMsg.indexOf(":fail")?e.fail&&e.fail(r):e.success&&e.success(r),e.complete&&e.complete(r)}),4)};returny[t]||(y[t]=uni[t]),uni[t]=o,Promise.resolve()}},C={getData:function(e){returnv(g(e.pageId),e.path)},setData:function(e){returnh(g(e.pageId),e.data)},callMethod:function(t){varn,r=((n={})[e.VM_NOT_EXISTS]="Page["+t.pageId+"] not exists",n[e.METHOD_NOT_EXISTS]="page."+t.method+" not exists",n);returnnewPromise((function(e,n){T(g(t.pageId),t.method,t.args).then((function(t){returne(t)})).catch((function(e){n(Error(r[e]))}))}))}};functionw(e){returne.nodeId||e.elementId}for(varM={getData:function(e){returnv(m(e.pageId,w(e)),e.path)},setData:function(e){returnh(m(e.pageId,w(e)),e.data)},callMethod:function(t){varn,r=w(t),o=((n={})[e.VM_NOT_EXISTS]="Component["+t.pageId+":"+r+"] not exists",n[e.METHOD_NOT_EXISTS]="component."+t.method+" not exists",n);returnnewPromise((function(e,n){T(m(t.pageId,r),t.method,t.args).then((function(t){returne(t)})).catch((function(e){n(Error(o[e]))}))}))}},P=("undefined"!=typeofcrypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeofmsCrypto&&"function"==typeofmsCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto),[]),b=0;b<256;++b)P[b]=(b+256).toString(16).substr(1);["movable-view","picker","ad","button","checkbox-group","checkbox","form","icon","label","movable-area","navigator","picker-view-column","picker-view","progress","radio-group","radio","rich-text","u-slider","swiper-item","swiper","switch"].map((function(e){returnu(i(e))}));varx={};Object.keys(I).forEach((function(e){x["App."+e]=I[e]})),Object.keys(C).forEach((function(e){x["Page."+e]=C[e]})),Object.keys(M).forEach((function(e){x["Element."+e]=M[e]}));var$,k=process.env.UNI_AUTOMATOR_WS_ENDPOINT;functionA(e){$.send({data:JSON.stringify(e)})}functionN(e){vart=JSON.parse(e.data),n=t.id,r=t.method,o=t.params,a={id:n},i=x[r];if(!i&&!i)returna.error={message:r+" unimplemented"},A(a);try{i(o).then((function(e){e&&(a.result=e)})).catch((function(e){a.error={message:e.message}})).finally((function(){A(a)}))}catch(e){a.error={message:e.message},A(a)}}swan.$$initRuntimeAutomator=function(e){void0===e&&(e={}),($=uni.connectSocket({url:k,complete:function(){}})).onMessage(N),$.onOpen((function(t){e.success&&e.success(),console.log("已开启自动化测试...")})),$.onError((function(e){console.log("automator.onError",e)})),$.onClose((function(){e.fail&&e.fail({errMsg:"$$initRuntimeAutomator:fail"}),console.log("automator.onClose")}))},setTimeout((function(){swan.$$initRuntimeAutomator()}),500);
"use strict";functione(e){returne&&"object"==typeofe&&"default"ine?e.default:e}vart=e(require("os")),r=e(require("path")),s=e(require("debug")),a=e(require("licia/isWindows")),n=e(require("fs")),o=e(require("child_process")),i=e(require("licia/sleep")),c=e(require("licia/toStr")),l=e(require("licia/waitUntil")),p=e(require("licia/concat")),u=e(require("licia/getPort")),m=e(require("licia/dateFormat"));require("address"),require("default-gateway"),require("jimp"),require("licia/isStr");vard=e(require("ws")),h=require("events"),f=e(require("licia/uuid")),g=e(require("licia/stringify"));constw=/(^[a-z][a-z0-9-]*)/i,y=/^navigator/i,E=/^swan-nav$/i;varb;!function(e){e.SELECTOR="selector",e.TAGNAME="tagName"}(b||(b={}));constv={[b.SELECTOR]:[{test:y,processor:e=>e.replace(y,"nav")},{test:w,processor:e=>"swan-"+e}],[b.TAGNAME]:[{test:E,processor:e=>e.replace(E,"swan-navigator")},{test:w,processor:e=>e.toLocaleLowerCase().replace("swan-","")}]},j=e=>t=>{constr=(v[e]||[]).filter(e=>e.test.test(t));for(consteofr)t=e.processor(t);returnt},P=j(b.SELECTOR),q=j(b.TAGNAME),O=e=>Object.assign({},e,{type:"id",info:{id:e.elementId}});require("qrcode-terminal"),require("qrcode-reader");classMextendsh.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()}}classCextendsh.EventEmitter{constructor(e,t,r){super(),this.puppet=t,this.namespace=r,this.callbacks=newMap,this.transport=e,this.debug=s("automator:protocol:"+this.namespace),this.onMessage=e=>{this.debug(`${m("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${e}`);const{id:t,method:r,error:s,result:a,params:n}=JSON.parse(e);if(!t)returnthis.puppet.emit(r,n);const{callbacks:o}=this;if(t&&o.has(t)){conste=o.get(t);o.delete(t),s?e.reject(Error(s.message)):e.resolve(a)}},this.onClose=()=>{this.callbacks.forEach(e=>{e.reject(Error("Connection closed"))})},this.transport.on("message",this.onMessage),this.transport.on("close",this.onClose)}send(e,t={},r=!0){if(r&&this.puppet.adapter.has(e))returnthis.puppet.adapter.send(this,e,t);consts=f(),a=g({id:s,method:e,params:t});returnthis.debug(`${m("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${a}`),newPromise((e,t)=>{try{this.transport.send(a)}catch(e){t(Error("Connection closed"))}this.callbacks.set(s,{resolve:e,reject:t})})}dispose(){this.transport.close()}staticcreateDevtoolConnection(e,t){returnnewPromise((r,s)=>{consta=newd(e);a.addEventListener("open",()=>{r(newC(newM(a),t,"devtool"))}),a.addEventListener("error",s)})}staticcreateRuntimeConnection(e,t,r){returnnewPromise((a,n)=>{s("automator:runtime")(`${m("yyyy-mm-dd HH:MM:ss:l")} port=${e}`);consto=newd.Server({port:e});l(async()=>{if(t.runtimeConnection)return!0},r,1e3).catch(e=>{throwError("Failed to connect to runtime, please make sure the project is running")}),o.on("connection",(function(e){s("automator:runtime")(m("yyyy-mm-dd HH:MM:ss:l")+" connected");constr=newC(newM(e),t,"runtime");t.setRuntimeConnection(r),a(r)})),t.setRuntimeServer(o)})}}const$=s("automator:devtool");asyncfunctionS(e,t,r){const{port:s,cliPath:a,timeout:n,cwd:u="",account:d="",args:h=[],launch:f=!0}=t;letg=!1,w=!1;if(!1!==f){constt={stdio:"ignore"};u&&(t.cwd=u);letr=p(h,[]);r=p(r,["--auto"]),r=p(r,[e,"--auto-port",c(s)]),d&&(r=p(r,["--auto-account",d]));try{$("%s %o %o",a,r,t);conste=o.spawn(a,r,t);e.on("error",e=>{g=!0}),e.on("exit",()=>{setTimeout(()=>{w=!0},15e3)}),e.unref()}catch(e){g=!1}}elsesetTimeout(()=>{w=!0},15e3);consty=awaitl(async()=>{try{if(g||w)return!0;returnawaitasyncfunction(e,t){letr;try{r=awaitC.createDevtoolConnection(e.wsEndpoint,t)}catch(t){throwError(`Failed connecting to ${e.wsEndpoint}, check if target project window is opened with automation enabled`)}returnr}({wsEndpoint:"ws://127.0.0.1:"+s},r)}catch(e){}},n,1e3);if(g)throwError(`Failed to launch ${r.devtools.name}, please make sure cliPath is correctly specified`);if(w)throwError(`Failed to launch ${r.devtools.name} , please make sure http port is open`);returnawaiti(5e3),$(m("yyyy-mm-dd HH:MM:ss:l")+" connected"),y}constA=[];["","-rc"].forEach(e=>{a?(A.push(r.join(t.homedir(),`AppData/Local/Programs/swan-ide-gui${e}/cli.bat`)),A.push(`C:/Program Files/swan-ide-gui${e}/cli.bat`)):A.push(`/Applications/百度开发者工具${e}.app/Contents/MacOS/cli`)});constT={devtools:{name:"Baidu DevTools",remote:!0,automator:!0,paths:A,required:["project.swan.json","app.json","app.js"],defaultPort:9430,validate:asyncfunction(e,t){constr=function(e,t){constr=t.devtools.paths.slice(0);e&&r.unshift(e);for(consteofr)if(n.existsSync(e))returne;throwError(t.devtools.name+" not found, please specify executablePath option")}(e.executablePath,t);lets=e.port||t.devtools.defaultPort;if(!1!==e.launch)try{s=awaitasyncfunction(e,t){constr=awaitu(e||t);if(e&&r!==e)throwError(`Port ${e} is in use, please specify another port`);returnr}(s)}catch(t){e.launch=!1}else{s===awaitu(s)&&(e.launch=!0)}returnObject.assign(Object.assign({},e),{port:s,cliPath:r})},asynccreate(e,t,r){consta=awaitS(e,t,r);returns("automator:devtool")("initRuntimeAutomator"),a.send("smartapp.swan",{api:"$$initRuntimeAutomator",params:[]}),a}},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:(r=t.selector,r.split("").map(e=>P(e)).join(""))}))).map(e=>{constt=e.properties;return{elementId:t.id,nodeId:t.id,tagName:q(t.tagName)}})};varr}},"Page.getWindowProperties":{reflect:async(e,t)=>{constr=t.names.map(e=>e.replace("document.documentElement.","")),s=(awaite("smartapp.element.getBySelector",{properties:r,selector:"html"}))[0];return{properties:r.map(e=>s.properties[e])}}},"Element.getHTML":{reflect:async(e,t)=>{constr=[t.type+"HTML"];return{html:(awaite("Element.getDOMProperties",Object.assign(Object.assign({},t),{names:r}))).properties[0]}}},"Element.getElement":{reflect:async(e,t)=>(awaite("Element.getElements",t)).elements[0]},"Element.getElements":{reflect:async(e,t)=>{const{elements:r}=awaite("Page.getElements",Object.assign(Object.assign({},t),{selector:`#${t.elementId}${t.selector}`}));returnr.forEach(e=>{e.nodeId=e.id}),{elements:r}}},"Element.getAttributes":{reflect:async(e,t)=>{constr=[];for(constsoft.names)r.push(awaite("smartapp.element.getAttribute",Object.assign({attribute:s},t)));return{attributes:r}},params:O},"Element.getStyles":{reflect:async(e,t)=>{constr=[];for(constsoft.names)r.push(awaite("smartapp.element.getComputedStyle",Object.assign({style:s},t)));return{styles:r}},params:O},"Element.getDOMProperties":{reflect:async(e,t)=>{constr=[];for(constsoft.names)r.push(awaite("smartapp.element.getProperty",Object.assign({property:s},t)));return{properties:r}},params:O},"Element.getProperties":{reflect:async(e,t)=>{constr=[];for(constsoft.names)r.push(awaite("smartapp.element.getAttribute",Object.assign({attribute:s},t)));return{properties:r}},params:O},"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:O},"Element.tap":{reflect:"smartapp.element.touch",params:O}}};module.exports=T;
"use strict";functione(e){returne&&"object"==typeofe&&"default"ine?e.default:e}vart=e(require("os")),r=e(require("path")),s=e(require("debug")),a=e(require("licia/isWindows")),n=e(require("fs")),o=e(require("child_process")),i=e(require("licia/sleep")),c=e(require("licia/toStr")),l=e(require("licia/waitUntil")),p=e(require("licia/concat")),u=e(require("licia/getPort")),m=e(require("licia/dateFormat"));require("address"),require("default-gateway"),require("jimp"),require("licia/isStr");vard=e(require("ws")),h=require("events"),f=e(require("licia/uuid")),g=e(require("licia/stringify"));constw=/(^[a-z][a-z0-9-]*)/i,y=/^navigator/i,E=/^swan-nav$/i;varb;!function(e){e.SELECTOR="selector",e.TAGNAME="tagName"}(b||(b={}));constv={[b.SELECTOR]:[{test:y,processor:e=>e.replace(y,"nav")},{test:w,processor:e=>"swan-"+e}],[b.TAGNAME]:[{test:E,processor:e=>e.replace(E,"swan-navigator")},{test:w,processor:e=>e.toLocaleLowerCase().replace("swan-","")}]},j=e=>t=>{constr=(v[e]||[]).filter(e=>e.test.test(t));for(consteofr)t=e.processor(t);returnt},P=j(b.SELECTOR),q=j(b.TAGNAME),O=e=>Object.assign({},e,{type:"id",info:{id:e.elementId}});require("qrcode-terminal"),require("qrcode-reader");classMextendsh.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()}}classCextendsh.EventEmitter{constructor(e,t,r){super(),this.puppet=t,this.namespace=r,this.callbacks=newMap,this.transport=e,this.debug=s("automator:protocol:"+this.namespace),this.onMessage=e=>{this.debug(`${m("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${e}`);const{id:t,method:r,error:s,result:a,params:n}=JSON.parse(e);if(!t)returnthis.puppet.emit(r,n);const{callbacks:o}=this;if(t&&o.has(t)){conste=o.get(t);o.delete(t),s?e.reject(Error(s.message)):e.resolve(a)}},this.onClose=()=>{this.callbacks.forEach(e=>{e.reject(Error("Connection closed"))})},this.transport.on("message",this.onMessage),this.transport.on("close",this.onClose)}send(e,t={},r=!0){if(r&&this.puppet.adapter.has(e))returnthis.puppet.adapter.send(this,e,t);consts=f(),a=g({id:s,method:e,params:t});returnthis.debug(`${m("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${a}`),newPromise((e,t)=>{try{this.transport.send(a)}catch(e){t(Error("Connection closed"))}this.callbacks.set(s,{resolve:e,reject:t})})}dispose(){this.transport.close()}staticcreateDevtoolConnection(e,t){returnnewPromise((r,s)=>{consta=newd(e);a.addEventListener("open",()=>{r(newC(newM(a),t,"devtool"))}),a.addEventListener("error",s)})}staticcreateRuntimeConnection(e,t,r){returnnewPromise((a,n)=>{s("automator:runtime")(`${m("yyyy-mm-dd HH:MM:ss:l")} port=${e}`);consto=newd.Server({port:e});l(async()=>{if(t.runtimeConnection)return!0},r,1e3).catch(e=>{throwError("Failed to connect to runtime, please make sure the project is running")}),o.on("connection",(function(e){s("automator:runtime")(m("yyyy-mm-dd HH:MM:ss:l")+" connected");constr=newC(newM(e),t,"runtime");t.setRuntimeConnection(r),a(r)})),t.setRuntimeServer(o)})}}const$=s("automator:devtool");asyncfunctionS(e,t,r){const{port:s,cliPath:a,timeout:n,cwd:u="",account:d="",args:h=[],launch:f=!0}=t;letg=!1,w=!1;if(!1!==f){constt={stdio:"ignore"};u&&(t.cwd=u);letr=p(h,[]);r=p(r,["--auto"]),r=p(r,[e,"--auto-port",c(s)]),d&&(r=p(r,["--auto-account",d]));try{$("%s %o %o",a,r,t);conste=o.spawn(a,r,t);e.on("error",e=>{g=!0}),e.on("exit",()=>{setTimeout(()=>{w=!0},15e3)}),e.unref()}catch(e){g=!1}}elsesetTimeout(()=>{w=!0},15e3);consty=awaitl(async()=>{try{if(g||w)return!0;returnawaitasyncfunction(e,t){letr;try{r=awaitC.createDevtoolConnection(e.wsEndpoint,t)}catch(t){throwError(`Failed connecting to ${e.wsEndpoint}, check if target project window is opened with automation enabled`)}returnr}({wsEndpoint:"ws://127.0.0.1:"+s},r)}catch(e){}},n,1e3);if(g)throwError(`Failed to launch ${r.devtools.name}, please make sure cliPath is correctly specified`);if(w)throwError(`Failed to launch ${r.devtools.name} , please make sure http port is open`);returnawaiti(5e3),$(m("yyyy-mm-dd HH:MM:ss:l")+" connected"),y}constA=[];["","-rc"].forEach(e=>{a?(A.push(r.join(t.homedir(),`AppData/Local/Programs/swan-ide-gui${e}/cli.bat`)),A.push(`C:/Program Files/swan-ide-gui${e}/cli.bat`)):A.push(`/Applications/百度开发者工具${e}.app/Contents/MacOS/cli`)});constT={devtools:{name:"Baidu DevTools",remote:!0,automator:!0,paths:A,required:["project.swan.json","app.json","app.js"],defaultPort:9430,validate:asyncfunction(e,t){constr=function(e,t){constr=t.devtools.paths.slice(0);e&&r.unshift(e);for(consteofr)if(n.existsSync(e))returne;throwError(t.devtools.name+" not found, please specify executablePath option")}(e.executablePath,t);lets=e.port||t.devtools.defaultPort;if(!1!==e.launch)try{s=awaitasyncfunction(e,t){constr=awaitu(e||t);if(e&&r!==e)throwError(`Port ${e} is in use, please specify another port`);returnr}(s)}catch(t){e.launch=!1}else{s===awaitu(s)&&(e.launch=!0)}returnObject.assign(Object.assign({},e),{port:s,cliPath:r})},asynccreate(e,t,r){consta=awaitS(e,t,r);returnr.compiled?s("automator:devtool")("Waiting for runtime automator"):(s("automator:devtool")("initRuntimeAutomator"),a.send("smartapp.swan",{api:"$$initRuntimeAutomator",params:[]})),a}},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:(r=t.selector,r.split("").map(e=>P(e)).join(""))}))).map(e=>{constt=e.properties;return{elementId:t.id,nodeId:t.id,tagName:q(t.tagName)}})};varr}},"Page.getWindowProperties":{reflect:async(e,t)=>{constr=t.names.map(e=>e.replace("document.documentElement.","")),s=(awaite("smartapp.element.getBySelector",{properties:r,selector:"html"}))[0];return{properties:r.map(e=>s.properties[e])}}},"Element.getHTML":{reflect:async(e,t)=>{constr=[t.type+"HTML"];return{html:(awaite("Element.getDOMProperties",Object.assign(Object.assign({},t),{names:r}))).properties[0]}}},"Element.getElement":{reflect:async(e,t)=>(awaite("Element.getElements",t)).elements[0]},"Element.getElements":{reflect:async(e,t)=>{const{elements:r}=awaite("Page.getElements",Object.assign(Object.assign({},t),{selector:`#${t.elementId}${t.selector}`}));returnr.forEach(e=>{e.nodeId=e.id}),{elements:r}}},"Element.getAttributes":{reflect:async(e,t)=>{constr=[];for(constsoft.names)r.push(awaite("smartapp.element.getAttribute",Object.assign({attribute:s},t)));return{attributes:r}},params:O},"Element.getStyles":{reflect:async(e,t)=>{constr=[];for(constsoft.names)r.push(awaite("smartapp.element.getComputedStyle",Object.assign({style:s},t)));return{styles:r}},params:O},"Element.getDOMProperties":{reflect:async(e,t)=>{constr=[];for(constsoft.names)r.push(awaite("smartapp.element.getProperty",Object.assign({property:s},t)));return{properties:r}},params:O},"Element.getProperties":{reflect:async(e,t)=>{constr=[];for(constsoft.names)r.push(awaite("smartapp.element.getAttribute",Object.assign({attribute:s},t)));return{properties:r}},params:O},"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:O},"Element.tap":{reflect:"smartapp.element.touch",params:O}}};module.exports=T;
varn,e=Object.prototype.hasOwnProperty,t=Array.isArray,r=function(n){vare=Object.create(null);returnfunction(t){returne[t]||(e[t]=n(t))}},o=/-(\w)/g,u=r((function(n){returnn.replace(o,(function(n,e){returne?e.toUpperCase():""}))})),i=r((function(n){returnn.charAt(0).toUpperCase()+n.slice(1)})),a=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;functionc(n,r){if(t(n))returnn;if(r&&(o=r,u=n,e.call(o,u)))return[n];varo,u,i=[];returnn.replace(a,(function(n,e,t,r){returni.push(t?r.replace(/\\(\\)?/g,"$1"):e||n),r})),i}functions(n){returnn.__wxWebviewId__?n.__wxWebviewId__:n.privateProperties?n.privateProperties.slaveId:n.$page?n.$page.id:void0}functionf(n){returnn.route||n.uri}functionp(n){returnn.options||n.$page&&n.$page.options||{}}functionl(n){return{id:s(n),path:f(n),query:p(n)}}functiond(n){vare=function(n){returngetCurrentPages().find((function(e){returns(e)===n}))}(n);returne&&e.$vm}functiong(n,e){vart=d(n);returnt&&functionn(e,t){varr;returne&&(!function(n,e){returnn.$scope&&((t=n.$scope).__wxExparserNodeId__||t.nodeId||t.id)===e;vart}(e,t)?e.$children.find((function(e){returnr=n(e,t)})):r=e),r}(t,e)}functionm(n,e){vart;returnn&&(t=e?function(n,e){vart,r=c(e,n);for(t=r.shift();null!=t;){if(null==(n=n[t]))return;t=r.shift()}returnn}(n.$data,e):Object.assign({},n.$data)),Promise.resolve({data:t})}functionv(n,e){returnn&&Object.keys(e).forEach((function(t){n[t]=e[t]})),Promise.resolve()}functionh(e,t,r){returnnewPromise((function(o,u){if(!e)returnu(n.VM_NOT_EXISTS);if(!e[t])returnu(n.VM_NOT_EXISTS);vari,a=e[t].apply(e,r);!(i=a)||"object"!=typeofi&&"function"!=typeofi||"function"!=typeofi.then?o({result:a}):a.then((function(n){o({result:n})}))}))}!function(n){n.VM_NOT_EXISTS="VM_NOT_EXISTS",n.METHOD_NOT_EXISTS="METHOD_NOT_EXISTS"}(n||(n={}));var_=/Sync$/;vary={getPageStack:function(){returnPromise.resolve({pageStack:getCurrentPages().map((function(n){returnl(n)}))})},getCurrentPage:function(){varn=getCurrentPages(),e=n.length;returnnewPromise((function(t,r){e?t(l(n[e-1])):r(Error("getCurrentPages().length=0"))}))},callUniMethod:function(n){vare=n.method,t=n.args;returnnewPromise((function(n,r){if(!uni[e])returnr(Error("uni."+e+" not exists"));if(function(n){return_.test(n)}(e))returnn({result:uni[e].apply(uni,t)});varo=[Object.assign({},t[0]||{},{success:function(t){setTimeout((function(){n({result:t})}),"pageScrollTo"===e?350:0)},fail:function(n){r(Error(n.errMsg.replace(e+":fail ","")))}})];uni[e].apply(uni,o)}))}},T={getData:function(n){returnm(d(n.pageId),n.path)},setData:function(n){returnv(d(n.pageId),n.data)},callMethod:function(e){vart,r=((t={})[n.VM_NOT_EXISTS]="Page["+e.pageId+"] not exists",t[n.METHOD_NOT_EXISTS]="page."+e.method+" not exists",t);returnnewPromise((function(n,t){h(d(e.pageId),e.method,e.args).then((function(e){returnn(e)})).catch((function(n){t(Error(r[n]))}))}))}};functionO(n){returnn.nodeId||n.elementId}for(varS={getData:function(n){returnm(g(n.pageId,O(n)),n.path)},setData:function(n){returnv(g(n.pageId,O(n)),n.data)},callMethod:function(e){vart,r=O(e),o=((t={})[n.VM_NOT_EXISTS]="Component["+e.pageId+":"+r+"] not exists",t[n.METHOD_NOT_EXISTS]="component."+e.method+" not exists",t);returnnewPromise((function(n,t){h(g(e.pageId,r),e.method,e.args).then((function(e){returnn(e)})).catch((function(n){t(Error(o[n]))}))}))}},E=("undefined"!=typeofcrypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeofmsCrypto&&"function"==typeofmsCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto),[]),I=0;I<256;++I)E[I]=(I+256).toString(16).substr(1);["movable-view","picker","ad","button","checkbox-group","checkbox","form","icon","label","movable-area","navigator","picker-view-column","picker-view","progress","radio-group","radio","rich-text","u-slider","swiper-item","swiper","switch"].map((function(n){returni(u(n))}));varb={};Object.keys(y).forEach((function(n){b["App."+n]=y[n]})),Object.keys(T).forEach((function(n){b["Page."+n]=T[n]})),Object.keys(S).forEach((function(n){b["Element."+n]=S[n]}));varw,P=process.env.UNI_AUTOMATOR_WS_ENDPOINT;function$(n){w.send({data:JSON.stringify(n)})}functionM(n){vare=JSON.parse(n.data),t=e.id,r=e.method,o=e.params,u={id:t},i=b[r];if(!i&&!i)returnu.error={message:r+" unimplemented"},$(u);try{i(o).then((function(n){n&&(u.result=n)})).catch((function(n){u.error={message:n.message}})).finally((function(){$(u)}))}catch(n){u.error={message:n.message},$(u)}}wx.$$initRuntimeAutomator=function(n){void0===n&&(n={}),(w=uni.connectSocket({url:P,complete:function(){}})).onMessage(M),w.onOpen((function(e){n.success&&n.success(),console.log("已开启自动化测试...")})),w.onError((function(n){console.log("automator.onError",n)})),w.onClose((function(){n.fail&&n.fail({errMsg:"$$initRuntimeAutomator:fail"}),console.log("automator.onClose")}))},setTimeout((function(){wx.$$initRuntimeAutomator()}),500);
vare,t=Object.prototype.hasOwnProperty,n=function(e){returnnull==e},r=Array.isArray,o=function(e){vart=Object.create(null);returnfunction(n){returnt[n]||(t[n]=e(n))}},i=/-(\w)/g,a=o((function(e){returne.replace(i,(function(e,t){returnt?t.toUpperCase():""}))})),u=o((function(e){returne.charAt(0).toUpperCase()+e.slice(1)})),c=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;functions(e,n){if(r(e))returne;if(n&&(o=n,i=e,t.call(o,i)))return[e];varo,i,a=[];returne.replace(c,(function(e,t,n,r){returna.push(n?r.replace(/\\(\\)?/g,"$1"):t||e),r})),a}functionf(e){returne.__wxWebviewId__?e.__wxWebviewId__:e.privateProperties?e.privateProperties.slaveId:e.$page?e.$page.id:void0}functionp(e){returne.route||e.uri}functiond(e){returne.options||e.$page&&e.$page.options||{}}functionl(e){return{id:f(e),path:p(e),query:d(e)}}functiong(e){vart=function(e){returngetCurrentPages().find((function(t){returnf(t)===e}))}(e);returnt&&t.$vm}functionm(e,t){varn=g(e);returnn&&functione(t,n){varr;returnt&&(!function(e,t){returne.$scope&&((n=e.$scope).__wxExparserNodeId__||n.nodeId||n.id)===t;varn}(t,n)?t.$children.find((function(t){returnr=e(t,n)})):r=t),r}(n,t)}functionv(e,t){varr;returne&&(r=t?function(e,t){varr,o=s(t,e);for(r=o.shift();!n(r);){if(null==(e=e[r]))return;r=o.shift()}returne}(e.$data,t):Object.assign({},e.$data)),Promise.resolve({data:r})}functionh(e,t){returne&&Object.keys(t).forEach((function(n){e[n]=t[n]})),Promise.resolve()}functionT(t,n,r){returnnewPromise((function(o,i){if(!t)returni(e.VM_NOT_EXISTS);if(!t[n])returni(e.VM_NOT_EXISTS);vara,u=t[n].apply(t,r);!(a=u)||"object"!=typeofa&&"function"!=typeofa||"function"!=typeofa.then?o({result:u}):u.then((function(e){o({result:e})}))}))}!function(e){e.VM_NOT_EXISTS="VM_NOT_EXISTS",e.METHOD_NOT_EXISTS="METHOD_NOT_EXISTS"}(e||(e={}));var_=["stopRecord","getRecorderManager","pauseVoice","stopVoice","pauseBackgroundAudio","stopBackgroundAudio","getBackgroundAudioManager","createAudioContext","createInnerAudioContext","createVideoContext","createCameraContext","createMapContext","canIUse","startAccelerometer","stopAccelerometer","startCompass","stopCompass","hideToast","hideLoading","showNavigationBarLoading","hideNavigationBarLoading","navigateBack","createAnimation","pageScrollTo","createSelectorQuery","createCanvasContext","createContext","drawCanvas","hideKeyboard","stopPullDownRefresh","arrayBufferToBase64","base64ToArrayBuffer"],y={},O=/Sync$/,S=/^on|^off/;functionE(e){returnO.test(e)||-1!==_.indexOf(e)}varI={getPageStack:function(){returnPromise.resolve({pageStack:getCurrentPages().map((function(e){returnl(e)}))})},getCurrentPage:function(){vare=getCurrentPages(),t=e.length;returnnewPromise((function(n,r){t?n(l(e[t-1])):r(Error("getCurrentPages().length=0"))}))},callUniMethod:function(e){vart=e.method,n=e.args;returnnewPromise((function(e,r){if(!uni[t])returnr(Error("uni."+t+" not exists"));if(E(t))returne({result:uni[t].apply(uni,n)});varo=[Object.assign({},n[0]||{},{success:function(n){setTimeout((function(){e({result:n})}),"pageScrollTo"===t?350:0)},fail:function(e){r(Error(e.errMsg.replace(t+":fail ","")))}})];uni[t].apply(uni,o)}))},mockUniMethod:function(e){vart=e.method;if(!uni[t])throwError("uni."+t+" not exists");if(!function(e){return!S.test(e)}(t))throwError("You can't mock uni."+t);varr=e.result;if(n(r))returny[t]&&(uni[t]=y[t],deletey[t]),Promise.resolve();varo=E(t)?function(){returnr}:function(e){setTimeout((function(){r.errMsg&&-1!==r.errMsg.indexOf(":fail")?e.fail&&e.fail(r):e.success&&e.success(r),e.complete&&e.complete(r)}),4)};returny[t]||(y[t]=uni[t]),uni[t]=o,Promise.resolve()}},C={getData:function(e){returnv(g(e.pageId),e.path)},setData:function(e){returnh(g(e.pageId),e.data)},callMethod:function(t){varn,r=((n={})[e.VM_NOT_EXISTS]="Page["+t.pageId+"] not exists",n[e.METHOD_NOT_EXISTS]="page."+t.method+" not exists",n);returnnewPromise((function(e,n){T(g(t.pageId),t.method,t.args).then((function(t){returne(t)})).catch((function(e){n(Error(r[e]))}))}))}};functionw(e){returne.nodeId||e.elementId}for(varx={getData:function(e){returnv(m(e.pageId,w(e)),e.path)},setData:function(e){returnh(m(e.pageId,w(e)),e.data)},callMethod:function(t){varn,r=w(t),o=((n={})[e.VM_NOT_EXISTS]="Component["+t.pageId+":"+r+"] not exists",n[e.METHOD_NOT_EXISTS]="component."+t.method+" not exists",n);returnnewPromise((function(e,n){T(m(t.pageId,r),t.method,t.args).then((function(t){returne(t)})).catch((function(e){n(Error(o[e]))}))}))}},M=("undefined"!=typeofcrypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeofmsCrypto&&"function"==typeofmsCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto),[]),P=0;P<256;++P)M[P]=(P+256).toString(16).substr(1);["movable-view","picker","ad","button","checkbox-group","checkbox","form","icon","label","movable-area","navigator","picker-view-column","picker-view","progress","radio-group","radio","rich-text","u-slider","swiper-item","swiper","switch"].map((function(e){returnu(a(e))}));varb={};Object.keys(I).forEach((function(e){b["App."+e]=I[e]})),Object.keys(C).forEach((function(e){b["Page."+e]=C[e]})),Object.keys(x).forEach((function(e){b["Element."+e]=x[e]}));var$,k=process.env.UNI_AUTOMATOR_WS_ENDPOINT;functionA(e){$.send({data:JSON.stringify(e)})}functionN(e){vart=JSON.parse(e.data),n=t.id,r=t.method,o=t.params,i={id:n},a=b[r];if(!a&&!a)returni.error={message:r+" unimplemented"},A(i);try{a(o).then((function(e){e&&(i.result=e)})).catch((function(e){i.error={message:e.message}})).finally((function(){A(i)}))}catch(e){i.error={message:e.message},A(i)}}wx.$$initRuntimeAutomator=function(e){void0===e&&(e={}),($=uni.connectSocket({url:k,complete:function(){}})).onMessage(N),$.onOpen((function(t){e.success&&e.success(),console.log("已开启自动化测试...")})),$.onError((function(e){console.log("automator.onError",e)})),$.onClose((function(){e.fail&&e.fail({errMsg:"$$initRuntimeAutomator:fail"}),console.log("automator.onClose")}))},setTimeout((function(){wx.$$initRuntimeAutomator()}),500);
"use strict";functione(e){returne&&"object"==typeofe&&"default"ine?e.default:e}vart=e(require("debug")),r=e(require("licia/isWindows"));require("address"),require("default-gateway");varn=e(require("jimp"));require("licia/isStr");varo=e(require("licia/getPort")),s=e(require("fs")),a=e(require("child_process")),i=e(require("licia/sleep")),c=e(require("licia/toStr")),u=e(require("licia/waitUntil")),l=e(require("licia/concat")),d=e(require("licia/dateFormat")),p=e(require("ws")),h=require("events"),m=e(require("licia/uuid")),w=e(require("licia/stringify"));require("qrcode-terminal");constf=require("qrcode-reader");classyextendsh.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()}}classgextendsh.EventEmitter{constructor(e,r,n){super(),this.puppet=r,this.namespace=n,this.callbacks=newMap,this.transport=e,this.debug=t("automator:protocol:"+this.namespace),this.onMessage=e=>{this.debug(`${d("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${e}`);const{id:t,method:r,error:n,result:o,params:s}=JSON.parse(e);if(!t)returnthis.puppet.emit(r,s);const{callbacks:a}=this;if(t&&a.has(t)){conste=a.get(t);a.delete(t),n?e.reject(Error(n.message)):e.resolve(o)}},this.onClose=()=>{this.callbacks.forEach(e=>{e.reject(Error("Connection closed"))})},this.transport.on("message",this.onMessage),this.transport.on("close",this.onClose)}send(e,t={},r=!0){if(r&&this.puppet.adapter.has(e))returnthis.puppet.adapter.send(this,e,t);constn=m(),o=w({id:n,method:e,params:t});returnthis.debug(`${d("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${o}`),newPromise((e,t)=>{try{this.transport.send(o)}catch(e){t(Error("Connection closed"))}this.callbacks.set(n,{resolve:e,reject:t})})}dispose(){this.transport.close()}staticcreateDevtoolConnection(e,t){returnnewPromise((r,n)=>{consto=newp(e);o.addEventListener("open",()=>{r(newg(newy(o),t,"devtool"))}),o.addEventListener("error",n)})}staticcreateRuntimeConnection(e,r,n){returnnewPromise((o,s)=>{t("automator:runtime")(`${d("yyyy-mm-dd HH:MM:ss:l")} port=${e}`);consta=newp.Server({port:e});u(async()=>{if(r.runtimeConnection)return!0},n,1e3).catch(e=>{throwError("Failed to connect to runtime, please make sure the project is running")}),a.on("connection",(function(e){t("automator:runtime")(d("yyyy-mm-dd HH:MM:ss:l")+" connected");constn=newg(newy(e),r,"runtime");r.setRuntimeConnection(n),o(n)})),r.setRuntimeServer(a)})}}constv=t("automator:devtool");asyncfunctionb(e,t,r){const{port:n,cliPath:o,timeout:s,cwd:p="",account:h="",args:m=[],launch:w=!0}=t;letf=!1,y=!1;if(!1!==w){constt={stdio:"ignore",detached:!0};p&&(t.cwd=p);letr=l(m,[]);r=l(r,["auto","--project"]),r=l(r,[e,"--auto-port",c(n)]),h&&(r=l(r,["--auto-account",h]));try{v("%s %o %o",o,r,t);conste=a.spawn(o,r,t);e.on("error",e=>{f=!0}),e.on("exit",()=>{setTimeout(()=>{y=!0},15e3)}),e.unref()}catch(e){f=!1}}elsesetTimeout(()=>{y=!0},15e3);constb=awaitu(async()=>{try{if(f||y)return!0;returnawaitasyncfunction(e,t){letr;try{r=awaitg.createDevtoolConnection(e.wsEndpoint,t)}catch(t){throwError(`Failed connecting to ${e.wsEndpoint}, check if target project window is opened with automation enabled`)}returnr}({wsEndpoint:"ws://127.0.0.1:"+n},r)}catch(e){}},s,1e3);if(f)throwError(`Failed to launch ${r.devtools.name}, please make sure cliPath is correctly specified`);if(y)throwError(`Failed to launch ${r.devtools.name} , please make sure http port is open`);returnawaiti(5e3),v(d("yyyy-mm-dd HH:MM:ss:l")+" connected"),b}constq={devtools:{name:"Wechat web devTools",remote:!0,automator:!0,paths:[r?"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){constr=function(e,t){constr=t.devtools.paths.slice(0);e&&r.unshift(e);for(consteofr)if(s.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){constr=awaito(e||t);if(e&&r!==e)throwError(`Port ${e} is in use, please specify another port`);returnr}(n)}catch(t){e.launch=!1}else{n===awaito(n)&&(e.launch=!0)}returnObject.assign(Object.assign({},e),{port:n,cliPath:r})},asynccreate(e,r,n){consto=awaitb(e,r,n);returnt("automator:devtool")("initRuntimeAutomator"),o.send("App.callWxMethod",{method:"$$initRuntimeAutomator",args:[]}),o}},adapter:{"Tool.enableRemoteDebug":{reflect:async(e,t)=>{let{qrCode:r}=awaite("Tool.enableRemoteDebug",t,!1);returnr&&(r=awaitfunction(e){constt=newBuffer(e,"base64");returnnewPromise(async(e,r)=>{consto=awaitn.read(t),s=newf;s.callback=function(t,n){if(t)returnr(t);e(n.result)},s.decode(o.bitmap)})}(r)),{qrCode:r}}},"App.callFunction":{reflect:async(e,t)=>{returne("App.callFunction",Object.assign(Object.assign({},t),{functionDeclaration:(r=t.functionDeclaration,"}"===r[r.length-1]?r.replace("{","{\nvar uni = wx;\n"):r.replace("=>","=>{\nvar uni = wx;\nreturn ")+"}")}),!1);varr}},"Element.getHTML":{reflect:async(e,t)=>({html:(awaite("Element.getWXML",t,!1)).wxml})}}};module.exports=q;
"use strict";functione(e){returne&&"object"==typeofe&&"default"ine?e.default:e}vart=e(require("debug")),r=e(require("licia/isWindows"));require("address"),require("default-gateway");varo=e(require("jimp"));require("licia/isStr");varn=e(require("licia/getPort")),s=e(require("fs")),a=e(require("child_process")),i=e(require("licia/sleep")),c=e(require("licia/toStr")),u=e(require("licia/waitUntil")),l=e(require("licia/concat")),d=e(require("licia/dateFormat")),p=e(require("ws")),m=require("events"),h=e(require("licia/uuid")),w=e(require("licia/stringify"));require("qrcode-terminal");constf=require("qrcode-reader");classyextendsm.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()}}classgextendsm.EventEmitter{constructor(e,r,o){super(),this.puppet=r,this.namespace=o,this.callbacks=newMap,this.transport=e,this.debug=t("automator:protocol:"+this.namespace),this.onMessage=e=>{this.debug(`${d("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${e}`);const{id:t,method:r,error:o,result:n,params:s}=JSON.parse(e);if(!t)returnthis.puppet.emit(r,s);const{callbacks:a}=this;if(t&&a.has(t)){conste=a.get(t);a.delete(t),o?e.reject(Error(o.message)):e.resolve(n)}},this.onClose=()=>{this.callbacks.forEach(e=>{e.reject(Error("Connection closed"))})},this.transport.on("message",this.onMessage),this.transport.on("close",this.onClose)}send(e,t={},r=!0){if(r&&this.puppet.adapter.has(e))returnthis.puppet.adapter.send(this,e,t);consto=h(),n=w({id:o,method:e,params:t});returnthis.debug(`${d("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${n}`),newPromise((e,t)=>{try{this.transport.send(n)}catch(e){t(Error("Connection closed"))}this.callbacks.set(o,{resolve:e,reject:t})})}dispose(){this.transport.close()}staticcreateDevtoolConnection(e,t){returnnewPromise((r,o)=>{constn=newp(e);n.addEventListener("open",()=>{r(newg(newy(n),t,"devtool"))}),n.addEventListener("error",o)})}staticcreateRuntimeConnection(e,r,o){returnnewPromise((n,s)=>{t("automator:runtime")(`${d("yyyy-mm-dd HH:MM:ss:l")} port=${e}`);consta=newp.Server({port:e});u(async()=>{if(r.runtimeConnection)return!0},o,1e3).catch(e=>{throwError("Failed to connect to runtime, please make sure the project is running")}),a.on("connection",(function(e){t("automator:runtime")(d("yyyy-mm-dd HH:MM:ss:l")+" connected");consto=newg(newy(e),r,"runtime");r.setRuntimeConnection(o),n(o)})),r.setRuntimeServer(a)})}}constv=t("automator:devtool");asyncfunctionb(e,t,r){const{port:o,cliPath:n,timeout:s,cwd:p="",account:m="",args:h=[],launch:w=!0}=t;letf=!1,y=!1;if(!1!==w){constt={stdio:"ignore",detached:!0};p&&(t.cwd=p);letr=l(h,[]);r=l(r,["auto","--project"]),r=l(r,[e,"--auto-port",c(o)]),m&&(r=l(r,["--auto-account",m]));try{v("%s %o %o",n,r,t);conste=a.spawn(n,r,t);e.on("error",e=>{f=!0}),e.on("exit",()=>{setTimeout(()=>{y=!0},15e3)}),e.unref()}catch(e){f=!1}}elsesetTimeout(()=>{y=!0},15e3);constb=awaitu(async()=>{try{if(f||y)return!0;returnawaitasyncfunction(e,t){letr;try{r=awaitg.createDevtoolConnection(e.wsEndpoint,t)}catch(t){throwError(`Failed connecting to ${e.wsEndpoint}, check if target project window is opened with automation enabled`)}returnr}({wsEndpoint:"ws://127.0.0.1:"+o},r)}catch(e){}},s,1e3);if(f)throwError(`Failed to launch ${r.devtools.name}, please make sure cliPath is correctly specified`);if(y)throwError(`Failed to launch ${r.devtools.name} , please make sure http port is open`);returnawaiti(5e3),v(d("yyyy-mm-dd HH:MM:ss:l")+" connected"),b}constq={devtools:{name:"Wechat web devTools",remote:!0,automator:!0,paths:[r?"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){constr=function(e,t){constr=t.devtools.paths.slice(0);e&&r.unshift(e);for(consteofr)if(s.existsSync(e))returne;throwError(t.devtools.name+" not found, please specify executablePath option")}(e.executablePath,t);leto=e.port||t.devtools.defaultPort;if(!1!==e.launch)try{o=awaitasyncfunction(e,t){constr=awaitn(e||t);if(e&&r!==e)throwError(`Port ${e} is in use, please specify another port`);returnr}(o)}catch(t){e.launch=!1}else{o===awaitn(o)&&(e.launch=!0)}returnObject.assign(Object.assign({},e),{port:o,cliPath:r})},asynccreate(e,r,o){constn=awaitb(e,r,o);returno.compiled?t("automator:devtool")("Waiting for runtime automator"):(t("automator:devtool")("initRuntimeAutomator"),n.send("App.callWxMethod",{method:"$$initRuntimeAutomator",args:[]})),n}},adapter:{"Tool.enableRemoteDebug":{reflect:async(e,t)=>{let{qrCode:r}=awaite("Tool.enableRemoteDebug",t,!1);returnr&&(r=awaitfunction(e){constt=newBuffer(e,"base64");returnnewPromise(async(e,r)=>{constn=awaito.read(t),s=newf;s.callback=function(t,o){if(t)returnr(t);e(o.result)},s.decode(n.bitmap)})}(r)),{qrCode:r}}},"App.callFunction":{reflect:async(e,t)=>{returne("App.callFunction",Object.assign(Object.assign({},t),{functionDeclaration:(r=t.functionDeclaration,"}"===r[r.length-1]?r.replace("{","{\nvar uni = wx;\n"):r.replace("=>","=>{\nvar uni = wx;\nreturn ")+"}")}),!1);varr}},"Element.getHTML":{reflect:async(e,t)=>({html:(awaite("Element.getWXML",t,!1)).wxml})}}};module.exports=q;