Files
2026-09-08 20:28:54 +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"),d=require("os");function p(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=p(e),h=p(t),m=p(s),y=p(r),f=p(a),v=p(o),_=p(c),P=p(d);function $(e){e.walk((e=>{if("tag"===e.type){const t=e.value;e.value="page"===t?"body":"uni-"+t}}))}m.default("automator:devtool");const g=["Page.getElement","Page.getElements","Element.getElement","Element.getElements"];const I=/^win/.test(process.platform);function w(e){try{return require(e)}catch(t){return require(require.resolve(e,{paths:[process.cwd()]}))}}const S=m.default("automator:launcher"),N=n.promisify(u.default.readdir),E=n.promisify(u.default.stat);async function x(e){const s=await N(e);return(await Promise.all(s.map((async s=>{const i=t.resolve(e,s);return(await E(i)).isDirectory()?x(i):i})))).reduce(((e,t)=>e.concat(t)),[])}class D{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((()=>(S(`${v.default("yyyy-mm-dd HH:MM:ss:l")} ${this.FILE_APP_SERVICE} exists`),!1))).catch((()=>(S(`${v.default("yyyy-mm-dd HH:MM:ss:l")} ${this.FILE_APP_SERVICE} not exists`),!0)))}push(e){return x(e).then((s=>{const i=s.map((s=>{const i=(e=>I?e.replace(/\\/g,"/"):e)(t.join(this.DIR_WWW,t.relative(e,s)));return S(`${v.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 b=m.default("automator:simctl");function M(e){const t=parseInt(e);return t>9?String(t):"0"+t}class U extends D{constructor(){super(...arguments),this.bundleVersion=""}async init(){const e=w("node-simctl").Simctl;this.tool=new e({udid:this.id});try{await this.tool.bootDevice()}catch(e){}await this.initSDCard(),b(`${v.default("yyyy-mm-dd HH:MM:ss:l")} init ${this.id}`)}async initSDCard(){const e=await this.tool.appInfo(this.package);b(`${v.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],b(`${v.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]+M(t[1])+M(t[2])}async install(){return b(`${v.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(){b("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)}exists(e){return y.default.existsSync(e)?Promise.resolve(!0):Promise.reject(Error(`${e} not exists`))}pushFile(e,t){return Promise.resolve(y.default.copySync(e,t))}adbCommand(e){return new Promise(((e,t)=>{t("adbCommand only for App Android!")}))}getDensity(e,t,s){l.exec(`idb connect ${this.id} && idb describe --udid ${this.id}`,((i,r,a)=>{if(i)return console.error(`exec error: ${i}`),void e(`${t} fail: ${i}`);const o=r.indexOf("density="),n=r.indexOf(",",o),l=r.substring(o+8,n).trim(),c=parseFloat(l);s(c)}))}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=>{this.getDensity(i,"captureScreenshot",(a=>{const o=e.area.x*a,n=e.area.y*a;let l=t.bitmap.width-o;e.area.width&&(l=Math.min(l,e.area.width*a));let c=t.bitmap.height-n;e.area.height&&(c=Math.min(c,e.area.height*a)),t.crop(o,n,l,c).getBase64Async(r.MIME_PNG).then((e=>{s(e.replace("data:image/png;base64,",""))})).catch((e=>{i(e)}))}))})).catch((e=>{i(e)}))}else s(t)}))}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.text} --udid ${this.id}`,(e=>{if(e)return console.error(`exec error: ${e}`),void t(`tap fail: ${e}`);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 A=w("adbkit"),T=m.default("automator:adb");class H extends D{constructor(){super(...arguments),this.needStart=!0}async init(){if(console.log("app-plus/launcher/android.ts init start"),void 0!==_.default.setDefaultResultOrder&&_.default.setDefaultResultOrder("ipv4first"),console.log("app-plus/launcher/android.ts init before adb.createClient"),this.tool=A.createClient(),console.log("app-plus/launcher/android.ts init after adb.createClient"),T(`${v.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),T(`${v.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((()=>{T(`${v.default("yyyy-mm-dd HH:MM:ss:l")} root ${this.id} ${this.sdcard}`)})).catch((e=>{T(`${v.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(T(`${v.default("yyyy-mm-dd HH:MM:ss:l")} install ${this.app} permission=${e}`),e){const e=w("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 "),T(`${v.default("yyyy-mm-dd HH:MM:ss:l")} ${e} `)),t.call(this,e)}}return this.tool.install(this.id,this.app).then((()=>{T(`${v.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(e){return this.needStart||e?this.exit().then((()=>this.shell(this.COMMAND_START))):Promise.resolve()}exit(){return this.shell(this.COMMAND_STOP)}getDensity(e){this.tool.shell(this.id,"wm density").then((t=>{let s,i="";t.on("data",(t=>{i+=t.toString(),s&&clearTimeout(s),s=setTimeout((()=>{var t;const s=parseInt(null===(t=i.split(":")[1])||void 0===t?void 0:t.trim());e(s?s/160:1)}),50)}))}))}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.getDensity((t=>{var o,n,l,c;const d=e.area.x*t,p=e.area.y*t;let u=a.bitmap.width-d;(null===(o=e.area)||void 0===o?void 0:o.width)&&(u=Math.min(u,(null===(n=e.area)||void 0===n?void 0:n.width)*t));let h=a.bitmap.height-p;(null===(l=e.area)||void 0===l?void 0:l.height)&&(h=Math.min(h,(null===(c=e.area)||void 0===c?void 0:c.height)*t)),a.crop(d,p,u,h).getBase64Async(s.MIME_PNG).then((e=>{i(e.replace("data:image/png;base64,",""))})).catch((e=>{r(e)}))}))})).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.getDensity((s=>{const i=`input swipe ${e.startPoint.x*s} ${e.startPoint.y*s} ${e.endPoint.x*s} ${e.endPoint.y*s} ${e.duration||100}`;this.tool.shell(this.id,i).then((e=>{let s,i="";e.on("data",(e=>{i+=e.toString(),s&&clearTimeout(s),s=setTimeout((()=>{t(i)}),50)})),setTimeout((()=>{t(i)}),1500)}))}))}))}keyboardInput(e){return new Promise((t=>{this.tool.shell(this.id,`input text ${e.text}`).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.getDensity((s=>{const i=e.x*s,r=e.y*s,a=`input swipe ${i} ${r} ${i} ${r} ${e.duration||0}`;this.tool.shell(this.id,a).then((e=>{let s,i="";e.on("data",(e=>{i+=e.toString(),s&&clearTimeout(s),s=setTimeout((()=>{t(i)}),50)})),setTimeout((()=>{t(i)}),1500)}))}))}))}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=h.default.join(process.env.UNI_HBUILDERX_PLUGINS,"launcher","out","export","pushResources.js"),s=process.env.HX_CONFIG_ADB_PATH||h.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 T(`${v.default("yyyy-mm-dd HH:MM:ss:l")} SEND ► ${e}`),this.tool.shell(this.id,e).then(A.util.readAll).then((e=>{const t=e.toString();return T(`${v.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 R=m.default("automator:simctl");function C(e){const t=parseInt(e);return t>9?String(t):"0"+t}class k extends D{constructor(){super(...arguments),this.bundleVersion="harmony bundle version",this.hdcPath="win32"===P.default.platform()?`${this.app}/sdk/default/openharmony/toolchains/hdc.exe`:`${this.app}/Contents/sdk/default/openharmony/toolchains/hdc`,this.compiled=!1}async init(){R(`${v.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]+C(t[1])+C(t[2])}async install(){return R(`${v.default("yyyy-mm-dd HH:MM:ss:l")} install ${this.app}`),Promise.resolve(!0)}async start(e){if(R("harmony start"),!this.app)return Promise.reject("executablePath is required");if(!this.projectPath)return Promise.reject("projectPath is required");const t=process.env.HX_APP_ROOT||".",{HarmonyLauncher:s,run:i}=require(h.default.join(t,"plugins/launcher/out/export/HarmonyLauncher"));if(!process.env.UNI_OUTPUT_DIR||e||this.compiled){const e=new s;await e.init({devToolsPath:this.app,projectPath:this.projectPath,compilePath:"",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||""}),await e.runHap()}else this.compiled=!0,await i({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||""});return Promise.resolve(!0)}async exit(){return await this.tool.terminateApp(this.package),await this.tool.shutdownDevice(),Promise.resolve(!0)}exists(e){return y.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!")}))}getDensity(e,t,s){l.exec(`"${this.hdcPath}" shell hidumper -s DisplayManagerService -a -a`,((i,r,a)=>{if(i)return void e(`${t} fail: ${i.message}`);if(a)return void e(`${t} fail: ${a}`);const o=r.indexOf("Density:"),n=r.indexOf("DensityInCurResolution",o),l=r.slice(o+8,n),c=parseFloat(l);s(c)}))}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 l=y.default.readFileSync("./screenshot.png").toString("base64");if(y.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(l,"base64")).then((r=>{this.getDensity(s,"captureScreenshot",(a=>{const o=Math.floor(e.area.x*a),n=Math.floor(e.area.y*a);let l=r.bitmap.width-o;e.area.width&&(l=Math.min(l,Math.floor(e.area.width*a)));let c=r.bitmap.height-n;e.area.height&&(c=Math.min(c,Math.floor(e.area.height*a))),r.crop(o,n,l,c).getBase64Async(i.MIME_PNG).then((e=>{t(e.replace("data:image/png;base64,",""))})).catch((e=>{s(e)}))}))}))}else t(l)}))}))}))}swipe(e){return new Promise(((t,s)=>{this.getDensity(s,"swipe",(i=>{let r=Math.max(Math.abs(e.endPoint.x-e.startPoint.x),Math.abs(e.endPoint.y-e.startPoint.y))*i/(e.duration/1e3);r<200?r=200:r>4e4&&(r=4e4);const a=`"${this.hdcPath}" shell uitest uiInput swipe ${e.startPoint.x*i} ${e.startPoint.y*i} ${e.endPoint.x*i} ${e.endPoint.y*i} ${r}`;l.exec(a,((e,i,r)=>{e?s(`swipe fail: ${e.message}`):r?s(`swipe fail: ${r}`):t("swipe success")}))}))}))}tap(e){return new Promise(((t,s)=>{this.getDensity(s,"tap",(i=>{const r=`"${this.hdcPath}" shell uitest uiInput ${e.duration&&e.duration>=350?"longClick":"click"} ${e.x*i} ${e.y*i}`;l.exec(r,((e,i,r)=>{e?s(`tap fail: ${e.message}`):r?s(`tap fail: ${r}`):t("tap success")}))}))}))}keyboardInput(e){return new Promise(((t,s)=>{void 0!==e.x&&void 0!==e.y?this.getDensity(s,"keyboardInput",(i=>{const r=`"${this.hdcPath}" shell uitest uiInput inputText ${e.x*i} ${e.y*i} ${e.text}`;l.exec(r,((e,i,r)=>{e?s(`keyboardInput fail: ${e.message}`):r?s(`keyboardInput fail: ${r}`):t("keyboardInput success")}))})):s("keyboardInput fail: harmony keyboardInput x or y is undefined")}))}get DIR_WWW(){return""}}const O=m.default("automator:devtool");let j,X=!1;const F={android:/android_version=(.*)/,ios:/iphone_version=(.*)/};const L={"Tool.close":{reflect:async()=>{}},"App.start":{reflect:async(e,t)=>j.start(t)},"App.exit":{reflect:async()=>j.exit()},"App.enableLog":{reflect:()=>Promise.resolve()},"App.captureScreenshotWithDevice":{reflect:async(e,t)=>{const s=await j.captureScreenshot(t);return O(`App.captureScreenshot ${s.length}`),{data:s}}},"App.adbCommand":{reflect:async(e,t)=>{const s=await j.adbCommand(t);return O(`App.adbCommand ${s.length}`),{data:s}}},"App.swipe":{reflect:async(e,t)=>{const s=await j.swipe(t);return O(`App.swipe ${s.length}`),{data:s}}},"App.tap":{reflect:async(e,t)=>{const s=await j.tap(t);return O(`App.tap ${s.length}`),{data:s}}},"App.keyboardInput":{reflect:async(e,t)=>{const s=await j.keyboardInput(t);return O(`App.keyboardInput ${s.length}`),{data:s}}}};!function(e){g.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)}))}(L);const V={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]),j=function(e,t){return"ios"===e?new U(t):"harmony"===e?new k(t):new H(t)}(e.platform,e),await j.init();const s=await j.version();if(s){if(e.version){const t=j.formatVersion(function(e,t){if(e.endsWith(".txt"))try{const s=u.default.readFileSync(e).toString().match(F[t]);if(s)return s[1]}catch(e){console.error(e)}return e}(e.version,e.platform));O(`version: ${s}`),O(`newVersion: ${t}`),t!==s&&(X=!0)}}else X=!0;if(X){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){X&&await j.install(),(X||s.compiled||await j.shouldPush())&&await j.push(e),await j.start()}},adapter:L,beforeCompile(e){if(process.env.UNI_INPUT_DIR&&"true"===process.env.UNI_AUTOMATOR_APP_WEBVIEW){const t=i.parse(r.readFileSync(h.default.resolve(process.env.UNI_INPUT_DIR,"manifest.json"),"utf8")),s=h.default.resolve(process.env.UNI_INPUT_DIR,"unpackage",".automator","app-webview");process.env.UNI_INPUT_DIR=h.default.resolve(s,"src"),process.env.UNI_OUTPUT_DIR=h.default.resolve(s,"unpackage","dist","dev"),r.existsSync(process.env.UNI_INPUT_DIR)&&r.emptyDirSync(process.env.UNI_INPUT_DIR),r.copySync(h.default.resolve(e,"lib","app-webview","project"),process.env.UNI_INPUT_DIR);const a=i.parse(r.readFileSync(h.default.resolve(process.env.UNI_INPUT_DIR,"manifest.json"),"utf8"));r.writeFileSync(h.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&&j.app&&j.app.endsWith(".app")){const e=h.default.resolve(process.env.UNI_INPUT_DIR,"uni_modules");if(!u.default.existsSync(e))return;if(!r.readdirSync(e).some((t=>r.existsSync(h.default.resolve(e,t,"utssdk")))))return;process.env.HX_DEPENDENCIES_DIR=h.default.join(process.env.UNI_OUTPUT_DIR,"../../../cache/.automator/uts_standard_simulator"),process.env.HX_RUN_DEVICE_TYPE="ios_simulator",j.app&&(process.env.UTS_BASE_INFO=u.default.readFileSync(h.default.resolve(j.app,"Frameworks/DCloudUTSFoundation.framework/uts-info.json"),"utf8")),!process.env.HX_Version&&process.env.UNI_HBUILDERX_PLUGINS&&(process.env.HX_Version=require(h.default.join(process.env.UNI_HBUILDERX_PLUGINS,"about","package.json")).version),O("HX_DEPENDENCIES_DIR",process.env.HX_DEPENDENCIES_DIR),O("UTS_BASE_INFO",process.env.UTS_BASE_INFO)}},afterCompile(){if("ios_simulator"===process.env.HX_RUN_DEVICE_TYPE&&j.app){const t=h.default.resolve(process.env.HX_DEPENDENCIES_DIR,"Resources"),s=h.default.resolve(process.env.HX_DEPENDENCIES_DIR,"modules"),i=u.default.existsSync(t),a=u.default.existsSync(s),o=(e=h.default.basename(j.app),h.default.resolve(process.env.HX_DEPENDENCIES_DIR,".automator/"+e));if(!i&&!a)return;if(r.existsSync(o)&&r.emptyDirSync(o),r.copySync(j.app,o),j.app=o,i&&r.copySync(t,h.default.resolve(j.app)),a){const e=[];r.readdirSync(s).forEach((t=>{t.endsWith(".framework")&&(e.push(t),r.copySync(h.default.join(s,t),h.default.resolve(j.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' '${j.app}'`;try{const e=l.execSync(t);O(t,e.toString())}catch(e){console.error(e.message),console.error(e.stdout.toString())}}))}if(i||a){const e=l.execSync(`codesign -fs "-" "${j.app}"`);O("codesign success",e.toString())}}var e}};module.exports=V;