From 91b4e07456e64c9e9a25b7991d798c8399ac1a13 Mon Sep 17 00:00:00 2001 From: oliviareichl Date: Mon, 30 Sep 2024 14:35:42 +0200 Subject: [PATCH] fix: generate empty crm messages file when no database is available --- scripts/generate-crm-locale.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/scripts/generate-crm-locale.ts b/scripts/generate-crm-locale.ts index 5739e8da..12c09e19 100644 --- a/scripts/generate-crm-locale.ts +++ b/scripts/generate-crm-locale.ts @@ -112,6 +112,15 @@ const customDictionary: Record< }, }; +async function writeCrmMessages(obj: object, locale: string) { + const content = JSON.stringify(obj, null, "\t"); + + const folderPath = join(process.cwd(), "messages", locale); + await mkdir(folderPath, { recursive: true }); + await writeFile(join(folderPath, `crm.json`), content, { + encoding: "utf-8", + }); +} /** * Generates CRM messages for the specified locale. * @param locale - The locale for which to generate CRM messages. Defaults to `defaultLocale` if not provided. @@ -132,6 +141,7 @@ async function generate(locale = defaultLocale) { const isDatabaseEnabled = result.output.NUXT_PUBLIC_DATABASE === "enabled"; if (!isDatabaseEnabled) { + await writeCrmMessages({}, locale); return false; } @@ -166,13 +176,7 @@ async function generate(locale = defaultLocale) { obj[key] = typeTranslations; } - const content = JSON.stringify(obj, null, "\t"); - - const folderPath = join(process.cwd(), "messages", locale); - await mkdir(folderPath, { recursive: true }); - await writeFile(join(folderPath, `crm.json`), content, { - encoding: "utf-8", - }); + await writeCrmMessages(obj, locale); return true; }