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

Reading configs from .env with dotenv #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jyjokokk
Copy link

@jyjokokk jyjokokk commented Feb 5, 2023

Simple addition to reading configurations from .env files in your project root. Currently just switches the fileSuffix, but further additions are easily implemented.

Copy link
Owner

@egm0121 egm0121 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jyjokokk thanks for your contribution, I think it's a useful addition to parse per project settings based on the .env files!
I do have some changes for you to make before I can accept the PR, thanks again for your contribution!

export const FILE_SUFFIX = process.env.JEST_TEST_GEN_FILESUFFIX;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not a constant, it is a configuration, no need to read the config inside this file, it can be done in main.ts

@@ -32,7 +33,7 @@ export function run(args: minimist.ParsedArgs, opts?: TRunOptions) {
finalOutputDir = path.resolve(finalOutputDir, args.outputDir);
}
}
let fileSuffix = '.generated.test';
let fileSuffix = FILE_SUFFIX;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please keep the default and if specified, override with the process.env.value and finally any command line arguments have priority.
eg:

let fileSuffix = '.generated.test';
if (process.env.JEST_TEST_GEN_FILESUFFIX) {
    fileSuffix = process.env.JEST_TEST_GEN_FILESUFFIX;
 }
if (args.fileSuffix) {
    fileSuffix = args.fileSuffix;
 }

@@ -5,6 +5,7 @@ import * as ts from 'typescript';
import { parseSourceFile } from './parse-source-file';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here the should be an import of dotenv at the top to make it work

import * as dotenv from 'dotenv'
dotenv.config()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants