|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +/** |
| 4 | + * Post-clone setup script for vibe-coding-starter template |
| 5 | + * Run this after cloning to remove template-specific files |
| 6 | + * |
| 7 | + * Usage: node scripts/setup-template.js |
| 8 | + */ |
| 9 | + |
| 10 | +const fs = require('fs'); |
| 11 | +const path = require('path'); |
| 12 | + |
| 13 | +const ROOT = path.resolve(__dirname, '..'); |
| 14 | + |
| 15 | +const filesToRemove = [ |
| 16 | + '.github/workflows/claude-review.yml', |
| 17 | + '.github/workflows/template-cleanup.yml', |
| 18 | + 'scripts/claude-pr-review.ts', |
| 19 | +]; |
| 20 | + |
| 21 | +const devDepsToRemove = [ |
| 22 | + '@anthropic-ai/sdk', |
| 23 | + '@octokit/rest', |
| 24 | +]; |
| 25 | + |
| 26 | +function removeFile(relativePath) { |
| 27 | + const fullPath = path.join(ROOT, relativePath); |
| 28 | + if (fs.existsSync(fullPath)) { |
| 29 | + fs.unlinkSync(fullPath); |
| 30 | + console.log(`Removed: ${relativePath}`); |
| 31 | + return true; |
| 32 | + } |
| 33 | + return false; |
| 34 | +} |
| 35 | + |
| 36 | +function removeEmptyDir(relativePath) { |
| 37 | + const fullPath = path.join(ROOT, relativePath); |
| 38 | + if (fs.existsSync(fullPath)) { |
| 39 | + const files = fs.readdirSync(fullPath); |
| 40 | + if (files.length === 0) { |
| 41 | + fs.rmdirSync(fullPath); |
| 42 | + console.log(`Removed empty directory: ${relativePath}`); |
| 43 | + return true; |
| 44 | + } |
| 45 | + } |
| 46 | + return false; |
| 47 | +} |
| 48 | + |
| 49 | +function cleanPackageJson() { |
| 50 | + const pkgPath = path.join(ROOT, 'package.json'); |
| 51 | + const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')); |
| 52 | + |
| 53 | + let modified = false; |
| 54 | + |
| 55 | + if (pkg.devDependencies) { |
| 56 | + for (const dep of devDepsToRemove) { |
| 57 | + if (pkg.devDependencies[dep]) { |
| 58 | + delete pkg.devDependencies[dep]; |
| 59 | + console.log(`Removed devDependency: ${dep}`); |
| 60 | + modified = true; |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + if (modified) { |
| 66 | + fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n'); |
| 67 | + console.log('Updated package.json'); |
| 68 | + } |
| 69 | + |
| 70 | + return modified; |
| 71 | +} |
| 72 | + |
| 73 | +function selfDestruct() { |
| 74 | + const scriptPath = __filename; |
| 75 | + fs.unlinkSync(scriptPath); |
| 76 | + console.log('Removed: scripts/setup-template.js'); |
| 77 | +} |
| 78 | + |
| 79 | +function main() { |
| 80 | + console.log('\n🚀 Setting up your project from template...\n'); |
| 81 | + |
| 82 | + // Remove template-specific files |
| 83 | + for (const file of filesToRemove) { |
| 84 | + removeFile(file); |
| 85 | + } |
| 86 | + |
| 87 | + // Clean up empty .github/workflows directory |
| 88 | + removeEmptyDir('.github/workflows'); |
| 89 | + removeEmptyDir('.github'); |
| 90 | + |
| 91 | + // Clean package.json |
| 92 | + cleanPackageJson(); |
| 93 | + |
| 94 | + // Remove this script |
| 95 | + selfDestruct(); |
| 96 | + |
| 97 | + // Check if scripts folder is now empty (only if it exists) |
| 98 | + const scriptsDir = path.join(ROOT, 'scripts'); |
| 99 | + if (fs.existsSync(scriptsDir)) { |
| 100 | + const remaining = fs.readdirSync(scriptsDir); |
| 101 | + if (remaining.length === 0) { |
| 102 | + fs.rmdirSync(scriptsDir); |
| 103 | + console.log('Removed empty directory: scripts'); |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + console.log('\n✅ Template setup complete!'); |
| 108 | + console.log(' Run "npm install" to update your dependencies.\n'); |
| 109 | +} |
| 110 | + |
| 111 | +main(); |
0 commit comments