Skip to content

Commit

Permalink
Merge pull request #22 from acro5piano/feature/dotenv-option
Browse files Browse the repository at this point in the history
feat: enable to specify dotenv file along with other config params
  • Loading branch information
acro5piano committed Mar 18, 2024
2 parents 93169bc + 5df8658 commit 45c6f15
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/cli.ts
Expand Up @@ -4,11 +4,17 @@ import path from 'path'
import { promises as fs } from 'fs'
import { Pool } from 'pg'

const dotenvPath = process.env.DOTENV_CONFIG_PATH || '.env'

/**
* Load Dotenv if the module exists.
*/
try {
require('dotenv').config()
require('dotenv').config({
debug: !!process.env.DOTENV_CONFIG_DEBUG,
path: dotenvPath,
encoding: process.env.DOTENV_CONFIG_ENCODING,
})
} catch {}

const { DATABASE_URL } = process.env
Expand All @@ -18,7 +24,7 @@ if (!DATABASE_URL) {
Please specify DATABASE_URL to run this CLi. Try the following:
- Run \`DATABASE_URL=postgres://user:password@host:port/database && npm run kysely-migration-cli\`
- Place .env file containing \`DATABASE_URL=postgres://user:password@host:port/database\`
- Place ${dotenvPath} file containing \`DATABASE_URL=postgres://user:password@host:port/database\`
`
console.log(hint)
process.exit(1)
Expand Down

0 comments on commit 45c6f15

Please sign in to comment.