UNPKG

worktree-tool

Version:

A command-line tool for managing Git worktrees with integrated tmux/shell session management

59 lines 2.32 kB
import { spawn } from "child_process"; import { ExecutionMode } from "./base.js"; export class InlineMode extends ExecutionMode { logger; constructor(logger) { super(); this.logger = logger; } async execute(contexts) { this.logger.info(`Executing command in ${String(contexts.length)} worktree(s) (inline mode)...`); // Execute all commands in parallel const executions = contexts.map((context) => this.executeOne(context)); const results = await Promise.allSettled(executions); // Check for failures const failures = results.filter((r) => r.status === "rejected"); if (failures.length > 0) { throw new Error(`${String(failures.length)} command(s) failed`); } } async executeOne(context) { return new Promise((resolve, reject) => { const output = []; const errors = []; const proc = spawn(context.command, context.args, { cwd: context.worktreePath, env: this.getEnvironment(context), shell: true, }); proc.stdout.on("data", (data) => { output.push(data.toString()); }); proc.stderr.on("data", (data) => { errors.push(data.toString()); }); proc.on("error", (error) => { this.logger.error(`[${context.worktreeName}] Failed to start command: ${error.message}`); reject(error); }); proc.on("close", (code) => { // Print buffered output with worktree label if (output.length > 0) { this.logger.info(`\n[${context.worktreeName}] Output:`); this.logger.info(output.join("")); } if (errors.length > 0) { this.logger.error(`[${context.worktreeName}] Errors:`); this.logger.error(errors.join("")); } if (code !== 0) { reject(new Error(`Command failed in ${context.worktreeName} with code ${String(code)}`)); } else { resolve(); } }); }); } } //# sourceMappingURL=inline.js.map