npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

commitsafe

v2.3.2

Published

A powerful CLI tool that encrypts and decrypts .env files to protect your sensitive information during git commits. CommitSafe ensures that secrets remain secure and reduces the risk of accidental exposure in your repositories.

Downloads

54

Readme

commitsafe

A powerful CLI tool that encrypts and decrypts .env files to protect your sensitive information during git commits. CommitSafe ensures that secrets remain secure and reduces the risk of accidental exposure in your repositories.

npm version license downloads

What's New in Version 2.3.0?

  • Enhanced Git hooks integration for seamless operation.
  • Transitioned encryption/decryption backend from npm:crypto-js to the efficient node:crypto module.

Installation

You can install commitsafe using either npm or bun:

# Using npm
npm install --save-dev commitsafe
# Using bun
bun add --dev commitsafe

Usage

commitsafe enables encryption and decryption of environment variables within files. Run commitsafe --help for command-line interface details:

Usage: commitsafe [options] <files...>

Encrypt and decrypt environment variables in a file.

Arguments:
  <files...>       Files to encrypt or decrypt

Options:
  -l, --list       List files and their corresponding encryption keys
  -e, --encrypt    Encrypt environment variables in a file
  -d, --decrypt    Decrypt environment variables in a file
  -k, --key <key>  Optional: Specify the encryption/decryption key. By default, commitsafe uses keys stored in ~/.commitsafe
  -h, --help       Display help for command

How It Works

  • Encrypts specified environment variables in .env files.
  • Securely decrypts the variables back when needed.

Example:

# Original .env file
HELLO=world

# After running `commitsafe -e .env`
HELLO=encrypted::8cwf0HbsXjaniUiCZ4EH+A==:7XMi+FfjoKu3b+q/lRNuwQ==

# After running `commitsafe -d .env`
HELLO=world

Instructions

Encrypting/Decrypting a Single File

# Encrypt a single .env file
commitsafe -e .env

# Decrypt a single .env file
commitsafe -d .env

Encrypting/Decrypting Multiple Files

# Encrypt multiple .env files
commitsafe -e .env .env.local ...

# Decrypt multiple .env files
commitsafe -d .env .env.local ...

Using a Specific Key (Ideal for CI/CD Environments)

# Encrypt using a specific key
commitsafe -e .env -k my-secret-key

# Decrypt using a specific key
commitsafe -d .env -k my-secret-key

Listing Files and Their Encryption Keys

commitsafe -l .env .env.local ...

Best Practices: Committing .env Files Safely

To automate the safe management of .env files using Git hooks, follow these steps:

  1. Install necessary development dependencies:

    bun add -D commitsafe lint-staged simple-git-hooks
  2. Encrypt your .env file initially to set up an encryption key:

    commitsafe -e .env
  3. Configure Git hooks and lint-staged in your package.json:

    Add the following scripts to automate pre-commit encryption and post-commit decryption:

    // In package.json
    {
      "scripts": {
        "prepare": "simple-git-hooks"
      },
      "lint-staged": {
        ".env": ["commitsafe -e"]
      },
      "simple-git-hooks": {
        "pre-commit": "bunx lint-staged",
        "post-commit": "bunx commitsafe -d .env"
      }
    }

    Then, apply the hook configuration with:

    bun run prepare

By leveraging commitsafe, you can confidently manage your .env files by ensuring that sensitive information remains encrypted, reducing the risk of accidental exposure.

For more details, visit the GitHub repository. If you encounter issues, please report them here.

This project is licensed under the MIT License.