const libxmljs=require("libxmljs"),{readFile:readFile,readDir:readDir,stat:stat,isPrefabProject:isPrefabProject,getWmProjectPropertiesFilePath:getWmProjectPropertiesFilePath,getAuthInfoFilePath:getAuthInfoFilePath,getSecurityConfigPath:getSecurityConfigPath,getPagesConfigPath:getPagesConfigPath,getPrefabsDirPath:getPrefabsDirPath,getPrefabPagesDirPath:getPrefabPagesDirPath,getPrefabConfigPath:getPrefabConfigPath}=require("./wm-utils"),{join:join}=require("path"),getWmProjectProperties=async e=>{let t=await readFile(getWmProjectPropertiesFilePath(e),"utf8");const a=libxmljs.parseXml(t),r={};return a.find("//entry").forEach(e=>r[e.attr("key").value()]=e.text()),r},getSecurityConfig=async e=>stat(getAuthInfoFilePath(e)).then(()=>new Promise(async(t,a)=>{let r=null;JSON.parse(await readFile(getAuthInfoFilePath(e))).enforceSecurity&&(r=JSON.parse(await readFile(getSecurityConfigPath(e),"utf8"))),t(r)}),()=>Promise.resolve(null)),getPagesConfig=async e=>{let t=await readFile(getPagesConfigPath(e),"utf8");return t=JSON.parse(t)},getPrefabPartialsConfig=async(e,t)=>{let a=await readFile(`${getPrefabPagesDirPath(e,t)}/pages-config.json`,"utf8");return a=JSON.parse(a).filter(e=>"partial"===e.type.toLowerCase()||"template"===e.type.toLowerCase()).map(e=>({...e,prefabName:t}))},getPrefabConfigsUsedInApp=async(e,t)=>{const a=new Map,r=getPrefabsDirPath(t);return stat(r).then(()=>new Promise(async(i,s)=>{for(const e of await readDir(r))(await stat(join(r,e))).isDirectory()&&a.set(e,await readFile(getPrefabConfigPath(t,e)));isPrefabProject(e)&&a.set("__self__",await readFile(`${t}/src/main/webapp/config.json`)),i(a)}),()=>Promise.resolve(a))};module.exports={getWmProjectProperties:getWmProjectProperties,getSecurityConfig:getSecurityConfig,getPagesConfig:getPagesConfig,getPrefabConfigsUsedInApp:getPrefabConfigsUsedInApp,getPrefabPartialsConfig:getPrefabPartialsConfig};