1.0.0 • Published 3 years ago

copy-env-cli v1.0.0

Weekly downloads
57
License
MIT
Repository
-
Last release
3 years ago

copy-env-cli

📜 About

A tiny command-line interface (CLI) to copy .env.example to .env in the current working directory if the .env file doesn't exist yet. Useful to facilitate the installation of your application by setting default environment variables while leaving the .env file ignored.

💾 Install

npm install --save-dev copy-env-cli

⚙️ Usage

CLI

copy-env-cli

package.json

{
  ...
  "scripts": {
    "postinstall": "copy-env-cli"
  }
  ...
}

Source code

#!/usr/bin/env node
const fs = require('fs')
const path = require('path')

const cwd = process.cwd()
const envPath = path.join(cwd, '.env')
const envExamplePath = path.join(cwd, '.env.example')

if (!fs.existsSync(envPath) && fs.existsSync(envExamplePath)) {
  fs.copyFileSync(envExamplePath, envPath)
}

📄 License

MIT