Bundle service worker conditionally

This commit is contained in:
tusooa 2025-02-28 13:29:27 -05:00
commit eb6d9cdd4b
No known key found for this signature in database
GPG key ID: 42AEC43D48433C51
4 changed files with 108 additions and 44 deletions

View file

@ -3,14 +3,20 @@ import { readFile } from 'node:fs/promises'
import { dirname, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
const i18nDir = resolve(
dirname(dirname(fileURLToPath(import.meta.url))),
'src/i18n'
)
export const i18nFiles = languages.reduce((acc, lang) => {
const name = langCodeToJsonName(lang)
const file = resolve(i18nDir, name + '.json')
acc[lang] = file
return acc
}, {})
export const generateServiceWorkerMessages = async () => {
const i18nDir = resolve(
dirname(dirname(fileURLToPath(import.meta.url))),
'src/i18n'
)
const msgArray = await Promise.all(languages.map(async lang => {
const name = langCodeToJsonName(lang)
const file = resolve(i18nDir, name + '.json')
const msgArray = await Promise.all(Object.entries(i18nFiles).map(async ([lang, file]) => {
const fileContent = await readFile(file, 'utf-8')
const msg = {
notifications: JSON.parse(fileContent).notifications || {}