const util=require("util"),fs=require("fs"),ncp=util.promisify(require("ncp").ncp),{writeFile:writeFile,readFileSync:readFileSync,getCodegenPath:getCodegenPath}=require("./wm-utils"),PWA_ICONS=["icon-512x512.png","icon-384x384.png","icon-192x192.png","icon-152x152.png","icon-144x144.png","icon-128x128.png","icon-96x96.png","icon-72x72.png"],generatePwaFiles=async(s,n,e)=>{await copyAssets(s,n),await updateManifestJson(n,e)},copyAssets=async(s,n)=>{const e=getCodegenPath();await ncp(e+"/pwa-assets/ngsw-config.json",`${n}/ngsw-config.json`),await ncp(e+"/pwa-assets/wmsw-worker.js",`${n}/src/wmsw-worker.js`),await ncp(e+"/pwa-assets/manifest.json",`${n}/src/manifest.json`),await copyIcons(s,n)},copyIcons=async(s,n)=>{const e=`${n}/src/assets/icons`;let a;if(fs.existsSync(e)||fs.mkdirSync(e,{recursive:!0}),fs.existsSync(`${s}/pwa-icons`))for(const[n,t]of PWA_ICONS.entries()){const c=`${s}/pwa-icons/${t}`;if(fs.existsSync(c)){if(!a)for(i=0;i<n;i++)await ncp(c,`${e}/${PWA_ICONS[i]}`);a=c,await ncp(c,`${e}/${t}`)}else a&&await ncp(a,`${e}/${t}`)}a||await ncp(`${getCodegenPath()}/pwa-assets/icons`,e)},updateManifestJson=async(s,n)=>{const e=`${s}/src/manifest.json`;let i=readFileSync(e,!0);i.name=n.displayName,i.short_name=n.displayName,await writeFile(e,JSON.stringify(i,null,4))};module.exports={generatePwaFiles:generatePwaFiles,copyIcons:copyIcons,PWA_ICONS:PWA_ICONS};