UNPKG

@vite-pwa/create-pwa

Version:
12 lines (10 loc) 2.83 kB
import{rmSync as l,renameSync as v}from"node:fs";import{p as u,a as w,b as $,g as P,M as y}from"../shared/create-pwa.DNW-qV5p.mjs";import{e as a}from"../index.mjs";import"fs";import"node:path";import"node:process";import"node:url";import"child_process";import"path";import"readline";import"events";function k(s){const{rootPath:r,name:o,themeColor:m,framework:h,customServiceWorker:f,prompt:n,offline:c,reloadSW:g,pwaAssets:d}=s,t=h==="vanilla-ts";a(`${r}/src/pwa.${t?"t":"j"}s`,i=>{let e=i.replace("OFFLINE_COMMENT",`${c?"comment out the next 2 lines to show offline ready prompt":"uncomment the next 2 lines to hide offline ready prompt"}`);return c&&(e=e.replace("// pwaToastMessage.innerHTML = 'App ready to work offline'","pwaToastMessage.innerHTML = 'App ready to work offline'"),e=e.replace("// showPwaToast(true)","showPwaToast(true)")),g?e=e.replace("PERIODIC_SYNC_COMMENT","check for updates every hour").replace("const period = 0","const period = 60 * 60 * 1000"):e=e.replace("PERIODIC_SYNC_COMMENT",`periodic sync is disabled, change the value to enable it, the period is in milliseconds // You can remove onRegisteredSW callback and registerPeriodicSync function`),e.replace("PROMPT_COMMENT",n?"Show the prompt to update the service worker when a new version is available":"This method will not be called using registerType with 'autoUpdate' behavior: you can change the behavior in the Vite config file using 'registerType' property.")}),a(`${r}/index.html`,i=>{const e=i.replace("Vite VanillaJS PWA",`${o}`).replace("Vite TypeScript PWA",`${o}`);return d?e.replace('<link rel="icon" type="image/svg+xml" href="/favicon.svg" />',""):e.replace('<link rel="icon" type="image/svg+xml" href="/favicon.svg" />',` <meta name="theme-color" content="${m}"> <link rel="icon" href="/favicon.ico" sizes="48x48"> <link rel="icon" href="/favicon.svg" sizes="any" type="image/svg+xml"> <link rel="apple-touch-icon" href="/apple-touch-icon-180x180.png"> `)}),a(`${r}/src/main.${t?"t":"j"}s`,i=>i.replace("Vite VanillaJS PWA",`${o}`).replace("Vite TypeScript PWA",`${o}`).replace("Vite PWA logo",`${o} logo`)),f?(l(`${r}/src/service-worker/${n?"claims":"prompt"}-sw.${t?"t":"j"}s`),v(`${r}/src/service-worker/${n?"prompt":"claims"}-sw.${t?"t":"j"}s`,`${r}/src/service-worker/sw.${t?"t":"j"}s`)):l(`${s.rootPath}/src/service-worker`,{recursive:!0});const p=u(` import { defineConfig } from 'vite' // https://vitejs.dev/config/ export default defineConfig({}) `);w(p,{from:"vite-plugin-pwa",imported:"VitePWA",constructor:"VitePWA",options:$(t,s,"src/service-worker",{workbox:{globPatterns:["**/*.{js,css,html,svg,png,ico}"],cleanupOutdatedCaches:!0,clientsClaim:!0},injectManifest:{globPatterns:["**/*.{js,css,html,svg,png,ico}"]}})}),a(`${r}/vite.config.${t?"t":"j"}s`,()=>P(p,y).code)}export{k as customize};