Skip to content

Commit

Permalink
Merge pull request #8 from efstajas/comments
Browse files Browse the repository at this point in the history
Allow comments in template
  • Loading branch information
efstajas authored May 4, 2020
2 parents c30a774 + 48eb70d commit 26e5f8f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ This `.env.template` means you expect all the variables FOO, BAR, and FOOBAR to
- `boolean` means your variable must be either `'true'` or `'false'`
- `string` means your variable must be a valid string. In practice, *any value will pass this test*, because .env variables are always strings.

💡*You can put comments in your env template by using `#`. Great for annotations or sharing default values!*

### Usage

To run the test, simply import the main function, and pass it your `.env.template` file path. It returns a Promise that will resolve to a `ValidatorResult`.
Expand Down
13 changes: 8 additions & 5 deletions src/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ export default (location: string, options: {
}),
})

readInterface.on('line', (line) => {
if (!line || line === '') return
readInterface.on('line', (line = '') => {
const lineWithoutComments = line.replace(/\#(.*)/g, '').trim()
if (lineWithoutComments === '') return

const name = line.split('=')[0]
const expectedType = line.split('=')[1].toUpperCase().replace('?', '')
const optional = (line.substr(-1) === '?')
const name = lineWithoutComments.split('=')[0].trim()
const expectedType = lineWithoutComments.split('=')[1]
.toUpperCase()
.replace('?', '')
const optional = (lineWithoutComments.substr(-1) === '?')
const actualValue = process.env[name]

if (!Object.values(VariableType).includes(expectedType as any)) {
Expand Down

0 comments on commit 26e5f8f

Please sign in to comment.