From 88ecc1b2166f9587925b66ff9c5a52a1ce18bd20 Mon Sep 17 00:00:00 2001 From: dal Date: Fri, 25 Jul 2025 19:31:44 -0600 Subject: [PATCH] Add simplified env file copy script for worktrees MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This script copies all .env files from ~/buster/buster to the current worktree, ignoring gitignore rules to ensure actual .env files are copied (not just examples). Unlike the existing move-env-to-worktree.ts script which respects gitignore, this script is designed specifically for syncing environment files between worktrees. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- scripts/copy-env-files.ts | 78 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 scripts/copy-env-files.ts diff --git a/scripts/copy-env-files.ts b/scripts/copy-env-files.ts new file mode 100755 index 000000000..08322ee07 --- /dev/null +++ b/scripts/copy-env-files.ts @@ -0,0 +1,78 @@ +#!/usr/bin/env tsx + +import { promises as fs } from 'node:fs'; +import { join, relative, dirname } from 'node:path'; + +const SOURCE_REPO = join(process.env.HOME!, 'buster', 'buster'); +const TARGET_REPO = process.cwd(); + +async function findEnvFiles(dir: string): Promise { + const envFiles: string[] = []; + + async function walkDir(currentDir: string) { + try { + const entries = await fs.readdir(currentDir, { withFileTypes: true }); + + for (const entry of entries) { + const fullPath = join(currentDir, entry.name); + const relativePath = relative(dir, fullPath); + + if (entry.isDirectory()) { + // Skip .git and node_modules directories + if (entry.name === '.git' || entry.name === 'node_modules') continue; + await walkDir(fullPath); + } else if (entry.name.startsWith('.env')) { + envFiles.push(relativePath); + } + } + } catch (error) { + // Skip directories we can't read + console.warn(`Skipping directory: ${currentDir}`); + } + } + + await walkDir(dir); + return envFiles; +} + +async function copyEnvFiles() { + try { + console.info(`Searching for .env files in ${SOURCE_REPO}...`); + + const envFiles = await findEnvFiles(SOURCE_REPO); + + if (envFiles.length === 0) { + console.warn('No .env files found in source repository'); + return; + } + + console.info(`Found ${envFiles.length} .env file(s):`); + envFiles.forEach(file => console.info(` - ${file}`)); + + console.info('\nCopying files...'); + + for (const envFile of envFiles) { + const sourcePath = join(SOURCE_REPO, envFile); + const targetPath = join(TARGET_REPO, envFile); + const targetDir = dirname(targetPath); + + try { + await fs.mkdir(targetDir, { recursive: true }); + + const content = await fs.readFile(sourcePath, 'utf-8'); + await fs.writeFile(targetPath, content); + + console.info(` ✓ Copied ${envFile}`); + } catch (error) { + console.error(` ✗ Failed to copy ${envFile}: ${error instanceof Error ? error.message : 'Unknown error'}`); + } + } + + console.info('\nDone! All .env files have been copied to the worktree.'); + } catch (error) { + console.error('Error:', error instanceof Error ? error.message : 'Unknown error'); + process.exit(1); + } +} + +copyEnvFiles(); \ No newline at end of file