"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.checkXcodeEnv=exports.codesignAndExport=void 0;const generateIpa_1=require("./generateIpa"),singletontask_1=require("./singletontask"),cp_1=require("./cp"),env_1=require("./env"),path=require("path"),signAndInstallTask={};async function codesignAndExport(e,n,t,s,i,r,a,c){var o;const{output:p}=s,d=path.join(__dirname,"../static/scripts/resignIpa"),l=await(0,generateIpa_1.generateIpa)(n,i),g=(null===(o=s.entitlements)||void 0===o?void 0:o["com.apple.developer.associated-domains"])||"";try{await checkXcodeEnv(i);const e=[l,p,s.outputAppWithName?s.outputAppWithName:"false",r?"true":"",g,t];let n=!1;if(s.certificate?(e.push(s.certificate),s.profile?(e.push(s.profile),n=!0,s.tpnsProfile&&(e.push(s.tpnsProfile),i.message("doing","certificate: find tpns profile"))):i.message("error","certificate: cant find profile")):!0===c?n=!0:i.message("error","certificate: cant find certificate"),!n)throw i.message("error","codesignAndExport missing needed info"),new Error("Failed! codesignAndExport missing needed info");return signAndInstallTask[l]||(signAndInstallTask[l]=new singletontask_1.SingletonTask(cp_1.spawnSyncExecShell.bind(null,d,e,{},i))),await signAndInstallTask[l].getResult(!0),{success:!0}}catch(e){return{success:!1,errMsg:e.message}}finally{delete signAndInstallTask[l]}}async function checkXcodeEnv(e){if(env_1.isWin)throw new Error("windows下不能使用分发证书签名。需启用远程构建");const n=path.join(__dirname,"../static/scripts/checkXcodeEnv");await(0,cp_1.spawnSyncExecShell)(n,[],{},e)}exports.codesignAndExport=codesignAndExport,exports.checkXcodeEnv=checkXcodeEnv;