From 467cd0fc94084e17e3663320f4adc52c983534da Mon Sep 17 00:00:00 2001 From: Franz Unger Date: Thu, 5 Sep 2024 10:44:32 +0200 Subject: [PATCH] Add sane defaults for preloginEnabled When preloginEnabled is undefined or null set it to true on environments != prod or local. --- .changeset/tidy-mangos-swim.md | 8 ++++++++ packages/cli/src/commands/site-configs.ts | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 .changeset/tidy-mangos-swim.md diff --git a/.changeset/tidy-mangos-swim.md b/.changeset/tidy-mangos-swim.md new file mode 100644 index 0000000000..979ddae9ba --- /dev/null +++ b/.changeset/tidy-mangos-swim.md @@ -0,0 +1,8 @@ +--- +"@comet/cli": patch +--- + +inject-site-configs: Add sane defaults for preloginEnabled + +When `preloginEnabled` is `undefined` or `null` set it to `true` +on environments != `prod` or `local`. diff --git a/packages/cli/src/commands/site-configs.ts b/packages/cli/src/commands/site-configs.ts index 4854f7b398..0a58d2b78c 100644 --- a/packages/cli/src/commands/site-configs.ts +++ b/packages/cli/src/commands/site-configs.ts @@ -24,13 +24,14 @@ export const injectSiteConfigsCommand = new Command("inject-site-configs") return domain.includes("localhost") ? `http://${domain}` : `https://${domain}`; }; - const replacerFunctions: Record unknown> = { - private: (siteConfigs: BaseSiteConfig[]): ExtractPrivateSiteConfig[] => + const replacerFunctions: Record unknown> = { + private: (siteConfigs: BaseSiteConfig[], env: string): ExtractPrivateSiteConfig[] => siteConfigs.map((siteConfig) => (({ public: publicVars, ...rest }) => ({ ...publicVars, ...rest, url: getUrlFromDomain(siteConfig.domains.preliminary ?? siteConfig.domains.main), + preloginEnabled: siteConfig.preloginEnabled ?? !["prod", "local"].includes(env), }))(siteConfig), ), public: (siteConfigs: BaseSiteConfig[]): ExtractPublicSiteConfig[] => @@ -50,7 +51,7 @@ export const injectSiteConfigsCommand = new Command("inject-site-configs") console.error(`inject-site-configs: ERROR: type must be ${Object.keys(replacerFunctions).join("|")} (got ${type})`); return substr; } - const ret = JSON.stringify(replacerFunctions[type](siteConfigs)).replace(/\\/g, "\\\\"); + const ret = JSON.stringify(replacerFunctions[type](siteConfigs, env)).replace(/\\/g, "\\\\"); if (options.dotenv) return ret.replace(/\$/g, "\\$"); return ret; });