@@ -7,29 +7,34 @@ Environment Command:
77
88 pgpm env [OPTIONS] [COMMAND...]
99
10- Manage PostgreSQL environment variables with profile support.
10+ Manage environment variables for local development with profile support.
1111
12- Profiles:
12+ Database Profiles:
1313 (default) Use local Postgres development profile
1414 --supabase Use Supabase local development profile
1515
16+ Additional Services:
17+ --minio Include MinIO/S3 environment variables
18+
1619Modes:
1720 No command Print export statements for shell evaluation
1821 With command Execute command with environment variables applied
1922
2023Options:
2124 --help, -h Show this help message
2225 --supabase Use Supabase profile instead of default Postgres
26+ --minio Include CDN_ENDPOINT, AWS_ACCESS_KEY, AWS_SECRET_KEY, AWS_REGION
2327
2428Examples:
2529 pgpm env Print default Postgres env exports
2630 pgpm env --supabase Print Supabase env exports
31+ pgpm env --minio Print Postgres + MinIO env exports
32+ pgpm env --supabase --minio Print Supabase + MinIO env exports
2733 eval "$(pgpm env)" Load default Postgres env into shell
28- eval "$(pgpm env --supabase)" Load Supabase env into shell
34+ eval "$(pgpm env --minio)" Load Postgres + MinIO env into shell
35+ eval "$(pgpm env --supabase --minio)" Load Supabase + MinIO env into shell
2936 pgpm env pgpm deploy --database db1 Run command with default Postgres env
30- pgpm env createdb mydb Run command with default Postgres env
31- pgpm env --supabase pgpm deploy --database db1 Run command with Supabase env
32- pgpm env --supabase createdb mydb Run command with Supabase env
37+ pgpm env --minio pgpm deploy --database db1 Run command with Postgres + MinIO env
3338` ;
3439
3540const SUPABASE_PROFILE : PgConfig = {
@@ -44,26 +49,49 @@ const DEFAULT_PROFILE: PgConfig = {
4449 ...defaultPgConfig
4550} ;
4651
47- function configToEnvVars ( config : PgConfig ) : Record < string , string > {
48- return {
52+ interface MinioConfig {
53+ endpoint : string ;
54+ accessKey : string ;
55+ secretKey : string ;
56+ region : string ;
57+ }
58+
59+ const MINIO_PROFILE : MinioConfig = {
60+ endpoint : 'http://localhost:9000' ,
61+ accessKey : 'minioadmin' ,
62+ secretKey : 'minioadmin' ,
63+ region : 'us-east-1' ,
64+ } ;
65+
66+ function configToEnvVars ( config : PgConfig , minio ?: MinioConfig ) : Record < string , string > {
67+ const vars : Record < string , string > = {
4968 PGHOST : config . host ,
5069 PGPORT : String ( config . port ) ,
5170 PGUSER : config . user ,
5271 PGPASSWORD : config . password ,
5372 PGDATABASE : config . database
5473 } ;
74+
75+ if ( minio ) {
76+ vars . CDN_ENDPOINT = minio . endpoint ;
77+ vars . AWS_ACCESS_KEY = minio . accessKey ;
78+ vars . AWS_SECRET_KEY = minio . secretKey ;
79+ vars . AWS_REGION = minio . region ;
80+ }
81+
82+ return vars ;
5583}
5684
57- function printExports ( config : PgConfig ) : void {
58- const envVars = configToEnvVars ( config ) ;
85+ function printExports ( config : PgConfig , minio ?: MinioConfig ) : void {
86+ const envVars = configToEnvVars ( config , minio ) ;
5987 for ( const [ key , value ] of Object . entries ( envVars ) ) {
6088 console . log ( `export ${ key } =${ value } ` ) ;
6189 }
6290}
6391
64- function executeCommand ( config : PgConfig , command : string , args : string [ ] ) : Promise < number > {
92+ function executeCommand ( config : PgConfig , command : string , args : string [ ] , minio ?: MinioConfig ) : Promise < number > {
6593 return new Promise ( ( resolve , reject ) => {
66- const envVars = configToEnvVars ( config ) ;
94+ const envVars = configToEnvVars ( config , minio ) ;
6795 const env = {
6896 ...process . env ,
6997 ...envVars
@@ -95,7 +123,11 @@ export default async (
95123 }
96124
97125 const useSupabase = argv . supabase === true || typeof argv . supabase === 'string' ;
126+ const useMinio = argv . minio === true || typeof argv . minio === 'string' ;
98127 const profile = useSupabase ? SUPABASE_PROFILE : DEFAULT_PROFILE ;
128+ const minioProfile = useMinio ? MINIO_PROFILE : undefined ;
129+
130+ const knownFlags = [ '--supabase' , '--minio' ] ;
99131
100132 const rawArgs = process . argv . slice ( 2 ) ;
101133
@@ -106,14 +138,7 @@ export default async (
106138
107139 const argsAfterEnv = rawArgs . slice ( envIndex + 1 ) ;
108140
109- const supabaseIndex = argsAfterEnv . findIndex ( arg => arg === '--supabase' ) ;
110-
111- let commandArgs : string [ ] ;
112- if ( supabaseIndex !== - 1 ) {
113- commandArgs = argsAfterEnv . slice ( supabaseIndex + 1 ) ;
114- } else {
115- commandArgs = argsAfterEnv ;
116- }
141+ let commandArgs = argsAfterEnv . filter ( arg => ! knownFlags . includes ( arg ) ) ;
117142
118143 commandArgs = commandArgs . filter ( arg => arg !== '--cwd' && ! arg . startsWith ( '--cwd=' ) ) ;
119144
@@ -123,14 +148,14 @@ export default async (
123148 }
124149
125150 if ( commandArgs . length === 0 ) {
126- printExports ( profile ) ;
151+ printExports ( profile , minioProfile ) ;
127152 return ;
128153 }
129154
130155 const [ command , ...args ] = commandArgs ;
131156
132157 try {
133- const exitCode = await executeCommand ( profile , command , args ) ;
158+ const exitCode = await executeCommand ( profile , command , args , minioProfile ) ;
134159 process . exit ( exitCode ) ;
135160 } catch ( error ) {
136161 if ( error instanceof Error ) {
0 commit comments