Skip to content

Commit

Permalink
Merge pull request #7 from zackmoy/patch-1
Browse files Browse the repository at this point in the history
Support .env filename as argument
  • Loading branch information
PatrickHeneise committed Mar 5, 2024
2 parents 1572b69 + 5ed9278 commit 665e0e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ is required in the same folder as the `.env.example` file.
# yarn add @zentered/envsync
```

Two things are required to use `EnvSync`:
#### Two things are required to use `EnvSync`:

1. An `.env.example` file (use `envsync//[variable]` to indicate a variable that
should be fetched from Secrets Manager). The first variable should be
Expand All @@ -69,6 +69,11 @@ Two things are required to use `EnvSync`:
}
```

#### Optional: Specifying the `.env` file:

- If you have multiple `.env` files, you can provide the filename as an argument. The `.env` example file must end in `.example`
- Usage: `npx envsync .env.development.example` will create `.env.development`

## Contributing

See [CONTRIBUTING](CONTRIBUTING.md).
Expand Down
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import fs from 'fs/promises'
import { readExample } from './lib/readExample.js'
import { joinEnv } from './lib/joinEnv.js'

const exampleFile = await fs.readFile('.env.example', 'utf8')
const args = process.argv.slice(2);
const filePath = args[0] || '.env.example'

const exampleFile = await fs.readFile(filePath, 'utf8')
const env = await readExample(exampleFile)
await fs.writeFile('.env', joinEnv(env))
const output = filePath.replace(".example", "")
await fs.writeFile(output, joinEnv(env))

0 comments on commit 665e0e9

Please sign in to comment.