Not Yet Implemented - This hook is planned but not available. The API below is a design spec.
useCommand Hook
import { useCommand } from 'smithers-orchestrator'
function BuildComponent() {
const { run, output, isRunning, error } = useCommand()
const build = async () => {
const result = await run('bun', ['run', 'build'])
console.log(`Done in ${result.durationMs}ms`)
}
}
API
function useCommand(options?: UseCommandOptions): UseCommandReturn
interface UseCommandOptions {
cwd?: string // Working directory
env?: Record<string, string> // Environment variables
timeout?: number // Default: 300000 (5 min)
autoClear?: boolean // Clear output after success
}
interface UseCommandReturn {
run: (cmd: string | string[], args?: string[]) => Promise<CommandResult>
output: string
error: Error | null
isRunning: boolean
exitCode: number | null
clear: () => void
}
interface CommandResult {
stdout: string
stderr: string
exitCode: number
durationMs: number
success: boolean
}
Examples
Sequential Commands
const cmd = useCommand({ cwd: '/project' })
await cmd.run('bun install')
await cmd.run('bun run typecheck')
await cmd.run('bun test')
Conditional Execution
const test = useCommand()
const deploy = useCommand()
const result = await test.run('bun test')
if (result.success) {
await deploy.run('bun run deploy')
}
Git Workflow
const git = useCommand()
await git.run('git add .')
await git.run('git', ['commit', '-m', message])
await git.run('git push origin main')
Options
| Option | Type | Default | Description |
|---|
cwd | string | process.cwd() | Working directory |
env | Record<string, string> | {} | Merged with process.env |
timeout | number | 300000 | Timeout in ms |
autoClear | boolean | false | Clear output after success |
Return Values
| Property | Type | Description |
|---|
run | (cmd, args?) => Promise<CommandResult> | Execute command |
output | string | stdout + stderr |
error | Error | null | Last error |
isRunning | boolean | Currently executing |
exitCode | number | null | Last exit code |
clear | () => void | Clear state |