"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.generateIpa=generateIpa;const zip_1=require("./zip"),path=require("path"),os=require("os"),fse=require("fs-extra");async function generateIpa(e,i,t){let p="";if(e.endsWith(".app")){null==t||t.progress("packing the ipa...");const r=path.basename(e),s=os.tmpdir();p=path.join(s,"miniapp-unsigned.ipa");const a=path.join(s,"appdir"),n=path.join(a,"Payload");if(fse.existsSync(a)&&fse.removeSync(a),fse.ensureDirSync(n),fse.copySync(e,path.join(n,r)),fse.existsSync(p)&&fse.removeSync(p),i){null==t||t.progress("start packing swift");const i=path.join(a,"SwiftSupport/iphoneos"),p=path.join(e,"../../../../SwiftSupport");null==t||t.progress("SwiftSupportCachePath: "+p),fse.existsSync(p)&&(null==t||t.progress("SwiftSupportCachePath exit: "+p),fse.ensureDirSync(i),fse.copySync(p,path.join(i)))}try{await(0,zip_1.archiveZip)(a,p)}catch(e){throw new Error("generateIpa failed archiveZip file")}}else{if(!e.endsWith(".ipa"))throw new Error("invalid ipa/.app file");p=e}return p}