"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.compileUseWCSC=compileUseWCSC;const tslib_1=require("tslib"),nativeModule_1=require("../../nativeModule/common/nativeModule"),getservice_1=tslib_1.__importDefault(require("../../common/getservice")),genTempFileService_1=require("../../genTempFile/common/genTempFileService"),common_1=require("../../../utils/node/common"),tools_1=require("../../../utils/tools"),fs=require("fs"),cp=require("child_process");async function compileUseWCSC(e){const{files:t,pageCount:o,lazyload:i,cwd:n,subPackage:r=""}=e;if(!o)return{common:"",pageWxss:{}};const s=["-db","-pc",""+o].concat(t);r&&(s.push("--subpackage"),s.push(r.replace(/\/$/,""))),i&&s.push("-ll");const c=await(0,getservice_1.default)(genTempFileService_1.IGenTempFile).genPath(),l=(0,common_1.shouldUseConfigFile)(s);l&&fs.writeFileSync(c,s.join("\n"));const u=await(0,getservice_1.default)(nativeModule_1.INativeModuleService).getWXSSParsePath(),a=cp.spawn(u,l?["--config-path",(0,tools_1.normalizePath)(c)]:s,{cwd:n}),p=[],m=[];return a.stdout.on("data",e=>{p.push(e)}),a.stderr.on("data",e=>{m.push(e)}),new Promise((e,t)=>{a.on("close",o=>{if(l&&fs.unlinkSync(c),0===o){const t=Buffer.concat(p).toString();let o={};if(i)o=JSON.parse(t);else{const e=t.split("=");for(let t=0,i=e.length;t<i&&e[t+1];t+=2)o[e[t]]=e[t+1]}return e(o)}return t(new Error(Buffer.concat(m).toString()))})})}