### Install env-twin using yarn Source: https://github.com/atssj/env-twin/blob/main/README.md Installs env-twin as a development dependency using yarn. This command is equivalent to the npm installation for yarn users. ```bash yarn add --dev env-twin ``` -------------------------------- ### Install env-twin using Bun Source: https://github.com/atssj/env-twin/blob/main/README.md Installs env-twin as a development dependency using Bun. This command is for developers using the Bun runtime and package manager. ```bash bun add -D env-twin ``` -------------------------------- ### Install env-twin using pnpm Source: https://github.com/atssj/env-twin/blob/main/README.md Installs env-twin as a development dependency using pnpm. This command is suitable for users who prefer the pnpm package manager. ```bash pnpm add -D env-twin ``` -------------------------------- ### Install env-twin using npm Source: https://github.com/atssj/env-twin/blob/main/README.md Installs env-twin as a development dependency using npm. This command ensures the tool is available for use in your project's development scripts. ```bash npm install --save-dev env-twin ``` -------------------------------- ### Install env-twin using npm, Yarn, Bun, or pnpm Source: https://github.com/atssj/env-twin/blob/main/llm.txt Install env-twin as a development dependency using your preferred package manager. This command adds the tool to your project's devDependencies. ```bash npm install --save-dev env-twin ``` ```bash yarn add --dev env-twin ``` ```bash bun add -D env-twin ``` ```bash pnpm add -D env-twin ``` -------------------------------- ### Generate .env.example from .env (Legacy CLI) Source: https://context7.com/atssj/env-twin/llms.txt Generates a `.env.example` file from a `.env` file by sanitizing all values into placeholder strings. This is the default command if no subcommand is specified. ```bash # Generate .env.example from .env npx env-twin # Specify source and destination files npx env-twin --source .env.development --dest .env.dev.example ``` -------------------------------- ### List Available Backup Sets (TypeScript) Source: https://context7.com/atssj/env-twin/llms.txt Lists all available backup sets, sorted by creation time with the most recent first. For each backup set, it provides the timestamp, a list of backed-up files, and the creation date. Requires the current working directory as input. ```typescript import { listBackups } from 'env-twin/utils/backup'; const backups = listBackups(process.cwd()); backups.forEach(backup => { console.log(`Timestamp: ${backup.timestamp}`); console.log(`Files: ${backup.files.join(', ')}`); console.log(`Created: ${backup.createdAt.toISOString()}`); }); // Output: // Timestamp: 20241208-143022 // Files: .env, .env.local, .env.example // Created: 2024-12-08T14:30:22.000Z // // Timestamp: 20241208-120530 // Files: .env, .env.example // Created: 2024-12-08T12:05:30.000Z ``` -------------------------------- ### Run env-twin with default paths Source: https://github.com/atssj/env-twin/blob/main/README.md Executes env-twin with default settings, synchronizing the primary .env file to its corresponding .env.example file. This is the simplest way to initiate the sync process. ```bash npx env-twin ``` -------------------------------- ### Restore Files with Progress and Rollback (TypeScript) Source: https://context7.com/atssj/env-twin/llms.txt Restores files from a backup with detailed progress tracking and rollback capability. It supports preserving file permissions and timestamps, and can create a backup before restoration. This function is useful for recovering previous environment configurations. ```typescript import { FileRestorer } from 'env-twin/modules/file-restoration'; import { BackupDiscovery } from 'env-twin/modules/backup-discovery'; const restorer = new FileRestorer(process.cwd()); // Set up progress callback restorer.setProgressCallback((progress) => { const percentage = Math.round((progress.current / progress.total) * 100); console.log(`${percentage}% - ${progress.phase}: ${progress.currentFile}`); }); // Find a backup to restore const discovery = new BackupDiscovery(process.cwd()); const backup = discovery.findMostRecentValidBackup(); if (backup) { // Restore with options const result = await restorer.restoreFiles(backup, { preservePermissions: true, preserveTimestamps: true, createBackup: true, force: false, dryRun: false }); console.log(`Success: ${result.success}`); console.log(`Restored: ${result.restoredCount} files`); console.log(`Failed: ${result.failedCount} files`); if (result.warnings.length > 0) { console.warn('Warnings:', result.warnings); } if (result.errors.size > 0) { console.error('Errors:'); result.errors.forEach((error, fileName) => { console.error(` ${fileName}: ${error}`); }); } } ``` -------------------------------- ### Create Timestamped Backups (TypeScript) Source: https://context7.com/atssj/env-twin/llms.txt Creates timestamped backups for multiple environment files in the .env-twin/ directory. It takes an array of file paths and the current working directory as input, returning a timestamp string or null if no backups were created. The .env-twin directory is automatically added to .gitignore. ```typescript import { createBackups } from 'env-twin/utils/backup'; import path from 'path'; // Backup multiple environment files const filesToBackup = [ path.resolve(process.cwd(), '.env'), path.resolve(process.cwd(), '.env.local'), path.resolve(process.cwd(), '.env.example') ]; const timestamp = createBackups(filesToBackup, process.cwd()); if (timestamp) { console.log(`Backup created with timestamp: ${timestamp}`); // Output: Backup created with timestamp: 20241208-143022 // Files are stored as: // .env-twin/.env.20241208-143022 // .env-twin/.env.local.20241208-143022 // .env-twin/.env.example.20241208-143022 } else { console.error('Failed to create backup'); } // The .env-twin directory is automatically added to .gitignore ``` -------------------------------- ### Run env-twin with custom paths Source: https://github.com/atssj/env-twin/blob/main/README.md Executes env-twin, specifying custom source and destination files for synchronization. This allows flexibility in managing different environment configurations. ```bash npx env-twin --source .env.development --dest .env.dev.example ``` -------------------------------- ### BackupDiscovery Class for Validation (TypeScript) Source: https://context7.com/atssj/env-twin/llms.txt A class designed for discovering and validating backups with robust error checking. It automates backup selection and validation, offering methods to discover all backups, find the most recent valid one, and retrieve specific backups by timestamp along with their validation status and file details. ```typescript import { BackupDiscovery } from 'env-twin/modules/backup-discovery'; const discovery = new BackupDiscovery(process.cwd()); // Discover and validate all backups const result = discovery.discoverAndValidateBackups(); console.log(`Total backups found: ${result.validatedBackups.length}`); console.log(`Valid backups: ${result.validatedBackups.filter(b => b.isValid).length}`); if (result.errors.length > 0) { console.error('Validation errors:', result.errors); } // Find most recent valid backup automatically const mostRecent = discovery.findMostRecentValidBackup(); if (mostRecent) { console.log(`Most recent backup: ${mostRecent.timestamp}`); console.log(`Files: ${mostRecent.files.join(', ')}`); console.log(`Created: ${mostRecent.createdAt.toISOString()}`); } // Get specific backup by timestamp with validation const specific = discovery.getBackupByTimestamp('20241208-143022'); if (specific && specific.isValid) { console.log('Backup is valid and ready to restore'); console.log(`File count: ${specific.files.length}`); specific.fileStats.forEach((stats, fileName) => { console.log(`${fileName}: ${stats.size} bytes`); }); } else if (specific && !specific.isValid) { console.error('Backup is invalid:', specific.errors); } ``` -------------------------------- ### Synchronize Environment Variables Across .env Files (TypeScript) Source: https://context7.com/atssj/env-twin/llms.txt Programmatically runs the sync command to synchronize environment variable keys across all .env* files in the current directory. It can optionally create backups before synchronizing. This is crucial for maintaining consistency across different environments. ```typescript import { runSync } from 'env-twin/commands/sync'; // Run sync with automatic backup runSync({ noBackup: false }); // Run sync without backup (not recommended) runSync({ noBackup: true }); // The function will: // 1. Discover all .env* files in the current directory // 2. Create timestamped backups (unless noBackup is true) // 3. Collect all unique environment variable keys // 4. Add missing keys to each file // 5. Generate .env.example with sanitized placeholder values // 6. Print a summary of changes ``` -------------------------------- ### Restore environment files from backup Source: https://github.com/atssj/env-twin/blob/main/llm.txt Restores your environment files from a previously created backup. An optional timestamp can be provided to specify which backup to restore. ```bash env-twin restore [timestamp] ``` -------------------------------- ### Restore .env Files from Backup (CLI) Source: https://context7.com/atssj/env-twin/llms.txt Restores `.env*` files from a backup. Automatically selects the most recent backup if no timestamp is provided. Supports dry runs, listing backups, and creating rollback snapshots. ```bash # Restore most recent backup npx env-twin restore # Restore specific backup by timestamp npx env-twin restore 20241208-143022 # List available backups npx env-twin restore --list # Dry run npx env-twin restore --dry-run ``` -------------------------------- ### Sync environment variables with automatic backup Source: https://github.com/atssj/env-twin/blob/main/llm.txt This command synchronizes all environment variable keys across your .env* files. It automatically creates a timestamped backup before making any modifications. ```bash env-twin sync ``` -------------------------------- ### Restore environment variables from backup Source: https://github.com/atssj/env-twin/blob/main/README.md Restores environment files from a specific timestamped backup. The --yes flag bypasses confirmation prompts for automated restoration. ```bash npx env-twin restore 20241125-143022 --yes ``` -------------------------------- ### Sync Environment Variables Across .env Files (CLI) Source: https://context7.com/atssj/env-twin/llms.txt Synchronizes environment variable keys across all `.env*` files in the current directory. It adds missing keys with empty values and can create automatic timestamped backups. Discovers files like `.env`, `.env.local`, `.env.example`, etc. ```bash npx env-twin sync # Sync without backup npx env-twin sync --no-backup ``` -------------------------------- ### Restore Files from Specific Backup (TypeScript) Source: https://context7.com/atssj/env-twin/llms.txt Restores files from a specified backup timestamp. It takes the timestamp string and the current working directory as arguments, returning an object containing lists of successfully restored and failed files. Useful for reverting to a previous state. ```typescript import { restoreBackup } from 'env-twin/utils/backup'; const result = restoreBackup('20241208-143022', process.cwd()); console.log(`Restored files: ${result.restored.join(', ')}`); console.log(`Failed files: ${result.failed.join(', ')}`); if (result.failed.length > 0) { console.error('Some files failed to restore'); } else { console.log('All files restored successfully'); } // Output: // Restored files: .env, .env.local, .env.example // Failed files: // All files restored successfully ``` -------------------------------- ### Clean up old environment backups Source: https://github.com/atssj/env-twin/blob/main/llm.txt Removes old backups to manage storage space. The --keep option allows you to specify the number of recent backups to retain. ```bash env-twin clean-backups --keep ``` -------------------------------- ### Clean Old Backup Sets (TypeScript) Source: https://context7.com/atssj/env-twin/llms.txt Cleans up old backup sets created by env-twin, keeping a specified number of the most recent backups. This utility helps manage disk space by removing outdated backup files. It returns a result object detailing which backup sets were deleted and which were kept. ```typescript import { cleanOldBackups } from 'env-twin/utils/backup'; // Keep 10 most recent backups (default) const result = cleanOldBackups(process.cwd(), 10); console.log(`Deleted: ${result.deleted.length} backup sets`); console.log(`Kept: ${result.kept.length} backup sets`); // Deleted timestamps result.deleted.forEach(timestamp => { console.log(` Deleted: ${timestamp}`); }); // Kept timestamps result.kept.forEach(timestamp => { console.log(` Kept: ${timestamp}`); }); ``` -------------------------------- ### Clean Old .env Backups (CLI) Source: https://context7.com/atssj/env-twin/llms.txt Deletes old backup sets to save disk space, keeping a specified number of the most recent backups. By default, it keeps the 10 most recent backups. ```bash # Clean backups, keeping 10 most recent npx env-twin clean-backups # Clean backups, keeping 5 most recent npx env-twin clean-backups --keep 5 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.