"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.IMiniappConnectType=exports.IMiniappPkgType=void 0,exports.packAllPackagesToWxapkg=packAllPackagesToWxapkg,exports.generateSubPkgAppInfoJson=generateSubPkgAppInfoJson;const tslib_1=require("tslib"),path_1=tslib_1.__importDefault(require("path")),pack_1=tslib_1.__importDefault(require("../../../utils/wxapkg/pack")),tools_1=require("../../../utils/tools"),updatecontactandlaunch_1=require("./contactandlaunch/updatecontactandlaunch"),env_1=require("../../../utils/env");var IMiniappPkgType,IMiniappConnectType;async function packAllPackagesToWxapkg(e,t,a){const n=[],i=t.subpackages||t.subPackages,p=[];if(i){const o="__APP__",s=`${a}/${(0,tools_1.generateMD5)(o)}.wxapkg`,l=path_1.default.join(e,s),u=path_1.default.join(e,"app"),c=await(0,pack_1.default)(".",l,u,i.map(e=>path_1.default.join(".",e.root,"/**/*")));p.push(c),n.push({name:o,filePath:s,pkgType:4,md5:(0,tools_1.generateMD5)(c),size:c.byteLength,independent:!1,page_count:t.pages.length,alias:[],wxacode_lib_info_list:[],without_lib_md5:"",separated_plugin_list:[],md5_list:[],widget_list:[]});for(const t of i){const i=processSubpkgRootPath(t.root),o=`${a}/${(0,tools_1.generateMD5)(i)}.wxapkg`,s=path_1.default.join(e,o),l=await(0,pack_1.default)(t.root,s,u,[]);p.push(l),n.push({name:i,filePath:o,pkgType:4,md5:(0,tools_1.generateMD5)(l),size:l.byteLength,independent:!1,page_count:t.pages.length,alias:[],wxacode_lib_info_list:[],without_lib_md5:"",separated_plugin_list:[],md5_list:[],widget_list:[]})}}else{const i="__APP__",p=`${a}/${(0,tools_1.generateMD5)(i)}.wxapkg`,o=path_1.default.join(e,p),s=path_1.default.join(e,"app"),l=await(0,pack_1.default)(".",o,s);n.push({name:i,filePath:p,pkgType:0,md5:(0,tools_1.generateMD5)(l),size:l.byteLength,independent:!1,page_count:t.pages.length,alias:[],wxacode_lib_info_list:[],without_lib_md5:"",separated_plugin_list:[],md5_list:[],widget_list:[]})}const o=Buffer.concat(p);return{wholePkgMd5:(0,tools_1.generateMD5)(o),moduleListConfig:n}}async function generateSubPkgAppInfoJson(e){const{miniModuleId:t,nickName:a,pageOrientation:n,subpkgs:i,buildVersion:p,contact:o,cpfWxaAttrSyncResponse:s,miniappPkgType:l}=e,u=p||1,c=await(0,updatecontactandlaunch_1.updateLaunchBase64)();return{miniModuleId:t,nickname:a,device_orientation:n||"portrait",appVersion:u,pkgInfos:i.map(e=>{var a,n;return{miniModuleId:t,moduleName:e.name,pkgType:e.type,pkgMd5:e.md5,appVersion:u,versionType:e.versionType===IMiniappPkgType.Release?0:1,assetPath:e.file,signVersion:null!==(a=e.signVersion)&&void 0!==a?a:0,signFilePath:null!==(n=e.signFile)&&void 0!==n?n:e.file+".sign"}}),contactBase64:o,launchBase64:c,cpfWxaAttrSyncResponse:s,version:2,miniappPkgType:l,devtoolsPlatform:env_1.isWin?"Windows":"Mac"}}function processSubpkgRootPath(e){return e.startsWith("/")||(e="/"+e),e.endsWith("/")||(e+="/"),e}!function(e){e.Release="Release",e.Debug="Debug",e.HotReload="HotReload"}(IMiniappPkgType||(exports.IMiniappPkgType=IMiniappPkgType={})),function(e){e.USB="USB",e.LAN="LAN"}(IMiniappConnectType||(exports.IMiniappConnectType=IMiniappConnectType={}));