Skip to content

[Feature Proposal]: Opt-in Preservation of Public Variables in .env to .example.env Syncing #52

@MendyLanda

Description

@MendyLanda

Feature Proposal: Enhancements for Syncing .env Files

Objective:

Improve the functionality of our CLI tool that synchronises .env files to .example.env files by providing an escape mechanism to preserve specific values for public variables.

Problem:

Currently, all variables in the .example.env file exist as empty strings after the syncing process. It would be helpful for public variables to retain their values.

Proposed Solution:

I thought of two way to achive this:

  1. Public Prefix Preservation: Allow users to specify a custom or default prefix for variable names that they want to remain public. Any variable with this prefix will retain its value during the sync process.

    CLI Example:

    sync-dotenv --preserve-public-prefix=NEXT_PUBLIC

    In this example, any variable starting with NEXT_PUBLIC will keep its original value in the .example.env file.

    Default behavior (when flag is used without a value): An error will be thrown requesting for a prefix input.

  2. Keyword Comment Preservation: Allow users to mark variables for preservation using a default or custom keyword comment at the end of the line.

    .env file Example:

    SENTRY_URL='https://example.ingest.sentry.io/example' #SYNC_VALUE

    CLI Example:

    sync-dotenv --preserve-keyword-comment=SYNC_VALUE

    In this example, any variable line ending with #SYNC_VALUE will keep its original value in the .example.env file.

    Default behavior (when flag is used without a value): An error will be thrown requesting for a keyword input.

Considerations:

  1. Need to ensure these changes are well documented in the CLI help text.

  2. Need to provide examples in the readme for the new flag and potential use cases.

  3. Error handling needs to be designed carefully to provide meaningful error messages, especially when the new flags are used without necessary inputs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions