Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
...
...
@@ -12,4 +12,4 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */functionI(t,e,n,s){varo,i=arguments.length,r=i<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,n):s;if("object"==typeofReflect&&"function"==typeofReflect.decorate)r=Reflect.decorate(t,e,n,s);elsefor(vara=t.length-1;a>=0;a--)(o=t[a])&&(r=(i<3?o(r):i>3?o(e,n,r):o(e,n))||r);returni>3&&r&&Object.defineProperty(e,n,r),r}varA,x;functionR(t,e){constn=e.value;returne.value=asyncfunction(e){return(await(null==n?void0:n.call(this,e)))(t)},e}functionS(t,e,n){returnR(A.RUNTIME,n)}functionj(t,e,n){returnR(A.DEVTOOL,n)}!function(t){t.RUNTIME="runtime",t.DEVTOOL="devtool"}(A||(A={}));classq{constructor(t){this.puppet=t}invoke(t,e){returnasyncn=>this.puppet.devtoolConnection?(n===A.DEVTOOL?this.puppet.devtoolConnection:this.puppet.runtimeConnection).send(t,e):this.puppet.runtimeConnection.send(t,e)}on(t,e){this.puppet.on(t,e)}}class$extendsq{constructor(t,e){super(t),this.id=e.elementId,this.pageId=e.pageId,this.nodeId=e.nodeId,this.videoId=e.videoId}asyncgetData(t){returnthis.invokeMethod("Element.getData",t)}asyncsetData(t){returnthis.invokeMethod("Element.setData",t)}asynccallMethod(t){returnthis.invokeMethod("Element.callMethod",t)}asyncgetElement(t){returnthis.invokeMethod("Element.getElement",t)}asyncgetElements(t){returnthis.invokeMethod("Element.getElements",t)}asyncgetOffset(){returnthis.invokeMethod("Element.getOffset")}asyncgetHTML(t){returnthis.invokeMethod("Element.getHTML",t)}asyncgetAttributes(t){returnthis.invokeMethod("Element.getAttributes",t)}asyncgetStyles(t){returnthis.invokeMethod("Element.getStyles",t)}asyncgetDOMProperties(t){returnthis.invokeMethod("Element.getDOMProperties",t)}asyncgetProperties(t){returnthis.invokeMethod("Element.getProperties",t)}asynctap(){returnthis.invokeMethod("Element.tap")}asynctouchstart(t){returnthis.invokeMethod("Element.touchstart",t)}asynctouchmove(t){returnthis.invokeMethod("Element.touchmove",t)}asynctouchend(t){returnthis.invokeMethod("Element.touchend",t)}asynctriggerEvent(t){returnthis.invokeMethod("Element.triggerEvent",t)}asynccallFunction(t){returnthis.invokeMethod("Element.callFunction",t)}asynccallContextMethod(t){returnthis.invokeMethod("Element.callContextMethod",t)}invokeMethod(t,e={}){returne.elementId=this.id,e.pageId=this.pageId,this.nodeId&&(e.nodeId=this.nodeId),this.videoId&&(e.videoId=this.videoId),this.invoke(t,e)}}I([S],$.prototype,"getData",null),I([S],$.prototype,"setData",null),I([S],$.prototype,"callMethod",null),I([j],$.prototype,"getElement",null),I([j],$.prototype,"getElements",null),I([j],$.prototype,"getOffset",null),I([j],$.prototype,"getHTML",null),I([j],$.prototype,"getAttributes",null),I([j],$.prototype,"getStyles",null),I([j],$.prototype,"getDOMProperties",null),I([j],$.prototype,"getProperties",null),I([j],$.prototype,"tap",null),I([j],$.prototype,"touchstart",null),I([j],$.prototype,"touchmove",null),I([j],$.prototype,"touchend",null),I([j],$.prototype,"triggerEvent",null),I([j],$.prototype,"callFunction",null),I([j],$.prototype,"callContextMethod",null);classO{constructor(t,e,n){this.puppet=t,this.id=e.elementId,this.pageId=e.pageId,this.nodeId=e.nodeId||null,this.videoId=e.videoId||null,this.tagName=e.tagName,this.elementMap=n,"body"===this.tagName&&(this.tagName="page"),this.api=new$(t,e)}async$(t){try{conste=awaitthis.api.getElement({selector:t});returnO.create(this.puppet,Object.assign({},e,{pageId:this.pageId}),this.elementMap)}catch(t){returnnull}}async$$(t){const{elements:e}=awaitthis.api.getElements({selector:t});returne.map(t=>O.create(this.puppet,Object.assign({},t,{pageId:this.pageId}),this.elementMap))}asyncsize(){const[t,e]=awaitthis.domProperty(["offsetWidth","offsetHeight"]);return{width:t,height:e}}asyncoffset(){returnthis.api.getOffset()}asynctext(){returnthis.domProperty("innerText")}asyncattribute(t){if(!P(t))throwError("name must be a string");return(awaitthis.api.getAttributes({names:[t]})).attributes[0]}asyncvalue(){returnthis.property("value")}asyncproperty(t){if(!P(t))throwError("name must be a string");if(this.puppet.checkProperty){lete=this.publicProps;if(e||(this.publicProps=e=awaitthis._property("__propPublic")),!e[t])throwError(`${this.tagName}.${t} not exists`)}returnthis._property(t)}asynchtml(){return(awaitthis.api.getHTML({type:"inner"})).html}asyncouterHtml(){return(awaitthis.api.getHTML({type:"outer"})).html}asyncstyle(t){if(!P(t))throwError("name must be a string");return(awaitthis.api.getStyles({names:[t]})).styles[0]}asynctap(){returnthis.api.tap()}asynclongpress(){returnawaitthis.touchstart(),awaitp(350),this.touchend()}asynctrigger(t,e){constn={type:t};returnk(e)||(n.detail=e),this.api.triggerEvent(n)}asynctouchstart(t){returnthis.api.touchstart(t)}asynctouchmove(t){returnthis.api.touchmove(t)}asynctouchend(t){returnthis.api.touchend(t)}asyncdomProperty(t){returnD(asynct=>(awaitthis.api.getDOMProperties({names:t})).properties,t)}_property(t){returnD(asynct=>(awaitthis.api.getProperties({names:t})).properties,t)}send(t,e){returne.elementId=this.id,e.pageId=this.pageId,this.nodeId&&(e.nodeId=this.nodeId),this.videoId&&(e.videoId=this.videoId),this.puppet.send(t,e)}asynccallFunction(t,...e){return(awaitthis.api.callFunction({functionName:t,args:e})).result}staticcreate(t,e,n){lets,o=n.get(e.elementId);if(o)returno;if(e.nodeId)s=F;elseswitch(e.tagName){case"input":s=N;break;case"textarea":s=L;break;case"scroll-view":s=U;break;case"swiper":s=H;break;case"movable-view":s=B;break;case"switch":s=_;break;case"slider":s=W;break;case"video":s=V;break;default:s=O}returno=news(t,e,n),n.set(e.elementId,o),o}}classFextendsO{asyncsetData(t){returnthis.api.setData({data:t})}asyncdata(t){conste={};returnt&&(e.path=t),(awaitthis.api.getData(e)).data}asynccallMethod(t,...e){return(awaitthis.api.callMethod({method:t,args:e})).result}}classNextendsO{asyncinput(t){returnthis.callFunction("input.input",t)}}classLextendsO{asyncinput(t){returnthis.callFunction("textarea.input",t)}}classUextendsO{asyncscrollTo(t,e){returnthis.callFunction("scroll-view.scrollTo",t,e)}asyncproperty(t){return"scrollTop"===t?this.callFunction("scroll-view.scrollTop"):"scrollLeft"===t?this.callFunction("scroll-view.scrollLeft"):super.property(t)}asyncscrollWidth(){returnthis.callFunction("scroll-view.scrollWidth")}asyncscrollHeight(){returnthis.callFunction("scroll-view.scrollHeight")}}classHextendsO{asyncswipeTo(t){returnthis.callFunction("swiper.swipeTo",t)}}classBextendsO{asyncmoveTo(t,e){returnthis.callFunction("movable-view.moveTo",t,e)}asyncproperty(t){return"x"===t?this._property("_translateX"):"y"===t?this._property("_translateY"):super.property(t)}}class_extendsO{asynctap(){returnthis.callFunction("switch.tap")}}classWextendsO{asyncslideTo(t){returnthis.callFunction("slider.slideTo",t)}}classVextendsO{asynccallContextMethod(t,...e){returnthis.api.callContextMethod({method:t,args:e})}}classzextendsq{constructor(t,e){super(t),this.id=e.id}asyncgetData(t){returnthis.invokeMethod("Page.getData",t)}asyncsetData(t){returnthis.invokeMethod("Page.setData",t)}asynccallMethod(t){returnthis.invokeMethod("Page.callMethod",t)}asyncgetElement(t){returnthis.invokeMethod("Page.getElement",t)}asyncgetElements(t){returnthis.invokeMethod("Page.getElements",t)}asyncgetWindowProperties(t){returnthis.invokeMethod("Page.getWindowProperties",t)}invokeMethod(t,e={}){returne.pageId=this.id,this.invoke(t,e)}}I([S],z.prototype,"getData",null),I([S],z.prototype,"setData",null),I([S],z.prototype,"callMethod",null),I([j],z.prototype,"getElement",null),I([j],z.prototype,"getElements",null),I([j],z.prototype,"getWindowProperties",null);classG{constructor(t,e){this.puppet=t,this.id=e.id,this.path=e.path,this.query=e.query,this.elementMap=newMap,this.api=newz(t,e)}asyncwaitFor(t){returnE(t)?awaitp(t):w(t)?c(t):P(t)?c(async()=>(awaitthis.$$(t)).length>0):void0}async$(t){try{conste=awaitthis.api.getElement({selector:t});returnO.create(this.puppet,Object.assign({selector:t},e,{pageId:this.id}),this.elementMap)}catch(t){returnnull}}async$$(t){const{elements:e}=awaitthis.api.getElements({selector:t});returne.map(e=>O.create(this.puppet,Object.assign({selector:t},e,{pageId:this.id}),this.elementMap))}asyncdata(t){conste={};returnt&&(e.path=t),(awaitthis.api.getData(e)).data}asyncsetData(t){returnthis.api.setData({data:t})}asyncsize(){const[t,e]=awaitthis.windowProperty(["document.documentElement.scrollWidth","document.documentElement.scrollHeight"]);return{width:t,height:e}}asynccallMethod(t,...e){return(awaitthis.api.callMethod({method:t,args:e})).result}asyncscrollTop(){returnthis.windowProperty("document.documentElement.scrollTop")}asyncwindowProperty(t){conste=P(t);e&&(t=[t]);const{properties:n}=awaitthis.api.getWindowProperties({names:t});returne?n[0]:n}staticcreate(t,e,n){lets=n.get(e.id);returns||(s=newG(t,e),n.set(e.id,s),s)}}classJextendsq{asyncgetPageStack(){returnthis.invoke("App.getPageStack")}asynccallUniMethod(t){returnthis.invoke("App.callUniMethod",t)}asyncgetCurrentPage(){returnthis.invoke("App.getCurrentPage")}asyncmockUniMethod(t){returnthis.invoke("App.mockUniMethod",t)}asynccallFunction(t){returnthis.invoke("App.callFunction",t)}asynccaptureScreenshot(){returnthis.invoke("App.captureScreenshot")}asyncexit(){returnthis.invoke("App.exit")}asyncaddBinding(t){returnthis.invoke("App.addBinding",t)}asyncenableLog(){returnthis.invoke("App.enableLog")}onLogAdded(t){returnthis.on("App.logAdded",t)}onBindingCalled(t){returnthis.on("App.bindingCalled",t)}onExceptionThrown(t){returnthis.on("App.exceptionThrown",t)}}I([S],J.prototype,"getPageStack",null),I([S],J.prototype,"callUniMethod",null),I([S],J.prototype,"getCurrentPage",null),I([j],J.prototype,"mockUniMethod",null),I([j],J.prototype,"callFunction",null),I([j],J.prototype,"captureScreenshot",null),I([j],J.prototype,"exit",null),I([j],J.prototype,"addBinding",null),I([j],J.prototype,"enableLog",null);classXextendsq{asyncgetInfo(){returnthis.invoke("Tool.getInfo")}asyncenableRemoteDebug(t){returnthis.invoke("Tool.enableRemoteDebug")}asyncclose(){returnthis.invoke("Tool.close")}asyncgetTestAccounts(){returnthis.invoke("Tool.getTestAccounts")}onRemoteDebugConnected(t){this.puppet.once("Tool.onRemoteDebugConnected",t),this.puppet.once("Tool.onPreviewConnected",t)}}functionY(t){returnnewPromise(e=>setTimeout(e,t))}I([j],X.prototype,"getInfo",null),I([j],X.prototype,"enableRemoteDebug",null),I([j],X.prototype,"close",null),I([j],X.prototype,"getTestAccounts",null),function(t){t.CLOSE="close",t.DISCONNECT="disconnect"}(x||(x={}));classKextendsm.EventEmitter{constructor(t,e){super(),this.puppet=t,this.options=e,this.pageMap=newMap,this.appBindings=newMap,this.appApi=newJ(t),this.toolApi=newX(t),this.appApi.onLogAdded(t=>{this.emit("console",t)}),this.appApi.onBindingCalled(({name:t,args:e})=>{try{constn=this.appBindings.get(t);n&&n(...e)}catch(t){}}),this.appApi.onExceptionThrown(t=>{this.emit("exception",t)})}asyncpageStack(){return(awaitthis.appApi.getPageStack()).pageStack.map(t=>G.create(this.puppet,t,this.pageMap))}asyncnavigateTo(t){returnthis.changeRoute("navigateTo",t)}asyncredirectTo(t){returnthis.changeRoute("redirectTo",t)}asyncnavigateBack(){returnthis.changeRoute("navigateBack")}asyncreLaunch(t){returnthis.changeRoute("reLaunch",t)}asyncswitchTab(t){returnthis.changeRoute("switchTab",t)}asynccurrentPage(){const{id:t,path:e,query:n}=awaitthis.appApi.getCurrentPage();returnG.create(this.puppet,{id:t,path:e,query:n},this.pageMap)}asyncsystemInfo(){returnthis.callUniMethod("getSystemInfoSync")}asynccallUniMethod(t,...e){return(awaitthis.appApi.callUniMethod({method:t,args:e})).result}asyncmockUniMethod(t,e,...n){returnw(e)||P(s=e)&&(s=f(s),M(s,"function")||M(s,"() =>"))?this.appApi.mockUniMethod({method:t,functionDeclaration:e.toString(),args:n}):this.appApi.mockUniMethod({method:t,result:e});vars}asyncrestoreUniMethod(t){returnthis.appApi.mockUniMethod({method:t})}asyncevaluate(t,...e){return(awaitthis.appApi.callFunction({functionDeclaration:t.toString(),args:e})).result}asyncpageScrollTo(t){awaitthis.callUniMethod("pageScrollTo",{scrollTop:t,duration:0})}asyncclose(){try{awaitthis.appApi.exit()}catch(t){}awaitY(1e3),this.puppet.disposeRuntimeServer(),awaitthis.toolApi.close(),this.disconnect()}asyncteardown(){returnthis[this.options.teardown===x.DISCONNECT?x.DISCONNECT:x.CLOSE]()}asyncremote(t){if(!this.puppet.devtools.remote)returnconsole.warn(`Failed to enable remote, ${this.puppet.devtools.name} is unimplemented`);const{qrCode:e}=awaitthis.toolApi.enableRemoteDebug({auto:t});varn;e&&await(n=e,newPromise(t=>{T.generate(n,{small:!0},e=>{process.stdout.write(e),t()})}));consts=newPromise(t=>{this.toolApi.onRemoteDebugConnected(async()=>{awaitY(1e3),t()})}),o=newPromise(t=>{this.puppet.setRemoteRuntimeConnectionCallback(()=>{t()})});returnPromise.all([s,o])}disconnect(){this.puppet.dispose()}on(t,e){return"console"===t&&this.appApi.enableLog(),super.on(t,e),this}asyncexposeFunction(t,e){if(this.appBindings.has(t))throwError(`Failed to expose function with name ${t}: already exists!`);this.appBindings.set(t,e),awaitthis.appApi.addBinding({name:t})}asynccheckVersion(){}asyncscreenshot(t){const{data:e}=awaitthis.appApi.captureScreenshot();if(!(null==t?void0:t.path))returne;awaitv.writeFile(t.path,e,"base64")}asynctestAccounts(){return(awaitthis.toolApi.getTestAccounts()).accounts}asyncchangeRoute(t,e){returnawaitthis.callUniMethod(t,{url:e}),awaitY(3e3),this.currentPage()}}classQ{constructor(t){this.options=t}has(t){return!!this.options[t]}send(t,e,n){consts=this.options[e];if(!s)returnPromise.reject(Error(`adapter for ${e} not found`));consto=s.reflect;returno?(s.params&&(n=s.params(n)),"function"==typeofo?o(t.send.bind(t),n):(e=o,t.send(e,n))):Promise.reject(Error(e+"'s reflect is required"))}}classZextendsm.EventEmitter{constructor(t,e){if(super(),this.target=e||require(`@dcloudio/uni-${t}/lib/uni.automator.js`),!this.target)throwError("puppet is not provided");this.platform=t,this.adapter=newQ(this.target.adapter||{})}setRuntimeServer(t){this.wss=t}setRemoteRuntimeConnectionCallback(t){this.remoteRuntimeConnectionCallback=t}setRuntimeConnection(t){this.runtimeConnection=t,this.remoteRuntimeConnectionCallback&&(this.remoteRuntimeConnectionCallback(),this.remoteRuntimeConnectionCallback=null)}setDevtoolConnection(t){this.devtoolConnection=t}disposeRuntimeServer(){this.wss&&this.wss.close()}disposeRuntime(){this.runtimeConnection.dispose()}disposeDevtool(){this.devtoolConnection&&this.devtoolConnection.dispose()}dispose(){this.disposeRuntime(),this.disposeDevtool(),this.disposeRuntimeServer()}send(t,e){returnthis.runtimeConnection.send(t,e)}validateProject(t){consts=this.target.devtools.required;return!s||!s.find(s=>!e.existsSync(n.join(t,s)))}getcheckProperty(){return"mp-weixin"===this.platform}getdefaultPort(){returnthis.target.devtools.defaultPort}getdevtools(){returnthis.target.devtools}getmode(){constt=this.target.mode;returnt||("production"===process.env.NODE_ENV?"build":"dev")}}consttt=s("automator:compiler"),et=/The\s+(.*)\s+directory is ready/;classnt{constructor(t){this.puppet=t}compile(t){conste=this.puppet.mode,s=this.puppet.platform;leti=t.silent;constr=t.port,c=t.host,l=process.env.UNI_NPM_PATH||"npm",p=`${e}:${s}`,u=t.projectPath,h=["run",p,"--","--auto-port",a(r)];c&&(h.push("--auto-host"),h.push(c));constd={cwd:t.cliPath||t.projectPath,env:process.env};returnnewPromise((t,r)=>{consta=function(o){constr=o.toString().trim();if(!i&&console.log(r),r.includes("App running at:"))t({path:""});elseif(r.includes("DONE Build complete")){leto=`unpackage/dist/${e}/${s}`;consta=r.match(et);a&&a.length>1&&(o=a[1]),i=!0,c.kill("SIGTERM"),t({path:n.join(u,o)})}};tt(`${l}${h.join("")}`);constc=o.spawn(l,h,d);c.on("error",(function(t){r(t)})),c.stdout.on("data",a),c.stderr.on("data",a)})}}constst=s("automator:devtool"),ot=1e5;functionit(t){throwError(t)}classrt{asynclaunch(t){conste=t.devtools||{};this.puppet=newZ(t.platform,t.puppet);const{port:n,cliPath:o,projectPath:i}=awaitthis.validate(t);letr;this.puppet.devtools.automator&&(r=awaitthis.validateDevtools(e));leta=i;if(!1!==t.compile){this.compiler=newnt(this.puppet);conste=awaitthis.compiler.compile({host:r&&r.host,port:n,cliPath:o,projectPath:i,silent:!!t.silent});e.path&&(a=e.path)}constc=[];returnc.push(this.createRuntimeConnection(n,e)),r&&c.push(this.createDevtoolConnection(a,r)),newPromise((t,n)=>{Promise.all(c).then(([n,o])=>{this.puppet.setRuntimeConnection(n),this.puppet.setDevtoolConnection(o),s("automator:program")("ready");consti=e.teardown||x.DISCONNECT;t(newK(this.puppet,{teardown:i}))}).catch(t=>n(t))})}asyncconnectTool(t){lete;try{e=awaitb.createDevtoolConnection(t.wsEndpoint,this.puppet)}catch(e){throwError(`Failed connecting to ${t.wsEndpoint}, check if target project window is opened with automation enabled`)}returne}validateCliPath(t){try{conste=require(n.join(t,"package.json"));if(e.devDependencies&&e.devDependencies["@dcloudio/vue-cli-plugin-uni"])return!0}catch(t){}}resolveCliPath(t){returnt?this.validateCliPath(t)?t:voidit(`Cli ${t} doesn't exist`):t}resolveProjectPath(t,s){if(t||(t=process.cwd()),u(t)&&(t=n.resolve(t)),e.existsSync(t)||it(`Project path ${t} doesn't exist`),!1===s.compile&&!this.puppet.validateProject(t)){conste=n.join(t,"dist/"+this.puppet.mode+"/"+this.puppet.platform);if(this.puppet.validateProject(e))returne;s.compile=!0}returnt}asyncresolvePort(t,e){constn=awaitr(t||e);returnt&&n!==t&&it(`Port ${t} is in use, please specify another port`),n}asyncvalidate(t){conste=this.resolveProjectPath(t.projectPath,t);letn=t.cliPath;return!1!==t.compile&&(n=this.resolveCliPath(t.cliPath||""),!n&&(n=this.resolveCliPath(e))),{port:awaitthis.resolvePort(t.port||9520),cliPath:n,projectPath:e,platform:t.platform}}resolveDevtoolsPath(t){constn=this.puppet.devtools.paths.slice(0);t&&n.unshift(t);for(consttofn)if(e.existsSync(t))returnt;it(this.puppet.devtools.name+" not found, please specify devtools.cliPath option")}asyncvalidateDevtools(t={}){conste=this.resolveDevtoolsPath(t.cliPath);letn=t.port||this.puppet.defaultPort;if(!1!==t.launch)try{n=awaitthis.resolvePort(n)}catch(e){t.launch=!1}else{n===awaitr(n)&&(t.launch=!0)}returnObject.assign(Object.assign({},t),{port:n,cliPath:e})}asynccreateRuntimeConnection(t,e){returnb.createRuntimeConnection(t,this.puppet,e.timeout||ot)}asynccreateDevtoolConnection(t,e){const{port:n,cliPath:s,timeout:o=ot,cwd:r="",account:u="",args:d=[],launch:m=!0}=e;lety=!1,g=!1;if(!1!==m){conste={detached:!0,stdio:"ignore"};r&&(e.cwd=r);leto=l(d,["--auto",t,"--auto-port",a(n)]);u&&(o=l(o,["--auto-account",u]));try{st("%s %o %o",s,o,e);constt=i.spawn(s,o,e);t.on("error",t=>{y=!0}),t.on("exit",()=>{setTimeout(()=>{g=!0},15e3)}),t.unref()}catch(t){y=!1}}elsesetTimeout(()=>{g=!0},15e3);constv=awaitc(async()=>{try{if(y||g)return!0;returnawaitthis.connectTool({wsEndpoint:"ws://127.0.0.1:"+n})}catch(t){}},o,1e3);returny&&it(`Failed to launch ${this.puppet.devtools.name}, please make sure cliPath is correctly specified`),g&&it(`Failed to launch ${this.puppet.devtools.name} , please make sure http port is open`),awaitp(5e3),st(h("yyyy-mm-dd HH:MM:ss:l")+" connected"),!1===m&&this.initRuntimeAutomator(v),v}asyncinitRuntimeAutomator(t){returnst("initRuntimeAutomator"),t.send("App.callUniMethod",{method:"$$initRuntimeAutomator",args:[]})}}module.exports=class{constructor(){this.launcher=newrt}asynclaunch(t){returnthis.launcher.launch(t)}};
***************************************************************************** */functionI(t,e,n,s){varo,i=arguments.length,r=i<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,n):s;if("object"==typeofReflect&&"function"==typeofReflect.decorate)r=Reflect.decorate(t,e,n,s);elsefor(vara=t.length-1;a>=0;a--)(o=t[a])&&(r=(i<3?o(r):i>3?o(e,n,r):o(e,n))||r);returni>3&&r&&Object.defineProperty(e,n,r),r}varA,x;functionR(t,e){constn=e.value;returne.value=asyncfunction(e){return(await(null==n?void0:n.call(this,e)))(t)},e}functionS(t,e,n){returnR(A.RUNTIME,n)}functionj(t,e,n){returnR(A.DEVTOOL,n)}!function(t){t.RUNTIME="runtime",t.DEVTOOL="devtool"}(A||(A={}));classq{constructor(t){this.puppet=t}invoke(t,e){returnasyncn=>this.puppet.devtoolConnection?(n===A.DEVTOOL?this.puppet.devtoolConnection:this.puppet.runtimeConnection).send(t,e):this.puppet.runtimeConnection.send(t,e)}on(t,e){this.puppet.on(t,e)}}class$extendsq{constructor(t,e){super(t),this.id=e.elementId,this.pageId=e.pageId,this.nodeId=e.nodeId,this.videoId=e.videoId}asyncgetData(t){returnthis.invokeMethod("Element.getData",t)}asyncsetData(t){returnthis.invokeMethod("Element.setData",t)}asynccallMethod(t){returnthis.invokeMethod("Element.callMethod",t)}asyncgetElement(t){returnthis.invokeMethod("Element.getElement",t)}asyncgetElements(t){returnthis.invokeMethod("Element.getElements",t)}asyncgetOffset(){returnthis.invokeMethod("Element.getOffset")}asyncgetHTML(t){returnthis.invokeMethod("Element.getHTML",t)}asyncgetAttributes(t){returnthis.invokeMethod("Element.getAttributes",t)}asyncgetStyles(t){returnthis.invokeMethod("Element.getStyles",t)}asyncgetDOMProperties(t){returnthis.invokeMethod("Element.getDOMProperties",t)}asyncgetProperties(t){returnthis.invokeMethod("Element.getProperties",t)}asynctap(){returnthis.invokeMethod("Element.tap")}asynctouchstart(t){returnthis.invokeMethod("Element.touchstart",t)}asynctouchmove(t){returnthis.invokeMethod("Element.touchmove",t)}asynctouchend(t){returnthis.invokeMethod("Element.touchend",t)}asynctriggerEvent(t){returnthis.invokeMethod("Element.triggerEvent",t)}asynccallFunction(t){returnthis.invokeMethod("Element.callFunction",t)}asynccallContextMethod(t){returnthis.invokeMethod("Element.callContextMethod",t)}invokeMethod(t,e={}){returne.elementId=this.id,e.pageId=this.pageId,this.nodeId&&(e.nodeId=this.nodeId),this.videoId&&(e.videoId=this.videoId),this.invoke(t,e)}}I([S],$.prototype,"getData",null),I([S],$.prototype,"setData",null),I([S],$.prototype,"callMethod",null),I([j],$.prototype,"getElement",null),I([j],$.prototype,"getElements",null),I([j],$.prototype,"getOffset",null),I([j],$.prototype,"getHTML",null),I([j],$.prototype,"getAttributes",null),I([j],$.prototype,"getStyles",null),I([j],$.prototype,"getDOMProperties",null),I([j],$.prototype,"getProperties",null),I([j],$.prototype,"tap",null),I([j],$.prototype,"touchstart",null),I([j],$.prototype,"touchmove",null),I([j],$.prototype,"touchend",null),I([j],$.prototype,"triggerEvent",null),I([j],$.prototype,"callFunction",null),I([j],$.prototype,"callContextMethod",null);classO{constructor(t,e,n){this.puppet=t,this.id=e.elementId,this.pageId=e.pageId,this.nodeId=e.nodeId||null,this.videoId=e.videoId||null,this.tagName=e.tagName,this.elementMap=n,"body"===this.tagName&&(this.tagName="page"),this.api=new$(t,e)}async$(t){try{conste=awaitthis.api.getElement({selector:t});returnO.create(this.puppet,Object.assign({},e,{pageId:this.pageId}),this.elementMap)}catch(t){returnnull}}async$$(t){const{elements:e}=awaitthis.api.getElements({selector:t});returne.map(t=>O.create(this.puppet,Object.assign({},t,{pageId:this.pageId}),this.elementMap))}asyncsize(){const[t,e]=awaitthis.domProperty(["offsetWidth","offsetHeight"]);return{width:t,height:e}}asyncoffset(){returnthis.api.getOffset()}asynctext(){returnthis.domProperty("innerText")}asyncattribute(t){if(!P(t))throwError("name must be a string");return(awaitthis.api.getAttributes({names:[t]})).attributes[0]}asyncvalue(){returnthis.property("value")}asyncproperty(t){if(!P(t))throwError("name must be a string");if(this.puppet.checkProperty){lete=this.publicProps;if(e||(this.publicProps=e=awaitthis._property("__propPublic")),!e[t])throwError(`${this.tagName}.${t} not exists`)}returnthis._property(t)}asynchtml(){return(awaitthis.api.getHTML({type:"inner"})).html}asyncouterHtml(){return(awaitthis.api.getHTML({type:"outer"})).html}asyncstyle(t){if(!P(t))throwError("name must be a string");return(awaitthis.api.getStyles({names:[t]})).styles[0]}asynctap(){returnthis.api.tap()}asynclongpress(){returnawaitthis.touchstart(),awaitp(350),this.touchend()}asynctrigger(t,e){constn={type:t};returnk(e)||(n.detail=e),this.api.triggerEvent(n)}asynctouchstart(t){returnthis.api.touchstart(t)}asynctouchmove(t){returnthis.api.touchmove(t)}asynctouchend(t){returnthis.api.touchend(t)}asyncdomProperty(t){returnT(asynct=>(awaitthis.api.getDOMProperties({names:t})).properties,t)}_property(t){returnT(asynct=>(awaitthis.api.getProperties({names:t})).properties,t)}send(t,e){returne.elementId=this.id,e.pageId=this.pageId,this.nodeId&&(e.nodeId=this.nodeId),this.videoId&&(e.videoId=this.videoId),this.puppet.send(t,e)}asynccallFunction(t,...e){return(awaitthis.api.callFunction({functionName:t,args:e})).result}staticcreate(t,e,n){lets,o=n.get(e.elementId);if(o)returno;if(e.nodeId)s=F;elseswitch(e.tagName){case"input":s=N;break;case"textarea":s=L;break;case"scroll-view":s=U;break;case"swiper":s=H;break;case"movable-view":s=B;break;case"switch":s=_;break;case"slider":s=W;break;case"video":s=V;break;default:s=O}returno=news(t,e,n),n.set(e.elementId,o),o}}classFextendsO{asyncsetData(t){returnthis.api.setData({data:t})}asyncdata(t){conste={};returnt&&(e.path=t),(awaitthis.api.getData(e)).data}asynccallMethod(t,...e){return(awaitthis.api.callMethod({method:t,args:e})).result}}classNextendsO{asyncinput(t){returnthis.callFunction("input.input",t)}}classLextendsO{asyncinput(t){returnthis.callFunction("textarea.input",t)}}classUextendsO{asyncscrollTo(t,e){returnthis.callFunction("scroll-view.scrollTo",t,e)}asyncproperty(t){return"scrollTop"===t?this.callFunction("scroll-view.scrollTop"):"scrollLeft"===t?this.callFunction("scroll-view.scrollLeft"):super.property(t)}asyncscrollWidth(){returnthis.callFunction("scroll-view.scrollWidth")}asyncscrollHeight(){returnthis.callFunction("scroll-view.scrollHeight")}}classHextendsO{asyncswipeTo(t){returnthis.callFunction("swiper.swipeTo",t)}}classBextendsO{asyncmoveTo(t,e){returnthis.callFunction("movable-view.moveTo",t,e)}asyncproperty(t){return"x"===t?this._property("_translateX"):"y"===t?this._property("_translateY"):super.property(t)}}class_extendsO{asynctap(){returnthis.callFunction("switch.tap")}}classWextendsO{asyncslideTo(t){returnthis.callFunction("slider.slideTo",t)}}classVextendsO{asynccallContextMethod(t,...e){returnthis.api.callContextMethod({method:t,args:e})}}classzextendsq{constructor(t,e){super(t),this.id=e.id}asyncgetData(t){returnthis.invokeMethod("Page.getData",t)}asyncsetData(t){returnthis.invokeMethod("Page.setData",t)}asynccallMethod(t){returnthis.invokeMethod("Page.callMethod",t)}asyncgetElement(t){returnthis.invokeMethod("Page.getElement",t)}asyncgetElements(t){returnthis.invokeMethod("Page.getElements",t)}asyncgetWindowProperties(t){returnthis.invokeMethod("Page.getWindowProperties",t)}invokeMethod(t,e={}){returne.pageId=this.id,this.invoke(t,e)}}I([S],z.prototype,"getData",null),I([S],z.prototype,"setData",null),I([S],z.prototype,"callMethod",null),I([j],z.prototype,"getElement",null),I([j],z.prototype,"getElements",null),I([j],z.prototype,"getWindowProperties",null);classG{constructor(t,e){this.puppet=t,this.id=e.id,this.path=e.path,this.query=e.query,this.elementMap=newMap,this.api=newz(t,e)}asyncwaitFor(t){returnE(t)?awaitp(t):w(t)?c(t):P(t)?c(async()=>(awaitthis.$$(t)).length>0):void0}async$(t){try{conste=awaitthis.api.getElement({selector:t});returnO.create(this.puppet,Object.assign({selector:t},e,{pageId:this.id}),this.elementMap)}catch(t){returnnull}}async$$(t){const{elements:e}=awaitthis.api.getElements({selector:t});returne.map(e=>O.create(this.puppet,Object.assign({selector:t},e,{pageId:this.id}),this.elementMap))}asyncdata(t){conste={};returnt&&(e.path=t),(awaitthis.api.getData(e)).data}asyncsetData(t){returnthis.api.setData({data:t})}asyncsize(){const[t,e]=awaitthis.windowProperty(["document.documentElement.scrollWidth","document.documentElement.scrollHeight"]);return{width:t,height:e}}asynccallMethod(t,...e){return(awaitthis.api.callMethod({method:t,args:e})).result}asyncscrollTop(){returnthis.windowProperty("document.documentElement.scrollTop")}asyncwindowProperty(t){conste=P(t);e&&(t=[t]);const{properties:n}=awaitthis.api.getWindowProperties({names:t});returne?n[0]:n}staticcreate(t,e,n){lets=n.get(e.id);returns||(s=newG(t,e),n.set(e.id,s),s)}}classJextendsq{asyncgetPageStack(){returnthis.invoke("App.getPageStack")}asynccallUniMethod(t){returnthis.invoke("App.callUniMethod",t)}asyncgetCurrentPage(){returnthis.invoke("App.getCurrentPage")}asyncmockUniMethod(t){returnthis.invoke("App.mockUniMethod",t)}asynccallFunction(t){returnthis.invoke("App.callFunction",t)}asynccaptureScreenshot(){returnthis.invoke("App.captureScreenshot")}asyncexit(){returnthis.invoke("App.exit")}asyncaddBinding(t){returnthis.invoke("App.addBinding",t)}asyncenableLog(){returnthis.invoke("App.enableLog")}onLogAdded(t){returnthis.on("App.logAdded",t)}onBindingCalled(t){returnthis.on("App.bindingCalled",t)}onExceptionThrown(t){returnthis.on("App.exceptionThrown",t)}}I([S],J.prototype,"getPageStack",null),I([S],J.prototype,"callUniMethod",null),I([S],J.prototype,"getCurrentPage",null),I([j],J.prototype,"mockUniMethod",null),I([j],J.prototype,"callFunction",null),I([j],J.prototype,"captureScreenshot",null),I([j],J.prototype,"exit",null),I([j],J.prototype,"addBinding",null),I([j],J.prototype,"enableLog",null);classXextendsq{asyncgetInfo(){returnthis.invoke("Tool.getInfo")}asyncenableRemoteDebug(t){returnthis.invoke("Tool.enableRemoteDebug")}asyncclose(){returnthis.invoke("Tool.close")}asyncgetTestAccounts(){returnthis.invoke("Tool.getTestAccounts")}onRemoteDebugConnected(t){this.puppet.once("Tool.onRemoteDebugConnected",t),this.puppet.once("Tool.onPreviewConnected",t)}}functionY(t){returnnewPromise(e=>setTimeout(e,t))}I([j],X.prototype,"getInfo",null),I([j],X.prototype,"enableRemoteDebug",null),I([j],X.prototype,"close",null),I([j],X.prototype,"getTestAccounts",null),function(t){t.CLOSE="close",t.DISCONNECT="disconnect"}(x||(x={}));classKextendsm.EventEmitter{constructor(t,e){super(),this.puppet=t,this.options=e,this.pageMap=newMap,this.appBindings=newMap,this.appApi=newJ(t),this.toolApi=newX(t),this.appApi.onLogAdded(t=>{this.emit("console",t)}),this.appApi.onBindingCalled(({name:t,args:e})=>{try{constn=this.appBindings.get(t);n&&n(...e)}catch(t){}}),this.appApi.onExceptionThrown(t=>{this.emit("exception",t)})}asyncpageStack(){return(awaitthis.appApi.getPageStack()).pageStack.map(t=>G.create(this.puppet,t,this.pageMap))}asyncnavigateTo(t){returnthis.changeRoute("navigateTo",t)}asyncredirectTo(t){returnthis.changeRoute("redirectTo",t)}asyncnavigateBack(){returnthis.changeRoute("navigateBack")}asyncreLaunch(t){returnthis.changeRoute("reLaunch",t)}asyncswitchTab(t){returnthis.changeRoute("switchTab",t)}asynccurrentPage(){const{id:t,path:e,query:n}=awaitthis.appApi.getCurrentPage();returnG.create(this.puppet,{id:t,path:e,query:n},this.pageMap)}asyncsystemInfo(){returnthis.callUniMethod("getSystemInfoSync")}asynccallUniMethod(t,...e){return(awaitthis.appApi.callUniMethod({method:t,args:e})).result}asyncmockUniMethod(t,e,...n){returnw(e)||P(s=e)&&(s=f(s),M(s,"function")||M(s,"() =>"))?this.appApi.mockUniMethod({method:t,functionDeclaration:e.toString(),args:n}):this.appApi.mockUniMethod({method:t,result:e});vars}asyncrestoreUniMethod(t){returnthis.appApi.mockUniMethod({method:t})}asyncevaluate(t,...e){return(awaitthis.appApi.callFunction({functionDeclaration:t.toString(),args:e})).result}asyncpageScrollTo(t){awaitthis.callUniMethod("pageScrollTo",{scrollTop:t,duration:0})}asyncclose(){try{awaitthis.appApi.exit()}catch(t){}awaitY(1e3),this.puppet.disposeRuntimeServer(),awaitthis.toolApi.close(),this.disconnect()}asyncteardown(){returnthis[this.options.teardown===x.DISCONNECT?x.DISCONNECT:x.CLOSE]()}asyncremote(t){if(!this.puppet.devtools.remote)returnconsole.warn(`Failed to enable remote, ${this.puppet.devtools.name} is unimplemented`);const{qrCode:e}=awaitthis.toolApi.enableRemoteDebug({auto:t});varn;e&&await(n=e,newPromise(t=>{D.generate(n,{small:!0},e=>{process.stdout.write(e),t()})}));consts=newPromise(t=>{this.toolApi.onRemoteDebugConnected(async()=>{awaitY(1e3),t()})}),o=newPromise(t=>{this.puppet.setRemoteRuntimeConnectionCallback(()=>{t()})});returnPromise.all([s,o])}disconnect(){this.puppet.dispose()}on(t,e){return"console"===t&&this.appApi.enableLog(),super.on(t,e),this}asyncexposeFunction(t,e){if(this.appBindings.has(t))throwError(`Failed to expose function with name ${t}: already exists!`);this.appBindings.set(t,e),awaitthis.appApi.addBinding({name:t})}asynccheckVersion(){}asyncscreenshot(t){const{data:e}=awaitthis.appApi.captureScreenshot();if(!(null==t?void0:t.path))returne;awaitv.writeFile(t.path,e,"base64")}asynctestAccounts(){return(awaitthis.toolApi.getTestAccounts()).accounts}asyncchangeRoute(t,e){returnawaitthis.callUniMethod(t,{url:e}),awaitY(3e3),this.currentPage()}}classQ{constructor(t){this.options=t}has(t){return!!this.options[t]}send(t,e,n){consts=this.options[e];if(!s)returnPromise.reject(Error(`adapter for ${e} not found`));consto=s.reflect;returno?(s.params&&(n=s.params(n)),"function"==typeofo?o(t.send.bind(t),n):(e=o,t.send(e,n))):Promise.reject(Error(e+"'s reflect is required"))}}classZextendsm.EventEmitter{constructor(t,e){if(super(),this.target=e||require(`@dcloudio/uni-${t}/lib/uni.automator.js`),!this.target)throwError("puppet is not provided");this.platform=t,this.adapter=newQ(this.target.adapter||{})}setRuntimeServer(t){this.wss=t}setRemoteRuntimeConnectionCallback(t){this.remoteRuntimeConnectionCallback=t}setRuntimeConnection(t){this.runtimeConnection=t,this.remoteRuntimeConnectionCallback&&(this.remoteRuntimeConnectionCallback(),this.remoteRuntimeConnectionCallback=null)}setDevtoolConnection(t){this.devtoolConnection=t}disposeRuntimeServer(){this.wss&&this.wss.close()}disposeRuntime(){this.runtimeConnection.dispose()}disposeDevtool(){this.devtoolConnection&&this.devtoolConnection.dispose()}dispose(){this.disposeRuntime(),this.disposeDevtool(),this.disposeRuntimeServer()}send(t,e){returnthis.runtimeConnection.send(t,e)}validateProject(t){consts=this.target.devtools.required;return!s||!s.find(s=>!e.existsSync(n.join(t,s)))}validateDevtools(t){conste=this.target.devtools.validate;e&&e()}createDevtools(){constt=this.target.devtools.create;returnt?t():Promise.resolve()}getcheckProperty(){return"mp-weixin"===this.platform}getdefaultPort(){returnthis.target.devtools.defaultPort}getdevtools(){returnthis.target.devtools}getmode(){constt=this.target.mode;returnt||("production"===process.env.NODE_ENV?"build":"dev")}}consttt=s("automator:compiler"),et=/The\s+(.*)\s+directory is ready/;classnt{constructor(t){this.puppet=t}compile(t){conste=this.puppet.mode,s=this.puppet.platform;leti=t.silent;constr=t.port,c=t.host,l=process.env.UNI_NPM_PATH||"npm",p=`${e}:${s}`,u=t.projectPath,h=["run",p,"--","--auto-port",a(r)];c&&(h.push("--auto-host"),h.push(c));constd={cwd:t.cliPath||t.projectPath,env:process.env};returnnewPromise((t,r)=>{consta=function(o){constr=o.toString().trim();if(!i&&console.log(r),r.includes("App running at:"))t({path:""});elseif(r.includes("DONE Build complete")){leto=`unpackage/dist/${e}/${s}`;consta=r.match(et);a&&a.length>1&&(o=a[1]),i=!0,c.kill("SIGTERM"),t({path:n.join(u,o)})}};tt(`${l}${h.join("")}`);constc=o.spawn(l,h,d);c.on("error",(function(t){r(t)})),c.stdout.on("data",a),c.stderr.on("data",a)})}}constst=s("automator:devtool"),ot=1e5;functionit(t){throwError(t)}classrt{asynclaunch(t){conste=t[t.platform]||{};this.puppet=newZ(t.platform,e.puppet);const{port:n,cliPath:o,projectPath:i}=awaitthis.validate(t);letr;this.puppet.devtools.automator&&(r=awaitthis.validateDevtools(e));leta=i;if(!1!==t.compile){this.compiler=newnt(this.puppet);conste=awaitthis.compiler.compile({host:t.host,port:n,cliPath:o,projectPath:i,silent:!!t.silent});e.path&&(a=e.path)}constc=[];returnc.push(this.createRuntimeConnection(n,t.timeout||ot)),r&&c.push(this.createDevtoolConnection(a,r)),newPromise((t,n)=>{Promise.all(c).then(([n,o])=>{this.puppet.setRuntimeConnection(n),this.puppet.setDevtoolConnection(o),s("automator:program")("ready");consti=e.teardown||x.DISCONNECT;t(newK(this.puppet,{teardown:i}))}).catch(t=>n(t))})}asyncconnectTool(t){lete;try{e=awaitb.createDevtoolConnection(t.wsEndpoint,this.puppet)}catch(e){throwError(`Failed connecting to ${t.wsEndpoint}, check if target project window is opened with automation enabled`)}returne}validateCliPath(t){try{conste=require(n.join(t,"package.json"));if(e.devDependencies&&e.devDependencies["@dcloudio/vue-cli-plugin-uni"])return!0}catch(t){}}resolveCliPath(t){returnt?this.validateCliPath(t)?t:voidit(`Cli ${t} doesn't exist`):t}resolveProjectPath(t,s){if(t||(t=process.cwd()),u(t)&&(t=n.resolve(t)),e.existsSync(t)||it(`Project path ${t} doesn't exist`),!1===s.compile&&!this.puppet.validateProject(t)){conste=n.join(t,"dist/"+this.puppet.mode+"/"+this.puppet.platform);if(this.puppet.validateProject(e))returne;s.compile=!0}returnt}asyncresolvePort(t,e){constn=awaitr(t||e);returnt&&n!==t&&it(`Port ${t} is in use, please specify another port`),n}asyncvalidate(t){conste=this.resolveProjectPath(t.projectPath,t);letn=t.cliPath;return!1!==t.compile&&(n=this.resolveCliPath(t.cliPath||""),!n&&(n=this.resolveCliPath(e))),{port:awaitthis.resolvePort(t.port||9520),cliPath:n,projectPath:e}}resolveDevtoolsPath(t){constn=this.puppet.devtools.paths.slice(0);t&&n.unshift(t);for(consttofn)if(e.existsSync(t))returnt;it(this.puppet.devtools.name+" not found, please specify devtools.cliPath option")}asyncvalidateDevtools(t){conste=this.resolveDevtoolsPath(t.cliPath);letn=t.port||this.puppet.defaultPort;if(!1!==t.launch)try{n=awaitthis.resolvePort(n)}catch(e){t.launch=!1}else{n===awaitr(n)&&(t.launch=!0)}returnObject.assign(Object.assign({},t),{port:n,cliPath:e})}asynccreateRuntimeConnection(t,e){returnb.createRuntimeConnection(t,this.puppet,e)}asynccreateDevtoolConnection(t,e){const{port:n,cliPath:s,timeout:o=ot,cwd:r="",account:u="",args:d=[],launch:m=!0}=e;lety=!1,g=!1;if(!1!==m){conste={detached:!0,stdio:"ignore"};r&&(e.cwd=r);leto=l(d,["--auto",t,"--auto-port",a(n)]);u&&(o=l(o,["--auto-account",u]));try{st("%s %o %o",s,o,e);constt=i.spawn(s,o,e);t.on("error",t=>{y=!0}),t.on("exit",()=>{setTimeout(()=>{g=!0},15e3)}),t.unref()}catch(t){y=!1}}elsesetTimeout(()=>{g=!0},15e3);constv=awaitc(async()=>{try{if(y||g)return!0;returnawaitthis.connectTool({wsEndpoint:"ws://127.0.0.1:"+n})}catch(t){}},o,1e3);returny&&it(`Failed to launch ${this.puppet.devtools.name}, please make sure cliPath is correctly specified`),g&&it(`Failed to launch ${this.puppet.devtools.name} , please make sure http port is open`),awaitp(5e3),st(h("yyyy-mm-dd HH:MM:ss:l")+" connected"),!1===m&&this.initRuntimeAutomator(v),v}asyncinitRuntimeAutomator(t){returnst("initRuntimeAutomator"),t.send("App.callUniMethod",{method:"$$initRuntimeAutomator",args:[]})}}module.exports=class{constructor(){this.launcher=newrt}asynclaunch(t){returnthis.launcher.launch(t)}};