"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getCompiledResult=getCompiledResult;const tslib_1=require("tslib"),fs_extra_1=tslib_1.__importDefault(require("fs-extra")),config_1=require("../config/config"),error_1=require("../utils/error"),locales_1=tslib_1.__importDefault(require("../utils/locales/locales")),cache_1=require("../utils/cache"),progressupdate_1=require("./utils/progressupdate"),jszip_1=tslib_1.__importDefault(require("jszip")),path_1=tslib_1.__importDefault(require("path")),getcompiler_1=require("./getcompiler"),tools_1=require("./utils/tools");async function getCompiledResult(e,t){const{project:r,setting:s={},onProgressUpdate:o=(()=>{}),threads:i=0,includedMap:a=!1}=e;if(process.env.COMPILE_THREADS=i.toString(),!r)throw new error_1.CodeError(locales_1.default.config.PARAM_ERROR.format("upload","project"),config_1.PARAM_ERROR);cache_1.cacheManager.clean();const l=await(0,getcompiler_1.getCompiler)(r,s),_=await l.compile({setting:(0,tools_1.formatCISetting)(r,s),onProgressUpdate:(0,progressupdate_1.transProgressUpdate)(o),resultType:"prod",disableSpreadingUsingComponents:!0}),p={};if(Object.keys(_).sort().forEach(e=>{e.endsWith("js.map")&&!a||(p[e]=_[e])}),t){const e=new jszip_1.default;Object.keys(p).forEach(t=>{e.folder(path_1.default.dirname(t)).file(path_1.default.basename(t),p[t])});const r=await e.generateAsync({type:"nodebuffer"});fs_extra_1.default.ensureDirSync(path_1.default.dirname(t)),fs_extra_1.default.writeFileSync(t,r)}return p}