Skip to content

Commit c6f4c81

Browse files
authored
Merge pull request #12 from code-like-a-carpenter/dotenv
dotenv
2 parents 332a35d + f789925 commit c6f4c81

File tree

12 files changed

+175
-5
lines changed

12 files changed

+175
-5
lines changed

package-lock.json

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@code-like-a-carpenter/assert/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ npm i @code-like-a-carpenter/assert
2727

2828
## Contributing
2929

30-
Please see contributing guidelines at
30+
Please see contributing guidelines at the
3131
[project homepage](https://www.github.com/code-like-a-carpenter/workbench/tree/main/packages/@code-like-a-carpenter/assert).
3232

3333
## License

packages/@code-like-a-carpenter/aws-env-loader/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ npm i @code-like-a-carpenter/aws-env-loader
2727

2828
## Contributing
2929

30-
Please see contributing guidelines at
30+
Please see contributing guidelines at the
3131
[project homepage](https://www.github.com/code-like-a-carpenter/workbench/tree/main/packages/@code-like-a-carpenter/aws-env-loader).
3232

3333
## License
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# @code-like-a-carpenter/dotenv
2+
3+
[![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
4+
5+
> Wrapper around dotenv the loads the right .env file(s) based on the NODE_ENV
6+
7+
## Table of Contents
8+
9+
- [Install](#install)
10+
- [Usage](#usage)
11+
- [Maintainer](#maintainer)
12+
- [Contributing](#contributing)
13+
- [License](#license)
14+
15+
## Install
16+
17+
```bash
18+
npm i @code-like-a-carpenter/dotenv
19+
```
20+
21+
## Usage
22+
23+
This package uses the [dotenv](https://www.npmjs.com/package/dotenv) package
24+
under the hood, but, depending on `NODE_ENV`, will load more files than just the
25+
default `.env`.
26+
27+
Each of the following files will be loaded if they exist, in the following
28+
order. Files loaded _earlier_ take precedence.
29+
30+
- `.env.<env>.local`
31+
- `.env.local`
32+
- `.env.<env>`
33+
- `.env`
34+
35+
There are only three valid values for `<env>`, based on the value of `NODE_ENV`:
36+
37+
| `NODE_ENV` | `<env>` |
38+
| ------------- | ------------- |
39+
| `production` | `production` |
40+
| `test` | `test` |
41+
| anything else | `development` |
42+
43+
Please add the following to your gitignore. `local` env files are intended for
44+
customizing the environment on your local machine and _should not_ be checked
45+
into git.
46+
47+
```gitignore
48+
.env.local
49+
.env.*.local
50+
.env.production
51+
```
52+
53+
**Even though you may check env files into git, you still shouldn't check in
54+
secrets.**
55+
56+
## Maintainer
57+
58+
[Ian Remmel](https://www.ianwremmel.com)
59+
60+
## Contributing
61+
62+
Please see contributing guidelines at the
63+
[project homepage](https://www.github.com/code-like-a-carpenter/workbench/tree/main/packages/@code-like-a-carpenter/dotenv).
64+
65+
## License
66+
67+
MIT © [Ian Remmel](https://www.ianwremmel.com) 2023 until at least now
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "@code-like-a-carpenter/dotenv",
3+
"description": "Wrapper around dotenv the loads the right .env file(s) based on the NODE_ENV",
4+
"author": "Ian Remmel <[email protected]> (https://www.ianwremmel.com)",
5+
"bugs": "https://www.github.com/code-like-a-carpenter/workbench/issues",
6+
"engines": {
7+
"node": "18.x",
8+
"npm": "9.x"
9+
},
10+
"exports": {
11+
".": {
12+
"import": "./dist/esm/index.js",
13+
"require": "./dist/cjs/index.js"
14+
},
15+
"./package.json": "./package.json"
16+
},
17+
"homepage": "https://www.github.com/code-like-a-carpenter/workbench/tree/main/packages/@code-like-a-carpenter/dotenv",
18+
"license": "MIT",
19+
"main": "dist/cjs/index.js",
20+
"module": "dist/esm/index.js",
21+
"repository": "[email protected]:code-like-a-carpenter/workbench.git",
22+
"types": "dist/types",
23+
"publishConfig": {
24+
"access": "public"
25+
},
26+
"dependencies": {
27+
"dotenv": "^16.0.3"
28+
},
29+
"devDependencies": {
30+
"@types/dotenv": "^8.2.0"
31+
}
32+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import dotenv from 'dotenv';
2+
3+
const TEST = process.env.NODE_ENV === 'test';
4+
const PROD = process.env.NODE_ENV === 'production';
5+
const DEV = !PROD && !TEST;
6+
7+
if (typeof process.env.SKIP_DOT_ENV === 'undefined') {
8+
[
9+
DEV && '.env.development.local',
10+
TEST && '.env.test.local',
11+
PROD && '.env.production.local',
12+
'.env.local',
13+
DEV && '.env.development',
14+
TEST && '.env.test',
15+
PROD && '.env.production',
16+
'.env',
17+
]
18+
.filter(Boolean)
19+
.forEach((name) => typeof name === 'string' && dotenv.config({path: name}));
20+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './dotenv';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "./dist/types",
4+
"rootDir": "./src"
5+
},
6+
"extends": "../../../tsconfig.references.json",
7+
"include": ["src"],
8+
"references": []
9+
}

packages/@code-like-a-carpenter/env/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ npm i @code-like-a-carpenter/env
2626

2727
## Contributing
2828

29-
Please see contributing guidelines at
29+
Please see contributing guidelines at the
3030
[project homepage](https://www.github.com/code-like-a-carpenter/workbench/tree/main/packages/@code-like-a-carpenter/env).
3131

3232
## License

packages/@code-like-a-carpenter/nx-auto/src/nx-auto.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ exports.registerProjectTargets = function registerProjectTargets(
1919
const srcDir = path.join('.', projectRoot, 'src');
2020
const distDir = path.join('.', projectRoot, 'dist');
2121

22-
const entryPoints = glob.sync(`${srcDir}/**/*.ts?(x)`).join(' ');
22+
const entryPoints = glob
23+
.sync(`${srcDir}/**/*.ts?(x)`)
24+
.filter((filePath) => !filePath.includes('.test.'))
25+
.join(' ');
2326

2427
const packageName = projectRoot.split('/').slice(-2).join('/');
2528

0 commit comments

Comments
 (0)