synv
v0.1.4
Published
Sync-something CLI
Readme
synv
🔄 Intelligent environment variable synchronization tool that keeps your
.envfiles in sync with.env.exampletemplates
✨ Features
- 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
📦 Installation
# Using npm
npm install -g synv
# Using yarn
yarn global add synv
# Using bun
bun add -g synv🚀 Quick Start
# 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 --quiet📖 Usage
Basic Synchronization
When 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
Command Line Options
| 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 |
Examples
Sync with custom file names
synv -x .env.template -e .env.localSync without creating backup
synv --skip-backupUse in CI/CD pipelines
synv --quiet --skip-backup🔧 How It Works
synv 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
Supported Syntax
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"🏗️ Development
Prerequisites
- Node.js 18+ or Bun 1.3.0+
- TypeScript 5.8+
Setup
# 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 buildTesting
# Run tests
bun test
# Run tests with coverage
bun test:coverage
# Run tests with UI
bun test:uiProject Structure
synv/
├── 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🧪 Testing
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 test🤝 Contributing
Contributions 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
Development Guidelines
- Write tests for new features
- Maintain existing code style
- Update documentation as needed
- Ensure all tests pass before submitting PR
📝 Changelog
See Releases for a detailed changelog.
🐛 Known Issues
- Multi-line environment values must be properly quoted
- Some edge cases with complex regex patterns in values
🗺️ Roadmap
- [ ] 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
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- 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
💬 Support
If you have any questions or run into issues, please:
- Check the FAQ section
- Search existing issues
- Create a new issue if needed
👤 Author
Your Name
- GitHub: @yourusername
- Twitter: @yourtwitter
Made with ❤️ and TypeScript
