Giter VIP home page Giter VIP logo

gen-env-template's Introduction

gen-env-template

oclif Version License All Contributors

Generate template .env.example file from your .env file.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Saurav Sahu

πŸ’»

Abishek Aditya

πŸ›

Ram Prasad Agarwal

πŸ’»

Tobias BΓΌschel

πŸ“–

Why?

A well documented template .env file helps set up the app.

How to use?

This package exposes both a CLI and an SDK.

CLI Usage

Install the tool

  • You can install gen-env-template as a devDependency.
$ npm i -D gen-env-template

$ pnpm i -D gen-env-template

$ yarn add --dev gen-env-template

You can now use the command like so:

$ ./node_modules/.bin/gen-env-template [path to input .env]=.env [path to output .env]=.env.example

Usage with npx:

$ npx gen-env-template [path to input .env]=.env [path to output .env]=.env.example

(genv is a shorthand command which can be used interchangeably.)

This will write the output to the path specified.

SDK Usage

The main import exposes a function with takes in the string contents of the .env file and returns the template string output

const genEnvTemplate = require('gen-env-template')

const inputString = 'NODE_ENV=development'

console.log(genEnvTemplate(inputString))

>> NODE_ENV=

Licensing

This project uses the MIT license as explained here.

Contributing

This project is Open-Source and I'm happy to hear feedback and receive improvements through Issues and PRs. For quick response, I'm the most active on twitter @mrsauravsahu

This project follows the all-contributors specification. Contributions of any kind welcome!

What's new? πŸŽ‰ πŸ₯³

  • v2.1.1 - Audit fixes and dependency updates
  • v2.1.0 - Improv: Ability to read multiline variables
  • v2.0.7 - Feat: Ability to remove region comments #region safe, #endregion safe
  • v2.0.6 - CI: Improvement (Use matrix builds to test on Windows, Linux and Mac)
  • v2.0.5 - Fix npm audit issues & bump node version
  • v2.0.4 - Update npm dependencies
  • v2.0.3 - Fix @oclif/command not found - move to dependencies
  • v2.0.2 - Bump all npm package versions
  • v2.0.1 - NPM audit fixes
  • v2.0.0 - Add format -f switch. Generate template-env or markdown format
  • v1.0.10 - Preserve LF or CRLF line endings from the input env file
  • v1.0.9 - Add -d or --dry-run switch to output to console
  • v1.0.8 - Remove whitespaces around key
  • v1.0.7 - Add safe region to keep sample values
  • v1.0.6 - Create CLI with OCLIF
  • v1.0.5 - Add alias command genv
  • v1.0.4 - Use gen-env-template through npx or pnpx
  • v1.0.3 - No usage change. Setup CI/CD
  • v1.0.2 - Trim bundle by ignoring files in .npmignore
  • v1.0.0 - Basic template generator

gen-env-template's People

Contributors

allcontributors[bot] avatar dependabot[bot] avatar mrsauravsahu avatar ramprasadagarwal avatar tobiasbueschel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gen-env-template's Issues

BUG: Variables with breakline isn't supported

In my .env file, I have a few private keys that require a line break in order to work with my server:

PRIVATE_KEY="-----BEGIN PRIVATE KEY-----
129812791827981whatheveristhevaluehere91092381029830192/
etc"

When I gen-env-template .env .env.example the output is

PRIVATE_KEY=
129812791827981whatheveristhevaluehere91092381029830192/
etc

When I expect

PRIVATE_KEY=

Using gen-env-template as a CLI causes an Error: Cannot find module '@oclif/command'

This can be fixed by making @oclif/command be a required dependency(or maybe just make it documented as people who don't use the CLI won't need it?), although I'm unsure if it's meant to actually end up being included or not.

In the mean time, I've created a fork which moves the dependency over and works: https://github.com/MelonCola/gen-env-template
Not sure if I should make a PR for this as I'm really not sure if this is the correct move to fix the issue.

Edit: Actually looks as though the full fleet of oclif packages might be necessary. Guess I didn't properly remove them all when testing.

Feat: Ability to retain values for certain keys

Some key=value pairs are supposed to have values in template files. They have safe values and can be committed to source control.

I have a couple of ideas for this.

Option 1

Use named regions in the .env file to mark that an area in the file contains safe values. This is similar to regions in C# files

#region safe This region contains keys which are safe to be added to source control
NODE_ENV=development 

APP_KEY=randomvalue123
#endregion safe

API_KEY=1234567890

This would result in the following template file

#region safe This region contains keys which are safe to be added to source control
NODE_ENV=development 

APP_KEY=randomvalue123
#endregion safe

API_KEY=

Option 2

This adds an -s flag in the CLI command to accept keys which are safe.

Given the following .env file below,

NODE_ENV=development 

APP_KEY=randomvalue123

API_KEY=1234567890

We can use $ genv .env template.env -s 'API_KEY' to achieve the same template as shown in Option 1's example.

Error when running through npx

OS: macOS
node: 14.16.1

Trying to run the command through npx gives a command not found. πŸ€”

➜ npx gen-env-template .env template.env
npx: command not found: gen-env-template

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.