Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable to specify dotenv file along with other config params #22

Merged
merged 1 commit into from Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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