Add script to copy .env files from main repo to worktree

This script helps developers quickly set up environment variables in worktrees by copying all .env files from the main repository (~buster/buster) to the current worktree, preserving the directory structure.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
dal 2025-07-25 19:11:50 -06:00
parent 57dd2895d2
commit 73e47748f2
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
1 changed files with 54 additions and 0 deletions

54
scripts/move-env-to-worktree.ts Executable file
View File

@ -0,0 +1,54 @@
#!/usr/bin/env tsx
import { promises as fs } from 'node:fs';
import { join, relative, dirname } from 'node:path';
import { glob } from 'glob';
const SOURCE_REPO = join(process.env.HOME!, 'buster', 'buster');
const TARGET_REPO = process.cwd();
async function copyEnvFiles() {
try {
console.info(`Searching for .env files in ${SOURCE_REPO}...`);
const envFiles = await glob('**/.env*', {
cwd: SOURCE_REPO,
absolute: false,
dot: true,
ignore: ['**/node_modules/**', '**/.git/**']
});
if (envFiles.length === 0) {
console.warn('No .env files found in source repository');
return;
}
console.info(`Found ${envFiles.length} .env file(s)`);
for (const envFile of envFiles) {
const sourcePath = join(SOURCE_REPO, envFile);
const targetPath = join(TARGET_REPO, envFile);
const targetDir = dirname(targetPath);
console.info(`Copying ${envFile}...`);
try {
await fs.mkdir(targetDir, { recursive: true });
const content = await fs.readFile(sourcePath, 'utf-8');
await fs.writeFile(targetPath, content);
console.info(` ✓ Copied to ${relative(TARGET_REPO, targetPath)}`);
} 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();