π Intelligent environment variable synchronization tool that keeps your
.envfiles in sync with.env.exampletemplates
- Smart Sync: Automatically synchronizes environment variables from
.env.exampleto.env - Interactive Mode: User-friendly prompts for missing or updated variables
- Preserve Values: Maintains existing values in your
.envfile - Comments & Structure: Preserves comments and file structure from templates
- Automatic Backup: Creates backups before modifying
.envfiles - Fuzzy Search: Intelligent file selection with fuzzy matching
- Type Safety: Built with TypeScript for reliability
- Comprehensive Testing: Full test coverage with Vitest
# Using npm
npm install -g synv
# Using yarn
yarn global add synv
# Using bun
bun add -g synv# Basic usage - syncs .env.example to .env
synv
# Specify custom file paths
synv --env-file .env.local --env-example-file .env.template
# Skip backup creation
synv --skip-backup
# Run in quiet mode (no output)
synv --quietWhen you run synv without arguments, it will:
- Look for
.env.examplein your current directory - Look for or create
.envin your current directory - Create a backup of your existing
.envfile - Synchronize variables from
.env.exampleto.env - Prompt you for values of new or empty variables
| Option | Short | Description |
|---|---|---|
--env-example-file <path> |
-x |
Path to the example environment file (default: .env.example) |
--env-file <path> |
-e |
Path to the environment file (default: .env) |
--skip-backup |
Skip creating a backup of the .env file | |
--quiet |
Suppress all output |
synv -x .env.template -e .env.localsynv --skip-backupsynv --quiet --skip-backupsynv intelligently parses your environment files to:
- Extract Variables: Identifies all environment variables using advanced regex patterns
- Preserve Structure: Maintains comments, empty lines, and file organization
- Smart Merging:
- Keeps existing values from your
.envfile - Adds new variables from
.env.example - Removes variables no longer in
.env.example - Updates empty variables with example values
- Keeps existing values from your
- Interactive Prompts: When values are missing or need updates, provides user-friendly prompts
synv supports various environment variable formats:
# Simple variables
API_KEY=abc123
PORT=3000
# Quoted values
DATABASE_URL="postgresql://localhost:5432/db"
MESSAGE='Hello World'
# Empty variables
SECRET_KEY=
UNSET_VAR=
# Variables with special characters
COMPLEX_VAR=value-with-dashes_and_underscores
URL=https://example.com/path?query=value
# Comments are preserved
# This is a comment
API_KEY=value # Inline comment
# Multi-line values (with quotes)
MULTI_LINE="line1
line2
line3"- Node.js 18+ or Bun 1.3.0+
- TypeScript 5.8+
# Clone the repository
git clone https://github.com/yourusername/synv.git
cd synv
# Install dependencies
bun install
# Run in development mode
bun dev
# Build the project
bun run build# Run tests
bun test
# Run tests with coverage
bun test:coverage
# Run tests with UI
bun test:uisynv/
βββ src/
β βββ cli.ts # Main CLI application
β βββ extract-environment-variables-from-file-lines.ts
β βββ extract-environment-variable-value-from-line.ts
β βββ extract-key-value-from-string.ts
β βββ regex.ts # Regex patterns for parsing
βββ coverage/ # Test coverage reports
βββ dist/ # Compiled output
βββ package.json
βββ tsconfig.json
βββ vitest.config.ts
The project includes comprehensive test coverage:
- Unit tests for all parsing functions
- Integration tests for complete workflows
- Edge case handling for various .env formats
- Regex pattern validation
Run the test suite:
bun testContributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Write tests for new features
- Maintain existing code style
- Update documentation as needed
- Ensure all tests pass before submitting PR
See Releases for a detailed changelog.
- Multi-line environment values must be properly quoted
- Some edge cases with complex regex patterns in values
- Support for
.env.local,.env.development, etc. - Configuration file support (
.synvrc) - Dry-run mode
- Variable validation rules
- Environment variable encryption
- Git hooks integration
- VS Code extension
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with cmd-ts for CLI parsing
- Interactive prompts powered by @inquirer/prompts
- Fuzzy search using fuzzbunny
- Styled output with chalk
- Progress indicators via ora
If you have any questions or run into issues, please:
- Check the FAQ section
- Search existing issues
- Create a new issue if needed
Your Name
- GitHub: @yourusername
- Twitter: @yourtwitter
Made with β€οΈ and TypeScript