Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
wangpin34 committed Dec 4, 2019
1 parent 04e6d89 commit 87f20b6
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
[![NPM downloads](http://img.shields.io/npm/dm/stack-env.svg?style=flat-square)](https://npmjs.org/package/stack-env)
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/wangpin34/stack-env.svg)](http://isitmaintained.com/project/wangpin34/stack-env "Average time to resolve an issue")

## What problem does it resolve?
### The background
Recently I'm working on a react application which is bootstrapped by create-react-app(CRA). There are mutiple online environment(e.g. dev,qa,stg, and prod) so that I have to configure mutiple sets of enviroment variables to the app. Unfortunately, CRA only provides two kind of env conf for local development and online. So I comes to the idea to develop a tool for this requirement.
## What problem it tries to resolve
create-react-app provides the basic mechanism to differentiate development and production env, but it lacks the capability of dividing multiple 'production' env. Let's say there are qa, stg, prod, three stacks, we are not able to give different env variables per stack like Spring-Profile. Here I want to introduce **stack-env** which means to resolve this pain point.

### My idea
A cli tool which can read the environment **stack**(value is the name of online env) and load the conrespondding env file. e.g. stack=dev, then it loads variables from file **.senv.dev**.
## Get started
The major concept in stack-env is stack and corresponding env files. e.g.,
stacks: qa, stg, prod,
files: senv.qa, senv.stg, senv.prod

When stack-env runs, it read the stack from process.env to recognize what the exact stack it runs on. And then read the corresponding env file and load it as the env variables. In the end, the desired command runs in an env that all env variables come from the env file.
## Usage
```
Usage: senv [options] [command]
Expand All @@ -24,6 +27,7 @@ A cli tool which can read the environment **stack**(value is the name of online
-c, --cmd The command to run
-f, --file Choose an env file
-h, --help Output usage information
-k, --key Stack key
-v, --verbose Print full logs
-V, --version Output the version number
```
Expand All @@ -32,6 +36,18 @@ e.g. load env and run command **yarn build**.
```
senv -c 'yarn build'
```
## Alias
What if the injected stack key is not 'stack' but others. stack-env provides a simple configuration section which is located in package.json to give an alias of the key.

```
"senv": {
"key": "any-key"
}
```

Or through the cmd.
```
stack-env -k 'any-key' -c 'other commands'
```
## LICENSE
MIT

0 comments on commit 87f20b6

Please sign in to comment.