"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.buildIpa=buildIpa;const tslib_1=require("tslib"),log=tslib_1.__importStar(require("../utils/log")),checkBuildArgument_1=require("./miniapp/checkBuildArgument"),miniAppI18N_1=tslib_1.__importDefault(require("../utils/miniAppI18N")),miniappJson_1=require("../utils/miniappJson"),sdkManager_1=require("./miniapp/sdkManager"),tools_1=require("./utils/tools"),iosLocalBuild_1=require("./miniapp/iosLocalBuild"),miniappPlugin_1=require("./miniapp/miniappPlugin"),iosTheme_1=require("./miniapp/iosTheme"),report_1=require("../utils/report"),iosCloudBuild_1=require("./miniapp/iosCloudBuild");async function buildIpa(i){var e;const t=Date.now();let o;try{if(!i.project)throw new Error("缺少参数 project");const{project:e}=i;e.targetPlatform="mini-ios",await e.miniappAttr();const{buildArchiveOpts:t,cloudBuildInfo:a}=(0,checkBuildArgument_1.transformIOSBuildArgument)(i);i.disableCache&&((0,tools_1.clearIOSCacheDir)(),log.info("清除 Ipa 构建缓存成功")),o=await generateCloudIOSIPA(i,t,a)}catch(i){log.error("构建 Ipa 失败：",i.message),o={success:!1,errmsg:"构建 Ipa 失败："+i.message}}const a=Date.now()-t;return i.project&&(0,report_1.reportAction)("buildIpa",o.success?0:-1,`${o.errmsg}。 isRemoteBuild: ${null!==(e=i.isRemoteBuild)&&void 0!==e&&e}`,a,i.project),o}async function generateCloudIOSIPA(i,e,t){var o;const{project:a,output:r}=i;let s=!1,n="failed";try{miniAppI18N_1.default.createI18NInfo(a.projectPath);const{useCloudUpload:p,packageVersion:u,packageDesc:l,useRemoteCloudBuild:c,uploadAppInfo:d}=t;(0,miniappJson_1.autoCompleteIOSPrivacyDesc)(a.projectPath)||log.info("默认隐私信息访问许可描述添加成功");const m=(0,miniappJson_1.tryGetIOSMiniappJson)(a.projectPath),g=m.sdkVersion,{demoIpaPath:I,sdkPath:_}=await(0,sdkManager_1.generateMiniappIOSResources)(a,g,"arm64",!!m.enableIpad);p?(e.useCloudSync=!0,e.version=u,e.desc=l):(e.version=d?d.userVersion:"",e.desc=d?d.userDesc:"");const h=Object.assign(Object.assign({},i),{resourceDir:(0,tools_1.getMiniappCacheDir)(),robot:i.robot||1}),P=(0,miniappPlugin_1.getMiniappPluginManager)(h);await P.downloadPlugin(miniappPlugin_1.OS_TYPE_ENUM.IOS);const f=await P.getPluginDirList(miniappPlugin_1.OS_TYPE_ENUM.IOS),b=await(0,iosTheme_1.getIOSTheme)(a,null===(o=null==m?void 0:m.splashscreen)||void 0===o?void 0:o.customImage),O=await a.miniappAttr()||{},B=(0,tools_1.getMiniappCacheDir)(),C={buildType:"CLOUD",certificateInfo:t.certificateInfo,demoIpaPath:I,sdkPath:_,miniappCacheDirPath:B,bindingInfo:O,output:r,pluginDirList:f,theme:b,i18nInfo:miniAppI18N_1.default.i18nInfo,projectPath:a.projectPath};if(c){const i=(0,iosCloudBuild_1.getIOSCloudBuild)(h);await i.build(e,C,r)}else{C.CILocalBuild=!0;const i=(0,iosLocalBuild_1.getIOSLocalBuild)(h);await i.build(e,C,I)}log.success("构建 Ipa 成功"),s=!0,n="success! output file at "+r}catch(i){s=!1,n=i.message||i,log.error("构建 Ipa 失败：",n)}return{success:s,errmsg:n}}