All files / src/commands sync-forever.ts

0% Statements 0/41
0% Branches 0/1
0% Functions 0/1
0% Lines 0/41

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42                                                                                   
import { execa } from "execa";
import chalk from "chalk";
import { join } from "path";
import { promises as fs } from "fs";

export async function syncForever(): Promise<void> {
  const ralphScript = join(process.cwd(), ".repomirror", "ralph.sh");

  try {
    // Check if ralph.sh exists
    await fs.access(ralphScript);
  } catch {
    console.error(
      chalk.red(
        "Error: .repomirror/ralph.sh not found. Run 'npx repomirror init' first.",
      ),
    );
    process.exit(1);
  }

  console.log(chalk.cyan("Running ralph.sh (continuous sync)..."));
  console.log(chalk.yellow("Press Ctrl+C to stop"));

  try {
    await execa("bash", [ralphScript], {
      stdio: "inherit",
      cwd: process.cwd(),
    });
  } catch (error) {
    if (error instanceof Error && (error as any).signal === "SIGINT") {
      console.log(chalk.yellow("\nStopped by user"));
    } else {
      console.error(
        chalk.red(
          `Sync forever failed: ${error instanceof Error ? error.message : String(error)}`,
        ),
      );
      process.exit(1);
    }
  }
}