Skip to content

Commit

Permalink
Merge pull request #13 from dgreene1/first-release
Browse files Browse the repository at this point in the history
chore(readme): explains how to install this
  • Loading branch information
dgreene1 committed Jul 2, 2021
2 parents 02cc0ba + ea4bb63 commit b8c9c64
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 23 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ _"When you want your code to work in every environment, call on the Environment

## Usage / Examples

1. Create a single file that will provide your code access to your environment files. Let's call it `environmentVariables.ts`
2. Import this macro and pass it the interface that defines all of the environment variables you require to be present at runtime.
1. run `npm install environment-enforcer.macro`
2. Create a single file that will provide your code access to your environment files. Let's call it `wrappedEnvVars.ts`
3. Import this macro and pass it the interface that defines all of the environment variables you require to be present at runtime.

```ts
// inside src/environmentVariables.ts
import EnvironmentEnforcer from 'environmentEnforcer.macro';
// inside src/wrappedEnvVars.ts
import EnvironmentEnforcer from 'environment-enforcer.macro';

interface IExample {
MY_API_URL: string;
Expand All @@ -20,8 +21,8 @@ interface IExample {
export const envVars = EnvironmentEnforcer.parse<IExample>();
```

3. create a folder called `environments` (or see Configuration below for other options) and place it at the level of `package.json`
4. create files within this folder that match your environments. For example, if you don't change the default `stageNames` value, you would want to have 5 files in this folder. So:
4. create a folder called `environments` (or see Configuration below for other options) and place it at the level of `package.json`
5. create files within this folder that match your environments. For example, if you don't change the default `stageNames` value, you would want to have 5 files in this folder. So:

```
package.json
Expand All @@ -34,15 +35,15 @@ environments/production.json
node_modules/
```

5. The content of each of these files must adhere to the interface you passed into the macro in the step above. So for example, `environments/development.json` would be:
6. The content of each of these files must adhere to the interface you passed into the macro in the step above. So for example, `environments/development.json` would be:

```json
{
"MY_API_URL": "dev.whateverMyServerIs.com"
}
```

6. EnvironmentEnforcer will make sure that all of your promotions have the expected variables and that your promotions are without fear! :)
7. EnvironmentEnforcer will make sure that all of your promotions have the expected variables and that your promotions are without fear! :)

### Other Examples

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EnvironmentEnforcer from '../../../dist/environmentEnforcer.macro';
import EnvironmentEnforcer from '../../../dist/index.macro';

interface IEnvs {
foobar: string;
Expand Down
2 changes: 1 addition & 1 deletion __fixtures__/errorCases/missing-custom-env-file/code.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EnvironmentEnforcer from '../../../dist/environmentEnforcer.macro';
import EnvironmentEnforcer from '../../../dist/index.macro';

interface IEnvs {
foobar: string;
Expand Down
2 changes: 1 addition & 1 deletion __fixtures__/errorCases/missing-the-qa-env-file/code.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EnvironmentEnforcer from '../../../dist/environmentEnforcer.macro';
import EnvironmentEnforcer from '../../../dist/index.macro';

interface IEnvs {
foobar: string;
Expand Down
2 changes: 1 addition & 1 deletion __fixtures__/errorCases/missing-the-type-parameter/code.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import EnvironmentEnforcer from '../../../dist/environmentEnforcer.macro';
import EnvironmentEnforcer from '../../../dist/index.macro';

export const envVars = EnvironmentEnforcer.parse();
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EnvironmentEnforcer from '../../../dist/environmentEnforcer.macro';
import EnvironmentEnforcer from '../../../dist/index.macro';

interface IEnvs {
foobar: string;
Expand Down
2 changes: 1 addition & 1 deletion __fixtures__/successCases/happy-path/code.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EnvironmentEnforcer from '../../../dist/environmentEnforcer.macro';
import EnvironmentEnforcer from '../../../dist/index.macro';

interface IExample {
singleStr: string;
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
'src/**/*.{js,ts,jsx,tsx}',
'!**/node_modules/**',
// You can't get code coverage environmentEnforcer.macro.ts since babel-plugin-tester doesn't do that and that's where we test this end-to-end. We get unit level coverage elsewhere though
'!src/environmentEnforcer.macro.ts',
'!src/index.macro.ts',
'!**/__fixtures__/**',
'!**/dist/**',
],
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"version": "0.0.0-development",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"name": "environment-enforcer.macro",
"author": "Dan Greene",
"main": "dist/index.macro.js",
"typings": "dist/index.macro.d.ts",
"files": [
"dist",
"src"
Expand Down Expand Up @@ -31,11 +33,12 @@
"type-check:fixtures": "tsc --noEmit --project ./__fixtures__/tsconfig.json",
"emit-declarations-only": "echo 'Hopefully someday, we can stop emiting the declarations by hand, but until there is a workaround for https://github.com/babel/babel/issues/9668#issuecomment-602221154 then we will will use the emitDeclarationOnly flag of tsc and leave the transpilation to Babel.' && tsc --emitDeclarationOnly --outDir dist",
"build": "npm run emit-declarations-only && npm run type-check:business && babel src --out-dir dist --extensions \".ts,.js\" --ignore '__fixtures__/**/*','**/*.spec.*'",
"pretest": "npm run build && npm run type-check:fixtures",
"pretest": "rimraf dist && npm run build && npm run type-check:fixtures",
"test": "jest --collect-coverage",
"lint": "eslint --ext=.tsx,.ts,.js .",
"size": "size-limit",
"prepare": "husky install",
"prepack": "npm run build",
"semantic-release": "semantic-release"
},
"husky": {
Expand All @@ -49,12 +52,9 @@
"singleQuote": true,
"trailingComma": "es5"
},
"name": "environment-enforcer",
"author": "Dan Greene",
"module": "dist/environment-enforcer.esm.js",
"size-limit": [
{
"path": "dist/environmentEnforcer.macro.js",
"path": "dist/index.macro.js",
"limit": "2 KB"
}
],
Expand Down Expand Up @@ -84,6 +84,7 @@
"jest": "^26.6.3",
"prettier": "^2.3.2",
"pretty-quick": "^3.1.1",
"rimraf": "^3.0.2",
"semantic-release": "^17.4.4",
"size-limit": "^4.12.0",
"ts-jest": "^26.5.3",
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/pullInterfaceOut.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { pluckInterfaceFromFile } from './pullInterfaceOut';
describe('pluckInterfaceFromFile', () => {
it('should return only the interface name and definition and nothing around it', () => {
// ARRANGE
const fileAsStr = `import EnvironmentEnforcer from '../../dist/environmentEnforcer.macro';
const fileAsStr = `import EnvironmentEnforcer from '../../dist/environment-enforcer/macro';
interface IExample {
hello: string;
Expand Down

0 comments on commit b8c9c64

Please sign in to comment.