@@ -5,6 +5,7 @@ import { fileURLToPath } from "node:url";
55import dotenv from "dotenv" ;
66import { Vercel } from "@vercel/sdk" ;
77
8+ // eslint-disable-next-line @typescript-eslint/naming-convention
89const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
910const projectRoot = join ( __dirname , ".." ) ;
1011const baseParams : Record < string , string > = { } ;
@@ -106,11 +107,27 @@ const makeProductionEnv = async (vercel: Vercel, vercelToken: string) => {
106107} ;
107108
108109const main = async ( variant : Variant ) => {
109- // Do not execute in deployment or github action.
110- if (
110+ if ( process . env . ROAM_BUILD_SCRIPT ) {
111+ // special case: production build
112+ try {
113+ const response = execSync ( 'curl https://discoursegraphs.com/api/supabase/env' ) ;
114+ const asJson = JSON . parse ( response . toString ( ) ) as Record < string , string > ;
115+ writeFileSync (
116+ join ( projectRoot , ".env" ) ,
117+ Object . entries ( asJson ) . map ( ( [ k , v ] ) => `${ k } =${ v } ` ) . join ( '\n' )
118+ ) ;
119+ return ;
120+ } catch ( e ) {
121+ if ( process . env . SUPABASE_URL && process . env . SUPABASE_ANON_KEY )
122+ return ;
123+ throw new Error ( "Could not get environment from site" ) ;
124+ }
125+ }
126+ else if (
111127 process . env . HOME === "/vercel" ||
112128 process . env . GITHUB_ACTIONS !== undefined
113129 )
130+ // Do not execute in deployment or github action.
114131 return ;
115132
116133 if ( variant === Variant . none ) return ;
0 commit comments