Skip to content

Commit

Permalink
V3.0.2
Browse files Browse the repository at this point in the history
Signed-off-by: iswilljr <iswilljr@gmail.com>
  • Loading branch information
iswilljr committed Jul 26, 2022
1 parent 4c51b1e commit e5e8991
Show file tree
Hide file tree
Showing 12 changed files with 292 additions and 249 deletions.
28 changes: 15 additions & 13 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"env": {
"commonjs": true,
"es2021": true,
"node": true
},
"extends": ["standard", "prettier"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest"
},
"plugins": ["@typescript-eslint"],
"rules": {},
"ignorePatterns": "src"
"env": {
"commonjs": true,
"es2021": true,
"node": true
},
"extends": ["standard", "prettier"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest"
},
"plugins": ["@typescript-eslint", "prettier"],
"rules": {
"prettier/prettier": "error"
},
"ignorePatterns": ["node_modules/", "lib/", "**/*.js"]
}
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
node_modules

dev

.env
.env.*

Expand Down
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules

.env
.env.*

lib
8 changes: 4 additions & 4 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"printWidth": 120,
"useTabs": true,
"tabWidth": 2,
"semi": true
"printWidth": 120,
"useTabs": false,
"tabWidth": 2,
"semi": true
}
135 changes: 53 additions & 82 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,105 +1,71 @@
# CONFIG ENV FILE

A command line to generate a .env.local based on a Config

---

## Go to

- [Install](#install)
- [Usage](#usage)
- [Help](#help)
- [Examples](#examples)

---
A command line to generate a .env file based on a Config

## Install

```bash
# npm
npm i config-env-file -D
npm install -g config-env-file

# yarn
yarn add config-env-file -D
yarn global add config-env-file -D
```

---

## Usage

```bash
# npm
npx cef --file /path/to/your/config/file

# yarn
yarn cef --file /path/to/your/config/file
```

---

## Help

```bash
# npm
npx cef --help

# yarn
yarn cef --help
cef /path/to/your/config/file [options]
```

---

## Examples

### Basic example

In this example we have the next config file:

```json
// File path: ./config.json
{
"apiKey": "example",
"authDomain": "example.firebaseapp.com",
"projectId": "example",
"storageBucket": "example.appspot.com",
"messagingSenderId": "example",
"appId": "1:example:web:example",
"appId": "1:example:web:example"
}
```

File path: ./config.json

Then, run the next command:

```bash
# npm
npx cef -f ./config.json

# yarn
yarn cef -f ./config.json
cef ./config.json
```

This will generate a .env.local file in root of our project, like this:

```env
APIKEY=example
AUTHDOMAIN=example.firebaseapp.com
PROJECTID=example
STORAGEBUCKET=example.appspot.com
MESSAGINGSENDERID=example
APPID=1:example:web:example
API_KEY=example
AUTH_DOMAIN=example.firebaseapp.com
PROJECT_ID=example
STORAGE_BUCKET=example.appspot.com
MESSAGING_SENDER_ID=example
APP_ID=1:example:web:example
```

Output:

```javascript
const config = {
apiKey: process.env.APIKEY,
authDomain: process.env.AUTHDOMAIN,
projectId: process.env.PROJECTID,
storageBucket: process.env.STORAGEBUCKET,
messagingSenderId: process.env.MESSAGINGSENDERID,
appId: process.env.APPID,
};
// Check your .env.local file
// Your config:
const config = {
apiKey: process.env.API_KEY,
authDomain: process.env.AUTH_DOMAIN,
projectId: process.env.PROJECT_ID,
storageBucket: process.env.STORAGE_BUCKET,
messagingSenderId: process.env.MESSAGING_SENDER_ID,
appId: process.env.APP_ID
}
```

### Full example
Expand All @@ -113,45 +79,50 @@ DOMAIN=http://localhost:3001
Then, run the next command:

```bash
# npm
npx cef -f ./config.json -d . -e prod -t react_app -p process -m .env.local

# yarn
yarn cef -f ./config.json -d . -e prod -t react_app -p process -m .env.local
cef ./config.json -d . -e development -t next_public -E import -m .env.local
```

Flags:
Options:

```javascript
-f ./config.json // file path
./config.json // file path
-d . // destination => current directory
-e prod // file extension => .env.prod
-t react_app // KEY => REACT_APP_KEY
-p process // output => proccess.env.${KEY}
-e development // file extension => .env.prod
-t next_public // KEY => NEXT_PUBLIC_KEY
-E import // output => import.meta.env.KEY
-m .env.local // merge with an existing env file
```

This will merge our .env.local file with the config and generate a .env.prod file in root of our project, like this:

```env
REACT_APP_DOMAIN=http://localhost:3001
REACT_APP_APIKEY=example
REACT_APP_AUTHDOMAIN=example.firebaseapp.com
REACT_APP_PROJECTID=example
REACT_APP_STORAGEBUCKET=example.appspot.com
REACT_APP_MESSAGINGSENDERID=example
REACT_APP_APPID=1:example:web:example
NEXT_PUBLIC_DOMAIN=http://localhost:3001
NEXT_PUBLIC_API_KEY=example
NEXT_PUBLIC_AUTH_DOMAIN=example.firebaseapp.com
NEXT_PUBLIC_PROJECT_ID=example
NEXT_PUBLIC_STORAGE_BUCKET=example.appspot.com
NEXT_PUBLIC_MESSAGING_SENDER_ID=example
NEXT_PUBLIC_APP_ID=1:example:web:example
```

Output:

```javascript
const config = {
apiKey: process.env.REACT_APP_APIKEY,
authDomain: process.env.REACT_APP_AUTHDOMAIN,
projectId: process.env.REACT_APP_PROJECTID,
storageBucket: process.env.REACT_APP_STORAGEBUCKET,
messagingSenderId: process.env.REACT_APP_MESSAGINGSENDERID,
appId: process.env.REACT_APP_APPID,
};
// Check your .env.development file
// Your config:
const config = {
domain: import.meta.env.NEXT_PUBLIC_DOMAIN,
apiKey: import.meta.env.NEXT_PUBLIC_API_KEY,
authDomain: import.meta.env.NEXT_PUBLIC_AUTH_DOMAIN,
projectId: import.meta.env.NEXT_PUBLIC_PROJECT_ID,
storageBucket: import.meta.env.NEXT_PUBLIC_STORAGE_BUCKET,
messagingSenderId: import.meta.env.NEXT_PUBLIC_MESSAGING_SENDER_ID,
appId: import.meta.env.NEXT_PUBLIC_APP_ID
}
```

## Help

```bash
cef --help
```
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"apiKey": "example",
"authDomain": "example.firebaseapp.com",
"projectId": "example",
"storageBucket": "example.appspot.com",
"messagingSenderId": "example",
"appId": "1:example:web:example"
}
115 changes: 59 additions & 56 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,58 +1,61 @@
{
"name": "config-env-file",
"version": "3.0.1",
"description": "A command line to generate a .env.local based on a Config",
"main": "lib/index.js",
"bin": {
"cef": "lib/bin.js"
},
"scripts": {
"build": "yarn typecheck && rimraf lib/**/*.js && tsc",
"typecheck": "tsc --noEmit",
"prepublish": "yarn build"
},
"keywords": [
"cli",
"commander",
"dotenv",
"env",
"config",
"env-file"
],
"author": "iswilljr",
"license": "ISC",
"devDependencies": {
"@types/node": "^17.0.29",
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.21.0",
"eslint": "^8.14.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-n": "^15.2.0",
"eslint-plugin-promise": "^6.0.0",
"prettier": "^2.6.2",
"rimraf": "^3.0.2",
"typescript": "^4.7.4"
},
"dependencies": {
"commander": "^9.2.0",
"dotenv": "^16.0.1"
},
"files": [
"lib",
"README.md"
],
"types": "./lib/index.d.ts",
"directories": {
"lib": "lib"
},
"repository": {
"type": "git",
"url": "git+https://github.com/iswilljr/config-env-file.git"
},
"bugs": {
"url": "https://github.com/iswilljr/config-env-file/issues"
},
"homepage": "https://github.com/iswilljr/config-env-file#readme"
"name": "config-env-file",
"version": "3.0.2",
"description": "A command line to generate a .env file based on a Config",
"main": "lib/index.js",
"bin": {
"cef": "lib/bin.js"
},
"scripts": {
"build": "yarn typecheck && rimraf lib && tsc",
"typecheck": "tsc --noEmit",
"prepare": "yarn build"
},
"keywords": [
"cli",
"commander",
"dotenv",
"env",
"config",
"env-file"
],
"author": "iswilljr",
"license": "ISC",
"devDependencies": {
"@types/node": "^17.0.29",
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.21.0",
"eslint": "^8.14.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-n": "^15.2.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.0.0",
"prettier": "^2.6.2",
"rimraf": "^3.0.2",
"typescript": "^4.7.4"
},
"dependencies": {
"camel-case": "^4.1.2",
"commander": "^9.2.0",
"constant-case": "^3.0.4",
"dotenv": "^16.0.1"
},
"files": [
"lib",
"README.md"
],
"types": "./lib/index.d.ts",
"directories": {
"lib": "lib"
},
"repository": {
"type": "git",
"url": "git+https://github.com/iswilljr/config-env-file.git"
},
"bugs": {
"url": "https://github.com/iswilljr/config-env-file/issues"
},
"homepage": "https://github.com/iswilljr/config-env-file#readme"
}
Loading

0 comments on commit e5e8991

Please sign in to comment.