Skip to content

Commit

Permalink
Merge pull request #7 from simplyStyle/main
Browse files Browse the repository at this point in the history
feat: update redeme
  • Loading branch information
tianyingchun authored May 27, 2024
2 parents 0f98548 + 17781d0 commit 8325124
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@

Runtime Environment Configuration

Populates your environment from .env files at run-time rather than build-time.

Populates your environment from `.env` files at **run-time** rather than **build-time**.

- Supports multiple `.env` files.

## README

- [Examples](#examples)
- [Getting started](#getting-started)
- [File priority](#env-file-order-of-priority)
- [Common use cases](#common-use-cases)
- [Environment specific config](#environment-specific-config)
- [Specifing an env file](#Specifing-an-env-file)
- [Using with Docker entrypoint](#using-with-docker-entrypoint)
- [Arguments and parameters](#arguments-and-parameters)
- [@hyperse-io/hyper-env](#hyperse-iohyper-env)
- [README](#readme)
- [Examples](#examples)
- [Getting started](#getting-started)
- [.env file order of priority](#env-file-order-of-priority)
- [Common use cases](#common-use-cases)
- [Environment specific config](#environment-specific-config)
- [Specifing an env file](#specifing-an-env-file)
- [Specifing an prefix for white-listed environment variables](#specifing-an-prefix-for-white-listed-environment-variables)
- [Arguments and parameters](#arguments-and-parameters)

### Examples

Expand Down Expand Up @@ -147,12 +147,10 @@ You may pass a command, such as a nodejs entry file to the `hyper-env` cli tool.

- `--env`, `-e` **(default: APP_ENV)**

Specify the name of an existing environment variable, whose value is the name of an environment you want, to make hyper-env parse an environment specific env-file. For example, you may set `APP_ENV=staging` first and then apply `--env APP_ENV` flag. react-env would load `.env.staging, .env.local, .env` in that order with the latter taking priority.
Specify the name of an existing environment variable, whose value is the name of an environment you want, to make hyper-env parse an environment specific env-file. For example, you may set `APP_ENV=staging` first and then apply `--env APP_ENV` flag. hyper-env would load `.env.staging, .env.local, .env` in that order with the latter taking priority.

- `--path`, `-p` **(default: '')**

Enable debugging for react-env. This will log loaded browser environment variables into your console when running `react-env --debug`

As a significant breaking change we have dropped the ability to specify specific files via the `--env` argument. This argument now specifies environment file to be parsed depending on the running environment. For example `--env APP_ENV` or `-e APP_ENV` where `APP_ENV=staging` reads in `.env.staging`. It is very common for platforms to have `staging, qa, integration` environments that are still built in "production" mode with `NODE_ENV=production`. This allows for that usecase and many others.

Depandand command is now in the format `hyper-env <args> -- <command>`
30 changes: 16 additions & 14 deletions tests/dotenv.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('test suites of hyper env', () => {
expect(stdout).not.toMatch(/foo: bar/);
});

it('parses env without next .env', async () => {
it('parses env with next .env', async () => {
writeEnvFile('.env', 'NEXT_PUBLIC_FOO=dev');

const { stderr, stdout } = await runTsCliMock(
Expand All @@ -72,7 +72,7 @@ describe('test suites of hyper env', () => {

it('parse env files via --env arg', async () => {
writeEnvFile('.env.staging', 'NEXT_PUBLIC_FOO=env_staging');
// APP_ENV=staging hyper-env --env APP_ENV -- next build
// hyper-env APP_ENV=staging hyper-env --env APP_ENV -- next build
vi.stubEnv('APP_ENV', 'staging');
const { stderr, stdout } = await runTsCliMock(
cliPath,
Expand All @@ -87,13 +87,13 @@ describe('test suites of hyper env', () => {
expect(readNextPage()).toMatch(/"hello:","env_staging"/);
});

it('parse env files via --e arg', async () => {
it('parse env files via -e arg', async () => {
writeEnvFile('.env.staging2', 'NEXT_PUBLIC_FOO=e_staging2');
// APP_ENV=staging2 hyper-env --env APP_ENV -- next build
// APP_ENV=staging2 hyper-env -e APP_ENV -- next build
vi.stubEnv('APP_ENV', 'staging2');
const { stderr, stdout } = await runTsCliMock(
cliPath,
'--env',
'-e',
'APP_ENV',
'--',
'next',
Expand All @@ -106,7 +106,7 @@ describe('test suites of hyper env', () => {

it('parses env files via --path arg', async () => {
writeEnvFile('.env.staging', 'NEXT_PUBLIC_FOO=path_staging');

// hyper-env --path .env.staging -- next build
const { stderr, stdout } = await runTsCliMock(
cliPath,
'--path',
Expand All @@ -120,12 +120,12 @@ describe('test suites of hyper env', () => {
expect(readNextPage()).toMatch(/"hello:","path_staging"/);
});

it('parses env files via --p arg', async () => {
it('parses env files via -p arg', async () => {
writeEnvFile('.env.staging2', 'NEXT_PUBLIC_FOO=p_staging2');

// hyper-env -p .env.staging2 -- next build
const { stderr, stdout } = await runTsCliMock(
cliPath,
'--p',
'-p',
'.env.staging2',
'--',
'next',
Expand All @@ -143,12 +143,12 @@ describe('test suites of hyper env', () => {
writeEnvFile('.env', 'NEXT_PUBLIC_FOO=dev');

vi.stubEnv('APP_ENV', 'production');

// APP_ENV=production hyper-env -p .env.staging -e APP_ENV -- next build
const testRes1 = await runTsCliMock(
cliPath,
'--p',
'-p',
'.env.staging',
'--e',
'-e',
'APP_ENV',
'--',
'next',
Expand All @@ -159,11 +159,12 @@ describe('test suites of hyper env', () => {
expect(testRes1.stdout).toMatch(/node_env: test/);
expect(readNextPage()).toMatch(/"hello:","staging"/);

// APP_ENV=production hyper-env -e APP_ENV -p .env.staging -- next build
const testRes2 = await runTsCliMock(
cliPath,
'--e',
'-e',
'APP_ENV',
'--p',
'-p',
'.env.staging',
'--',
'next',
Expand All @@ -182,6 +183,7 @@ describe('test suites of hyper env', () => {
writeEnvFile('.env.test', 'NEXT_PUBLIC_FOO=test');
writeEnvFile('.env', 'NEXT_PUBLIC_FOO=dev');

// hyper-env -- next build
const { stderr, stdout } = await runTsCliMock(
cliPath,
'--',
Expand Down

0 comments on commit 8325124

Please sign in to comment.