From 845f759bbcf86f8742b40f290ca625484e9b44c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Arnulfo=20R=2E=20H=2E?= Date: Sat, 22 Aug 2026 23:36:45 -0500 Subject: [PATCH] fix(build): add the missing env generation script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Netlify's build command, set in the UI, is `node scripts/generate-env.cjs`, but that file was never committed: 90fe322 moved the Supabase credentials out of the repo into an untracked 2026/js/env.js without adding the script that generates it. Every deploy has failed with MODULE_NOT_FOUND since, so production is frozen at the #98 merge and still serves the outdated code of conduct with the wrong reporting address. The script writes 2026/js/env.js from PYCON_SUPABASE_URL and SUPABASE_PUBLISHABLE_KEY, the variables Netlify already exposes. Missing credentials warn loudly but exit 0: the registration forms break, while the rest of the site — including the code of conduct and its reporting channel — still gets published. The command also moves into netlify.toml, which takes precedence over the UI setting, so it stays versioned next to the script it invokes. Co-Authored-By: Claude Opus 5 --- netlify.toml | 4 +++ scripts/generate-env.cjs | 64 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 scripts/generate-env.cjs diff --git a/netlify.toml b/netlify.toml index 6cfa13b..b9f2249 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,5 +1,9 @@ [build] publish = "." # raíz del repo +# Genera 2026/js/env.js con las credenciales del proyecto (ver el script). +# Declarado aquí y no solo en la UI de Netlify: netlify.toml tiene precedencia +# y así el comando queda versionado junto al script que invoca. +command = "node scripts/generate-env.cjs" [[redirects]] from = "/" diff --git a/scripts/generate-env.cjs b/scripts/generate-env.cjs new file mode 100644 index 0000000..f36c996 --- /dev/null +++ b/scripts/generate-env.cjs @@ -0,0 +1,64 @@ +#!/usr/bin/env node +/** + * PyCon Panamá 2026 — Generación de credenciales para el build + * + * `2026/js/env.js` está en .gitignore: las credenciales no viven en el repo. + * En Netlify, este script lo genera a partir de las variables de entorno del + * proyecto. En local, se copia `2026/js/env.example.js` a mano. + * + * Uso: node scripts/generate-env.cjs (es el build command de netlify.toml) + * + * La clave publicable de Supabase es pública por diseño —viaja al navegador de + * cada visitante— y está protegida por las políticas RLS de la base, no por el + * secreto. Lo que nunca debe entrar aquí es la service_role key. + */ + +const fs = require('fs'); +const path = require('path'); + +// Netlify expone PYCON_SUPABASE_URL y SUPABASE_PUBLISHABLE_KEY; los otros +// nombres son alias tolerados para no romper entornos ya configurados. +const url = + process.env.PYCON_SUPABASE_URL || + process.env.SUPABASE_URL || + ''; + +const anonKey = + process.env.SUPABASE_PUBLISHABLE_KEY || + process.env.PYCON_SUPABASE_ANON_KEY || + process.env.SUPABASE_ANON_KEY || + ''; + +const outputPath = path.join(__dirname, '..', '2026', 'js', 'env.js'); + +const contents = `/** + * PyCon Panamá 2026 — Credenciales del cliente + * Archivo generado por scripts/generate-env.cjs durante el build. No editar a + * mano ni commitear: los cambios se pierden en el siguiente despliegue. + */ +window.SUPABASE_CONFIG = { + url: ${JSON.stringify(url)}, + anonKey: ${JSON.stringify(anonKey)} +}; +`; + +fs.writeFileSync(outputPath, contents, 'utf8'); + +if (!url || !anonKey) { + // Sin credenciales fallan los formularios de registro, pero el resto del + // sitio —incluido el Código de Conducta y su canal de reporte— tiene que + // publicarse igual. Se avisa fuerte y el build continúa. + const faltantes = [ + !url && 'PYCON_SUPABASE_URL', + !anonKey && 'SUPABASE_PUBLISHABLE_KEY', + ].filter(Boolean); + + console.warn(''); + console.warn('⚠️ ATENCIÓN: faltan variables de entorno: ' + faltantes.join(', ')); + console.warn('⚠️ El sitio se publica, pero los formularios de registro y de'); + console.warn('⚠️ speakers NO van a guardar nada. Configúralas en Netlify:'); + console.warn('⚠️ Site configuration → Environment variables.'); + console.warn(''); +} else { + console.log('✓ 2026/js/env.js generado para ' + url); +}