|
| 1 | +#!/usr/bin/env node |
| 2 | +/* eslint-env node */ |
| 3 | + |
| 4 | +import path from 'path' |
| 5 | +import { fileURLToPath } from 'url' |
| 6 | + |
| 7 | +import { $, question } from 'zx' |
| 8 | + |
| 9 | +// Get the directory of this script |
| 10 | +const __filename = fileURLToPath(import.meta.url) |
| 11 | +const __dirname = path.dirname(__filename) |
| 12 | + |
| 13 | +// Get the repo root (parent of tasks directory) |
| 14 | +const repoRoot = path.resolve(__dirname, '..') |
| 15 | + |
| 16 | +const originalCwd = process.cwd() |
| 17 | + |
| 18 | +const restoreCwd = () => { |
| 19 | + process.chdir(originalCwd) |
| 20 | +} |
| 21 | + |
| 22 | +process.on('exit', restoreCwd) |
| 23 | +process.on('SIGINT', restoreCwd) |
| 24 | +process.on('SIGTERM', restoreCwd) |
| 25 | +process.on('uncaughtException', (error) => { |
| 26 | + console.error('Uncaught exception:', error) |
| 27 | + restoreCwd() |
| 28 | + process.exit(1) |
| 29 | +}) |
| 30 | + |
| 31 | +try { |
| 32 | + console.log(`Original directory: ${originalCwd}`) |
| 33 | + console.log(`Repo root: ${repoRoot}`) |
| 34 | + |
| 35 | + process.chdir(repoRoot) |
| 36 | + |
| 37 | + console.log('Checking for untracked files...') |
| 38 | + const statusResult = |
| 39 | + await $`git status --porcelain --untracked-files=all`.quiet() |
| 40 | + const untrackedFiles = statusResult.stdout |
| 41 | + .trim() |
| 42 | + .split('\n') |
| 43 | + .filter((line) => line.startsWith('??')) |
| 44 | + .map((line) => line.substring(3)) |
| 45 | + .filter((file) => file.trim()) |
| 46 | + |
| 47 | + if (untrackedFiles.length > 0) { |
| 48 | + console.log( |
| 49 | + `\n⚠️ WARNING: git clean -fdx will delete ${untrackedFiles.length} untracked files/directories:`, |
| 50 | + ) |
| 51 | + |
| 52 | + if (untrackedFiles.length <= 5) { |
| 53 | + untrackedFiles.forEach((file) => { |
| 54 | + console.log(` - ${file}`) |
| 55 | + }) |
| 56 | + } else { |
| 57 | + console.log( |
| 58 | + ` (${untrackedFiles.length} files/directories - too many to list)`, |
| 59 | + ) |
| 60 | + } |
| 61 | + |
| 62 | + const confirmed = await question('\nDo you want to proceed? (y/N): ') |
| 63 | + if (!confirmed || !['y', 'yes'].includes(confirmed.toLowerCase())) { |
| 64 | + console.log('Operation cancelled.') |
| 65 | + process.exit(0) |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + console.log('Running git clean -fdx...') |
| 70 | + await $`git clean -fdx` |
| 71 | + |
| 72 | + console.log('Running yarn install...') |
| 73 | + await $`yarn install` |
| 74 | + |
| 75 | + console.log('Running yarn build...') |
| 76 | + await $`yarn build` |
| 77 | + |
| 78 | + console.log('Installing dependencies in packages/create-cedar-rsc-app...') |
| 79 | + const createCedarRscAppPath = path.join( |
| 80 | + repoRoot, |
| 81 | + 'packages/create-cedar-rsc-app', |
| 82 | + ) |
| 83 | + process.chdir(createCedarRscAppPath) |
| 84 | + await $`yarn install` |
| 85 | + |
| 86 | + console.log('All tasks completed successfully!') |
| 87 | + console.log(`Returning to original directory: ${originalCwd}`) |
| 88 | +} catch (error) { |
| 89 | + console.error('Error during clean-build process:', error) |
| 90 | + process.exit(1) |
| 91 | +} |
0 commit comments