Giter Site home page Giter Site logo

now-dotenv's Introduction

now-dotenv

Handy cli tool for managing Zeit Now v2 secrets with dotenv files ๐Ÿ™Œ

DERPECIATED

Because Vercel has new / better env support :)

https://vercel.com/blog/environment-variables-ui

Install

$ yarn global add now-dotenv

$ npm install -g now-dotenv

Why

I did not feel like retyping secrets this morning... So I wrote CLI that use Now API to sync your Now Secrets with .env files.

Now v2 Secrets are great concept for safety and CI, but now secrets add is quite cumberstone. Here's the fix!

Features

  • upload/sync your selected .env file secrets with NOW API
  • generate/sync your now.stage.json files with envs
  • generate typescript typings for process.env
  • support for multiple staging enviroments
  • small programmatic API for scripting

Usage

Basic

  $ now-dotenv -t TOKEN
  # or
  $ now-dotenv sync --token TOKEN
  # .env
  MY_SECRET="ABC"

  # run now-dotenv
  $ now-dotenv -t TOKEN
  > NowDotenv: Done!

  # now api is updated
  $ now secrets ls
  > @projectname-my-secret 0d ago

  # now.json is also updated
  {
    ...
    env: {
      ...untouchedPreviousEnvs
      my-secret: @projectname-my-secret
    }
  }

Some custom use-case

  $ now-dotenv sync \
      --token TOKEN \
      # namespace as stage "prod"
      --stage prod \
      # show .env file location (.env.prod would be default)
      --env ../.env.production
      # show now.json location (now.prod.json would be default)
      --project now.production.json \
      # sync now.production.json with now.json (whole, not just envs)
      --overwrite \
      # codegen typings for process.env
      --codegen \
      # log verboose
      --verbose \

Only delete secrets

  $ now-dotenv reset -t TOKEN
  # for all stages
  $ now-dotenv reset -t TOKEN --all

Only codegen typings for process.env

  $ now-dotenv codegen -t TOKEN --codegen ./types/env.d.ts

Options


Options:
  --help           Show help                                                    [boolean]
  --version        Show version number                                          [boolean]
  --token, -t      Zeit Now API token (@default: process.env.NOW_TOKEN)         [string]
  --stage, -s      Stage name, eg. "development (@default: no staging)          [string]
  --name, -n       Project name (@default: from now.json / package.json)        [string]
  --env, -e        Dotenv file path (@default: .env.stage / .env)               [string]
  --project, -p    Location of now.json (@default: now.stage.json / now.json)   [string]
  --api, -a        Sync now secrets api (@default: true)                        [boolean]
  --json, -j       Sync now.stage.json (@default: true)                         [boolean]
  --overwrite, -o  Overwrite whole now.stage.json (@default: false)             [boolean]
  --codegen, -c    Path for proces.env typings (@default: disabled)             [string]
  --verbose, -v    Log verboose (@default: false)                               [boolean]

API

Usage same as CLI. Documented in JSDoc.

import { NowSecretsApi, NowDotenvOptions } from 'now-dotenv'

const opts: NowDotenvOptions = {}

const api = new NowDotenv(opts)

/** Synchronise secrets with now */
await api.syncApi()

/** Synchronise secrets with now.stage.json */
await api.syncJson()

/** Deletes all/staged previous secrets */
await api.clear()

/** Generates proces.env typings */
api.codegen()

Future

Not really, It was already crazy to write this incerdibly specific tool :)

Btw. you can help Zeit spec out new env system: vercel/vercel#2613

xkcd automation comic

now-dotenv's People

Contributors

dependabot[bot] avatar vadistic avatar

Stargazers

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

Watchers

 avatar  avatar

Forkers

sbmsr

now-dotenv's Issues

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.