@rmdes/indiekit-endpoint-site-config 1.0.0-alpha.1 → 1.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -8,6 +8,7 @@ import { layoutRouter } from "./lib/controllers/layout.js";
8
8
  import { featuresRouter } from "./lib/controllers/features.js";
9
9
  import { apiRouter } from "./lib/controllers/api.js";
10
10
  import { getSiteConfig } from "./lib/storage/get-site-config.js";
11
+ import { maybeSeedFromEnv } from "./lib/storage/seed-from-env.js";
11
12
  import { writeThemeCss } from "./lib/render/write-theme-css.js";
12
13
  import { writeSiteJson } from "./lib/render/write-site-json.js";
13
14
 
@@ -65,6 +66,7 @@ export default class SiteConfigEndpoint {
65
66
 
66
67
  // Ensure files exist on first boot — synchronously regenerate.
67
68
  try {
69
+ await maybeSeedFromEnv(Indiekit);
68
70
  const config = await getSiteConfig(Indiekit);
69
71
  await writeThemeCss(config);
70
72
  await writeSiteJson(config);
@@ -0,0 +1,41 @@
1
+ import { saveSiteConfig } from "./save-site-config.js";
2
+
3
+ /**
4
+ * Map env vars to identity fields. Only fields present in env are set.
5
+ * Returns null if NO relevant env vars are set (caller should not seed).
6
+ */
7
+ function buildIdentityFromEnv() {
8
+ const identity = {};
9
+ if (process.env.SITE_NAME) identity.name = process.env.SITE_NAME;
10
+ if (process.env.SITE_DESCRIPTION) identity.description = process.env.SITE_DESCRIPTION;
11
+ if (process.env.AUTHOR_NAME) identity.defaultAuthor = process.env.AUTHOR_NAME;
12
+ if (process.env.SITE_TIMEZONE) identity.timezone = process.env.SITE_TIMEZONE;
13
+ if (process.env.SITE_LOCALE) identity.locale = process.env.SITE_LOCALE;
14
+ return Object.keys(identity).length > 0 ? identity : null;
15
+ }
16
+
17
+ /**
18
+ * If MongoDB has no siteConfig AND env vars are present, seed siteConfig
19
+ * from env vars. Idempotent — does nothing if siteConfig already exists.
20
+ *
21
+ * Returns true if a seed was performed, false otherwise.
22
+ *
23
+ * @param {object} Indiekit - Indiekit application instance
24
+ * @returns {Promise<boolean>}
25
+ */
26
+ export async function maybeSeedFromEnv(Indiekit) {
27
+ const db = Indiekit.database;
28
+ if (!db) return false;
29
+
30
+ const existing = await db.collection("siteConfig").findOne({ _id: "primary" });
31
+ if (existing) return false;
32
+
33
+ const identity = buildIdentityFromEnv();
34
+ if (!identity) return false;
35
+
36
+ await saveSiteConfig(Indiekit, { identity }, "auto-seed-from-env");
37
+ return true;
38
+ }
39
+
40
+ // Export the helper for testing
41
+ export { buildIdentityFromEnv };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rmdes/indiekit-endpoint-site-config",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.2",
4
4
  "type": "module",
5
5
  "description": "Site identity, branding, layout, and feature flag configuration for Indiekit",
6
6
  "main": "index.js",