vending-machine/mobile/node_modules/@dcloudio/uni-app-plus/lib/uni.automator.js
2026-04-03 06:07:13 +08:00

2 lines
21 KiB
JavaScript

"use strict";var e=require("fs"),t=require("path"),s=require("debug"),i=require("jsonc-parser"),r=require("fs-extra"),a=require("postcss-selector-parser"),o=require("licia/dateFormat"),n=require("util"),l=require("child_process"),c=require("dns");function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=d(e),p=d(t),h=d(s),m=d(r),f=d(a),y=d(o),v=d(c);function _(e){e.walk((e=>{if("tag"===e.type){const t=e.value;e.value="page"===t?"body":"uni-"+t}}))}h.default("automator:devtool");const P=["Page.getElement","Page.getElements","Element.getElement","Element.getElements"];const $=/^win/.test(process.platform);function I(e){try{return require(e)}catch(t){return require(require.resolve(e,{paths:[process.cwd()]}))}}const g=h.default("automator:launcher"),w=n.promisify(u.default.readdir),S=n.promisify(u.default.stat);async function N(e){const s=await w(e);return(await Promise.all(s.map((async s=>{const i=t.resolve(e,s);return(await S(i)).isDirectory()?N(i):i})))).reduce(((e,t)=>e.concat(t)),[])}class E{constructor(e){this.isX=!1,"true"===process.env.UNI_APP_X&&(this.isX=!0),this.id=e.id,this.app=e.executablePath,this.appid=e.appid||process.env.UNI_APP_ID||(this.isX?"__UNI__uniappx":"HBuilder"),this.package=e.package||(this.isX?"io.dcloud.uniappx":"io.dcloud.HBuilder"),this.activity=e.activity||(this.isX?"io.dcloud.uniapp.UniAppActivity":"io.dcloud.PandoraEntry"),this.projectPath=e.projectPath}shouldPush(){return this.exists(this.FILE_APP_SERVICE).then((()=>(g(`${y.default("yyyy-mm-dd HH:MM:ss:l")} ${this.FILE_APP_SERVICE} exists`),!1))).catch((()=>(g(`${y.default("yyyy-mm-dd HH:MM:ss:l")} ${this.FILE_APP_SERVICE} not exists`),!0)))}push(e){return N(e).then((s=>{const i=s.map((s=>{const i=(e=>$?e.replace(/\\/g,"/"):e)(t.join(this.DIR_WWW,t.relative(e,s)));return g(`${y.default("yyyy-mm-dd HH:MM:ss:l")} push ${s} ${i}`),this.pushFile(s,i)}));return Promise.all(i)})).then((e=>!0))}get FILE_APP_SERVICE(){return`${this.DIR_WWW}/app-service.js`}}const x=h.default("automator:simctl");function b(e){const t=parseInt(e);return t>9?String(t):"0"+t}class D extends E{constructor(){super(...arguments),this.bundleVersion=""}async init(){const e=I("node-simctl").Simctl;this.tool=new e({udid:this.id});try{await this.tool.bootDevice()}catch(e){}await this.initSDCard(),x(`${y.default("yyyy-mm-dd HH:MM:ss:l")} init ${this.id}`)}async initSDCard(){const e=await this.tool.appInfo(this.package);x(`${y.default("yyyy-mm-dd HH:MM:ss:l")} appInfo ${e}`);const t=e.match(/DataContainer\s+=\s+"(.*)"/);if(!t)return Promise.resolve("");const s=e.match(/CFBundleVersion\s+=\s+(.*);/);if(!s)return Promise.resolve("");this.sdcard=t[1].replace("file:",""),this.bundleVersion=s[1],x(`${y.default("yyyy-mm-dd HH:MM:ss:l")} install ${this.sdcard}`)}async version(){return Promise.resolve(this.bundleVersion)}formatVersion(e){const t=e.split(".");return 3!==t.length?e:t[0]+b(t[1])+b(t[2])}async install(){return x(`${y.default("yyyy-mm-dd HH:MM:ss:l")} install ${this.app}`),await this.tool.installApp(this.app),await this.tool.grantPermission(this.package,"all"),await this.initSDCard(),Promise.resolve(!0)}async start(){x("ios simulator start");try{await this.tool.terminateApp(this.package)}catch(e){console.error("ios simulator start terminateApp fail",e)}try{await this.tool.launchApp(this.package)}catch(e){console.error("ios simulator start launchApp fail",e),console.error(e)}return Promise.resolve(!0)}async exit(){return await this.tool.terminateApp(this.package),await this.tool.shutdownDevice(),Promise.resolve(!0)}async captureScreenshot(e){const t=await Promise.resolve(await this.tool.getScreenshot());return new Promise(((s,i)=>{var r,a;if(void 0!==(null===(r=null==e?void 0:e.area)||void 0===r?void 0:r.x)&&void 0!==(null===(a=null==e?void 0:e.area)||void 0===a?void 0:a.y)){const r=require("jimp");r.read(Buffer.from(t,"base64")).then((t=>{l.exec(`idb connect ${this.id} && idb describe --udid ${this.id}`,((a,o,n)=>{if(a)return console.error(`exec error: ${a}`),void s(`captureScreenshot fail: ${a}`);const l=o.indexOf("density="),c=o.indexOf(",",l),d=o.substring(l+8,c).trim(),u=parseFloat(d),p=e.area.x*u,h=e.area.y*u;let m=t.bitmap.width-p;e.area.width&&(m=Math.min(m,e.area.width*u));let f=t.bitmap.height-h;e.area.height&&(f=Math.min(f,e.area.height*u)),t.crop(p,h,m,f).getBase64Async(r.MIME_PNG).then((e=>{s(e.replace("data:image/png;base64,",""))})).catch((e=>{i(e)}))}))})).catch((e=>{i(e)}))}else s(t)}))}exists(e){return m.default.existsSync(e)?Promise.resolve(!0):Promise.reject(Error(`${e} not exists`))}pushFile(e,t){return Promise.resolve(m.default.copySync(e,t))}adbCommand(e){return new Promise(((e,t)=>{t("adbCommand only for App Android!")}))}swipe(e){return new Promise((t=>{const{startPoint:s,endPoint:i,duration:r}=e;l.exec(`idb connect ${this.id} && idb ui swipe ${s.x} ${s.y} ${i.x} ${i.y} --duration ${r?r/1e3:.1} --udid ${this.id}`,(e=>{if(e)return console.error(`exec error: ${e}`),void t(`swipe fail: ${e}`);t("swipe success")}))}))}tap(e){return new Promise((t=>{const{x:s,y:i,duration:r}=e,a=Math.round(s),o=Math.round(i);l.exec(`idb connect ${this.id} && idb ui tap ${a} ${o} --duration ${r?r/1e3:0} --udid ${this.id}`,(e=>{if(e)return console.error(`exec error: ${e}`),void t(`tap fail: ${e}`);t("tap success")}))}))}keyboardInput(e){return new Promise((t=>{l.exec(`idb connect ${this.id} && idb ui text ${e} --udid ${this.id}`,(e=>{if(e)return console.error(`exec error: ${e}`),void t(`tap fail: ${e}`);t("keyboardInput success")})),t("keyboardInput success")}))}get DIR_WWW(){return"true"===process.env.UNI_APP_X?`${this.sdcard}/Documents/uni-app-x/apps/__UNI__uniappx/www/`:`${this.sdcard}/Documents/Pandora/apps/${this.appid}/www/`}}const M=I("adbkit"),U=h.default("automator:adb");class A extends E{constructor(){super(...arguments),this.needStart=!0}async init(){if(console.log("app-plus/launcher/android.ts init start"),void 0!==v.default.setDefaultResultOrder&&v.default.setDefaultResultOrder("ipv4first"),console.log("app-plus/launcher/android.ts init before adb.createClient"),this.tool=M.createClient(),console.log("app-plus/launcher/android.ts init after adb.createClient"),U(`${y.default("yyyy-mm-dd HH:MM:ss:l")} init ${await this.tool.version()}`),console.log("app-plus/launcher/android.ts init after debugClient init this.tool.version"),!this.id){console.log("app-plus/launcher/android.ts init before listDevices");const e=await this.tool.listDevices();if(!e.length)throw Error("Device not found");console.log("app-plus/launcher/android.ts init this.id",this.id),this.id=e[0].id}console.log("app-plus/launcher/android.ts init before echo ${$EXTERNAL_STORAGE}"),this.sdcard=(await this.shell(this.COMMAND_EXTERNAL)).trim(),console.log("app-plus/launcher/android.ts init after echo ${$EXTERNAL_STORAGE}",this.sdcard),U(`${y.default("yyyy-mm-dd HH:MM:ss:l")} init ${this.id} ${this.sdcard}`),console.log("app-plus/launcher/android.ts init after debugClient init this.id this.sdcard")}root(){return this.tool.root(this.id).then((()=>{U(`${y.default("yyyy-mm-dd HH:MM:ss:l")} root ${this.id} ${this.sdcard}`)})).catch((e=>{U(`${y.default("yyyy-mm-dd HH:MM:ss:l")} root ${this.id} ${e}`)}))}version(){return this.shell(this.COMMAND_VERSION).then((e=>{const t=e.match(/versionName=(.*)/);return t&&t.length>1?t[1]:""}))}formatVersion(e){return e}async install(){let e=!0;try{const t=(await this.tool.getProperties(this.id))["ro.build.version.release"].split(".")[0];parseInt(t)<6&&(e=!1)}catch(e){}if(U(`${y.default("yyyy-mm-dd HH:MM:ss:l")} install ${this.app} permission=${e}`),e){const e=I("adbkit/lib/adb/command.js"),t=e.prototype._send;e.prototype._send=function(e){return 0===e.indexOf("shell:pm install -r ")&&(e=e.replace("shell:pm install -r ","shell:pm install -r -g "),U(`${y.default("yyyy-mm-dd HH:MM:ss:l")} ${e} `)),t.call(this,e)}}return this.tool.install(this.id,this.app).then((()=>{U(`${y.default("yyyy-mm-dd HH:MM:ss:l")} installed`),this.init(),console.log("app-plus/launcher/android.ts this.tool.install after this.init")}))}start(){return this.needStart?this.exit().then((()=>this.shell(this.COMMAND_START))):Promise.resolve()}exit(){return this.shell(this.COMMAND_STOP)}captureScreenshot(e){const t=this;return this.tool.screencap(this.id).then((s=>new Promise(((i,r)=>{const a=[];s.on("data",(function(e){a.push(e)})),s.on("end",(function(){var s,o;if(void 0!==(null===(s=e.area)||void 0===s?void 0:s.x)&&void 0!==(null===(o=e.area)||void 0===o?void 0:o.y)){const s=require("jimp");s.read(Buffer.concat(a)).then((a=>{t.tool.shell(t.id,"wm density").then((t=>{let o,n="";t.on("data",(t=>{n+=t.toString(),o&&clearTimeout(o),o=setTimeout((()=>{var t,o,l,c,d;const u=parseInt(null===(t=n.split(":")[1])||void 0===t?void 0:t.trim()),p=u?u/160:1,h=e.area.x*p,m=e.area.y*p;let f=a.bitmap.width-h;(null===(o=e.area)||void 0===o?void 0:o.width)&&(f=Math.min(f,(null===(l=e.area)||void 0===l?void 0:l.width)*p));let y=a.bitmap.height-m;(null===(c=e.area)||void 0===c?void 0:c.height)&&(y=Math.min(y,(null===(d=e.area)||void 0===d?void 0:d.height)*p)),a.crop(h,m,f,y).getBase64Async(s.MIME_PNG).then((e=>{i(e.replace("data:image/png;base64,",""))})).catch((e=>{r(e)}))}),50)}))}))})).catch((e=>{r(e)}))}else i(Buffer.concat(a).toString("base64"))}))}))))}adbCommand(e){return new Promise((t=>{this.tool.shell(this.id,e).then((e=>{let s,i="";e.on("data",(e=>{i+=e.toString(),s&&clearTimeout(s),s=setTimeout((()=>{t(i)}),50)})),setTimeout((()=>{t(i)}),1500)}))}))}swipe(e){return new Promise((t=>{this.tool.shell(this.id,"wm density").then((s=>{let i,r="";s.on("data",(s=>{r+=s.toString(),i&&clearTimeout(i),i=setTimeout((()=>{var s;const i=parseInt(null===(s=r.split(":")[1])||void 0===s?void 0:s.trim()),a=i?i/160:1,o=`input swipe ${e.startPoint.x*a} ${e.startPoint.y*a} ${e.endPoint.x*a} ${e.endPoint.y*a} ${e.duration||100}`;this.tool.shell(this.id,o).then((e=>{let s,i="";e.on("data",(e=>{i+=e.toString(),s&&clearTimeout(s),s=setTimeout((()=>{t(i)}),50)})),setTimeout((()=>{t(i)}),1500)}))}),50)}))}))}))}keyboardInput(e){return new Promise((t=>{this.tool.shell(this.id,`input text ${e}`).then((e=>{let s,i="";e.on("data",(e=>{i+=e.toString(),s&&clearTimeout(s),s=setTimeout((()=>{t(i)}),50)})),setTimeout((()=>{t(i)}),1500)}))}))}tap(e){return new Promise((t=>{this.tool.shell(this.id,"wm density").then((s=>{let i,r="";s.on("data",(s=>{r+=s.toString(),i&&clearTimeout(i),i=setTimeout((()=>{var s;const i=parseInt(null===(s=r.split(":")[1])||void 0===s?void 0:s.trim()),a=i?i/160:1,o=e.x*a,n=e.y*a,l=`input swipe ${o} ${n} ${o} ${n} ${e.duration||0}`;this.tool.shell(this.id,l).then((e=>{let s,i="";e.on("data",(e=>{i+=e.toString(),s&&clearTimeout(s),s=setTimeout((()=>{t(i)}),50)})),setTimeout((()=>{t(i)}),1500)}))}),50)}))}))}))}exists(e){return this.tool.stat(this.id,e)}pushFile(e,t){return this.tool.push(this.id,e,t)}async push(e){if(!process.env.UNI_HBUILDERX_PLUGINS)return super.push(e);const t=p.default.join(process.env.UNI_HBUILDERX_PLUGINS,"launcher","out","export","pushResources.js"),s=process.env.HX_CONFIG_ADB_PATH||p.default.join(process.env.UNI_HBUILDERX_PLUGINS,"launcher-tools","tools","adbs","adb"),i=[t,s].map((e=>u.default.promises.access(e,u.default.constants.F_OK).then((()=>`${e} exists`)).catch((()=>`${e} not exists`))));return Promise.all(i).then((()=>{const{PushResources:i}=require(t);return new i({adbPath:s,appid:process.env.UNI_TEST_BASE_APPID||this.appid,uuid:this.id,packageName:process.env.UNI_TEST_BASE_PACKAGE_NAME||this.package,sourcePath:e}).start(),this.needStart=!1,!0})).catch((async t=>(console.log("pushResources or adb not exists: ",t),await super.push(e))))}shell(e){return U(`${y.default("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${e}`),this.tool.shell(this.id,e).then(M.util.readAll).then((e=>{const t=e.toString();return U(`${y.default("yyyy-mm-dd HH:MM:ss:l")} ◀ RECV ${t}`),t}))}get DIR_WWW(){return`/storage/emulated/0/Android/data/${this.package}/apps/${this.appid}/www`}get COMMAND_EXTERNAL(){return"echo $EXTERNAL_STORAGE"}get COMMAND_VERSION(){return`dumpsys package ${this.package}`}get COMMAND_STOP(){return`am force-stop ${this.package}`}get COMMAND_START(){return`am start -n ${this.package}/${this.activity} --es appid ${this.appid} --ez needUpdateApp false --ez reload true --ez externalStorage true`}}const T=h.default("automator:simctl");function R(e){const t=parseInt(e);return t>9?String(t):"0"+t}class H extends E{constructor(){super(...arguments),this.bundleVersion="harmony bundle version",this.hdcPath=`${this.app}/Contents/sdk/default/openharmony/toolchains/hdc`}async init(){T(`${y.default("yyyy-mm-dd HH:MM:ss:l")} init in harmony ${this.id}`)}async version(){return Promise.resolve(this.bundleVersion)}formatVersion(e){if(!e)return this.bundleVersion;const t=e.split(".");return 3!==t.length?e:t[0]+R(t[1])+R(t[2])}async install(){return T(`${y.default("yyyy-mm-dd HH:MM:ss:l")} install ${this.app}`),Promise.resolve(!0)}async start(){if(T("harmony start"),!this.app)return Promise.reject("executablePath is required");if(!this.projectPath)return Promise.reject("projectPath is required");const{run:e}=require(p.default.join(process.env.UNI_HBUILDERX_PLUGINS,"launcher","out","export","HarmonyLauncher"));return await e({devToolsPath:this.app,projectPath:this.projectPath,compilePath:process.env.UNI_OUTPUT_DIR,udid:this.id,getui_appid:process.env.UNI_getui_appid||"",harmony_client_id:process.env.UNI_harmony_client_id||"",getui_verify_appid:process.env.UNI_getui_verify_appid||""}),Promise.resolve(!0)}async exit(){return await this.tool.terminateApp(this.package),await this.tool.shutdownDevice(),Promise.resolve(!0)}async captureScreenshot(e){return new Promise(((t,s)=>{l.exec(`${this.hdcPath} shell snapshot_display -f /data/local/tmp/screenshot.jpeg`,((i,r,a)=>{i?s(`captureScreenshot fail: ${i.message}`):a?s(`captureScreenshot fail: ${a}`):l.exec(`${this.hdcPath} file recv /data/local/tmp/screenshot.jpeg ./screenshot.png`,((i,r,a)=>{var o,n;if(i)return void s(`captureScreenshot fail: ${i.message}`);if(a)return void s(`captureScreenshot fail: ${a}`);const c=m.default.readFileSync("./screenshot.png").toString("base64");if(m.default.unlinkSync("./screenshot.png"),void 0!==(null===(o=e.area)||void 0===o?void 0:o.x)&&void 0!==(null===(n=e.area)||void 0===n?void 0:n.y)){const i=require("jimp");i.read(Buffer.from(c,"base64")).then((r=>{l.exec(`${this.hdcPath} shell hidumper -s DisplayManagerService -a -a`,((a,o,n)=>{if(a)return void s(`captureScreenshot fail: ${a.message}`);if(n)return void s(`captureScreenshot fail: ${n}`);const l=o.indexOf("Density:"),c=o.indexOf("DensityInCurResolution",l),d=o.slice(l+8,c),u=parseFloat(d),p=Math.floor(e.area.x*u),h=Math.floor(e.area.y*u);let m=r.bitmap.width-p;e.area.width&&(m=Math.min(m,Math.floor(e.area.width*u)));let f=r.bitmap.height-h;e.area.height&&(f=Math.min(f,Math.floor(e.area.height*u))),r.crop(p,h,m,f).getBase64Async(i.MIME_PNG).then((e=>{t(e.replace("data:image/png;base64,",""))})).catch((e=>{s(e)}))}))}))}else t(c)}))}))}))}exists(e){return m.default.existsSync(e)?Promise.resolve(!0):Promise.reject(Error(`${e} not exists`))}pushFile(e,t){return Promise.resolve(Promise.resolve())}adbCommand(e){return new Promise(((e,t)=>{t("adbCommand only for App Android!")}))}swipe(e){return new Promise(((t,s)=>{l.exec(`${this.hdcPath} shell hidumper -s DisplayManagerService -a -a`,((i,r,a)=>{if(i)return void s(`swipe fail: ${i.message}`);if(a)return void s(`swipe fail: ${a}`);const o=r.indexOf("Density:"),n=r.indexOf("DensityInCurResolution",o),c=r.slice(o+8,n),d=parseFloat(c);let u=Math.max(Math.abs(e.endPoint.x-e.startPoint.x),Math.abs(e.endPoint.y-e.startPoint.y))*d/(e.duration/1e3);u<200?u=200:u>4e4&&(u=4e4);const p=`${this.hdcPath} shell uitest uiInput swipe ${e.startPoint.x*d} ${e.startPoint.y*d} ${e.endPoint.x*d} ${e.endPoint.y*d} ${u}`;l.exec(p,((e,i,r)=>{e?s(`swipe fail: ${e.message}`):r?s(`swipe fail: ${r}`):t("swipe success")}))}))}))}tap(e){return new Promise(((t,s)=>{l.exec(`${this.hdcPath} shell hidumper -s DisplayManagerService -a -a`,((i,r,a)=>{if(i)return void s(`tap fail: ${i.message}`);if(a)return void s(`tap fail: ${a}`);const o=r.indexOf("Density:"),n=r.indexOf("DensityInCurResolution",o),c=r.slice(o+8,n),d=parseFloat(c),u=`${this.hdcPath} shell uitest uiInput ${e.duration&&e.duration>=350?"longClick":"click"} ${e.x*d} ${e.y*d}`;l.exec(u,((e,i,r)=>{e?s(`tap fail: ${e.message}`):r?s(`tap fail: ${r}`):t("tap success")}))}))}))}keyboardInput(e){return new Promise(((e,t)=>{t("harmony keyboardInput tap not support yet")}))}get DIR_WWW(){return""}}const C=h.default("automator:devtool");let O,k=!1;const j={android:/android_version=(.*)/,ios:/iphone_version=(.*)/};const X={"Tool.close":{reflect:async()=>{}},"App.exit":{reflect:async()=>O.exit()},"App.enableLog":{reflect:()=>Promise.resolve()},"App.captureScreenshotWithDevice":{reflect:async(e,t)=>{const s=await O.captureScreenshot(t);return C(`App.captureScreenshot ${s.length}`),{data:s}}},"App.adbCommand":{reflect:async(e,t)=>{const s=await O.adbCommand(t);return C(`App.adbCommand ${s.length}`),{data:s}}},"App.swipe":{reflect:async(e,t)=>{const s=await O.swipe(t);return C(`App.swipe ${s.length}`),{data:s}}},"App.tap":{reflect:async(e,t)=>{const s=await O.tap(t);return C(`App.tap ${s.length}`),{data:s}}},"App.keyboardInput":{reflect:async(e,t)=>{const s=await O.keyboardInput(t);return C(`App.keyboardInput ${s.length}`),{data:s}}}};!function(e){P.forEach((t=>{e[t]=function(e){return{reflect:async(t,s)=>t(e,s,!1),params:e=>(e.selector&&(e.selector=f.default(_).processSync(e.selector)),e)}}(t)}))}(X);const F={devtools:{name:"App",paths:[],required:["manifest.json","app-service.js"],validate:async function(e,t){e.platform=(e.platform||process.env.UNI_OS_NAME).toLocaleLowerCase(),Object.assign(e,e[e.platform]),O=function(e,t){return"ios"===e?new D(t):"harmony"===e?new H(t):new A(t)}(e.platform,e),await O.init();const s=await O.version();if(s){if(e.version){const t=O.formatVersion(function(e,t){if(e.endsWith(".txt"))try{const s=u.default.readFileSync(e).toString().match(j[t]);if(s)return s[1]}catch(e){console.error(e)}return e}(e.version,e.platform));C(`version: ${s}`),C(`newVersion: ${t}`),t!==s&&(k=!0)}}else k=!0;if(k){if(!e.executablePath)throw Error(`app-plus->${e.platform}->executablePath is not provided`);if(!u.default.existsSync(e.executablePath))throw Error(`${e.executablePath} not exists`)}return e},create:async function(e,t,s){k&&await O.install(),(k||s.compiled||await O.shouldPush())&&await O.push(e),await O.start()}},adapter:X,beforeCompile(e){if(process.env.UNI_INPUT_DIR&&"true"===process.env.UNI_AUTOMATOR_APP_WEBVIEW){const t=i.parse(r.readFileSync(p.default.resolve(process.env.UNI_INPUT_DIR,"manifest.json"),"utf8")),s=p.default.resolve(process.env.UNI_INPUT_DIR,"unpackage",".automator","app-webview");process.env.UNI_INPUT_DIR=p.default.resolve(s,"src"),process.env.UNI_OUTPUT_DIR=p.default.resolve(s,"unpackage","dist","dev"),r.existsSync(process.env.UNI_INPUT_DIR)&&r.emptyDirSync(process.env.UNI_INPUT_DIR),r.copySync(p.default.resolve(e,"lib","app-webview","project"),process.env.UNI_INPUT_DIR);const a=i.parse(r.readFileSync(p.default.resolve(process.env.UNI_INPUT_DIR,"manifest.json"),"utf8"));r.writeFileSync(p.default.resolve(process.env.UNI_INPUT_DIR,"manifest.json"),JSON.stringify(Object.assign(Object.assign({},a),{name:t.name||"",appid:t.appid||""}),null,2))}else if(process.env.UNI_INPUT_DIR&&"ios"===process.env.UNI_OS_NAME&&O.app&&O.app.endsWith(".app")){const e=p.default.resolve(process.env.UNI_INPUT_DIR,"uni_modules");if(!u.default.existsSync(e))return;if(!r.readdirSync(e).some((t=>r.existsSync(p.default.resolve(e,t,"utssdk")))))return;process.env.UNI_APP_X="true"===process.env.UNI_APP_X?"1":"",process.env.HX_DEPENDENCIES_DIR=p.default.join(process.env.UNI_OUTPUT_DIR,"../../../cache/.automator/uts_standard_simulator"),process.env.HX_RUN_DEVICE_TYPE="ios_simulator",O.app&&(process.env.UTS_BASE_INFO=u.default.readFileSync(p.default.resolve(O.app,"Frameworks/DCloudUTSFoundation.framework/uts-info.json"),"utf8")),!process.env.HX_Version&&process.env.UNI_HBUILDERX_PLUGINS&&(process.env.HX_Version=require(p.default.join(process.env.UNI_HBUILDERX_PLUGINS,"about","package.json")).version),C("HX_DEPENDENCIES_DIR",process.env.HX_DEPENDENCIES_DIR),C("UTS_BASE_INFO",process.env.UTS_BASE_INFO)}},afterCompile(){if("ios_simulator"===process.env.HX_RUN_DEVICE_TYPE&&O.app){process.env.UNI_APP_X="1"===process.env.UNI_APP_X?"true":"false";const t=p.default.resolve(process.env.HX_DEPENDENCIES_DIR,"Resources"),s=p.default.resolve(process.env.HX_DEPENDENCIES_DIR,"modules"),i=u.default.existsSync(t),a=u.default.existsSync(s),o=(e=p.default.basename(O.app),p.default.resolve(process.env.HX_DEPENDENCIES_DIR,".automator/"+e));if(!i&&!a)return;if(r.existsSync(o)&&r.emptyDirSync(o),r.copySync(O.app,o),O.app=o,i&&r.copySync(t,p.default.resolve(O.app)),a){const e=[];r.readdirSync(s).forEach((t=>{t.endsWith(".framework")&&(e.push(t),r.copySync(p.default.join(s,t),p.default.resolve(O.app,"Frameworks",t)))})),e.forEach((e=>{const t=`'${process.env.UNI_HBUILDERX_PLUGINS}/launcher-tools/tools/uts/optool' 'install' '-c' 'weak' '-p' '@rpath/${e}/${e.replace(".framework","")}' '-t' '${O.app}'`;try{const e=l.execSync(t);C(t,e.toString())}catch(e){console.error(e.message),console.error(e.stdout.toString())}}))}if(i||a){const e=l.execSync(`codesign -fs "-" "${O.app}"`);C("codesign success",e.toString())}}var e}};module.exports=F;