mirror of https://github.com/buster-so/buster.git
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:
parent
57dd2895d2
commit
73e47748f2
|
@ -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();
|
Loading…
Reference in New Issue