Skip to main content

exec()

Execute a command on the limbuild server. Returns a ChildProcess-like object with stdout/stderr streams. The interface is designed to be similar to Node.js’s child_process.spawn() for familiarity and ease of extension.
import { exec } from 'limrun';

const proc = exec(
  { command: 'xcodebuild' },
  { apiUrl: '...', token: '...' }
);

// Stream output
proc.stdout.on('data', (chunk) => console.log('[stdout]', chunk));
proc.stderr.on('data', (chunk) => console.error('[stderr]', chunk));

// Wait for completion
const { exitCode, status } = await proc;

Parameters

request
ExecRequest
required
Command execution request
command
'xcodebuild'
required
The command to execute. Currently only ‘xcodebuild’ is supported.
xcodebuild
XcodeBuildConfig
Configuration for xcodebuild command
workspace
string
Path to .xcworkspace file
project
string
Path to .xcodeproj file
scheme
string
Scheme name to build
options
ExecOptions
required
Execution options
apiUrl
string
required
The API URL of the limbuild server
token
string
required
Auth token for the server
log
(level: 'debug' | 'info' | 'warn' | 'error', msg: string) => void
Custom logging function

Returns

process
ExecChildProcess
A ChildProcess-like object with stdout/stderr streams. Implements PromiseLike so it can be awaited directly.

Examples

const proc = exec({ command: 'xcodebuild' }, options);

proc.stdout.on('data', (chunk) => process.stdout.write(chunk));
proc.stderr.on('data', (chunk) => process.stderr.write(chunk));
proc.on('exit', (code) => console.log(`Exited with code ${code}`));

ExecChildProcess

A ChildProcess-like object similar to Node.js’s ChildProcess. Implements PromiseLike so it can be awaited directly.

Properties

stdout
ReadableStream
Stdout stream - emits ‘data’ and ‘close’ events
proc.stdout.on('data', (chunk: string) => {
  console.log(chunk);
});

proc.stdout.on('close', () => {
  console.log('stdout closed');
});
stderr
ReadableStream
Stderr stream - emits ‘data’ and ‘close’ events
proc.stderr.on('data', (chunk: string) => {
  console.error(chunk);
});
execId
string | undefined
The remote process/build identifier (similar to pid in Node.js)

Methods

on()

Listen for process events.
proc.on('exit', (code) => {
  console.log(`Process exited with code ${code}`);
});
event
'exit'
required
Event name to listen for
listener
(code: number) => void
required
Event handler function

kill()

Send a signal to terminate the process.
await proc.kill();
result
Promise<void>
Promise that resolves when the kill signal has been sent

then()

Promise interface for awaiting the process result.
const { exitCode, status } = await proc;
result
Promise<ExecResult>
Promise that resolves with the execution result

ReadableStream

A Readable-like stream interface, similar to Node.js stream.Readable. Emits ‘data’ for each chunk and ‘close’ when the stream ends.

Methods

on()

Attach event listeners to the stream.
proc.stdout.on('data', (chunk) => console.log(chunk));
proc.stdout.on('close', () => console.log('Stream closed'));
event
'data' | 'close'
required
Event name
listener
DataListener | CloseListener
required
Event handler function
  • For ‘data’ events: (chunk: string) => void
  • For ‘close’ events: () => void

Types

ExecRequest

type ExecRequest = {
  command: 'xcodebuild';
  xcodebuild?: {
    workspace?: string;
    project?: string;
    scheme?: string;
  };
};
Request object for executing a command.

ExecOptions

type ExecOptions = {
  apiUrl: string;
  token: string;
  log?: (level: 'debug' | 'info' | 'warn' | 'error', msg: string) => void;
};
Options for command execution.

ExecResult

type ExecResult = {
  exitCode: number;
  execId: string;
  status: 'SUCCEEDED' | 'FAILED' | 'CANCELLED';
};
Result of command execution.
exitCode
number
The exit code of the command (0 for success, non-zero for failure)
execId
string
The remote execution identifier
status
'SUCCEEDED' | 'FAILED' | 'CANCELLED'
The execution status
  • SUCCEEDED: exitCode === 0
  • FAILED: exitCode !== 0 and exitCode !== -1
  • CANCELLED: exitCode === -1 (killed)

Build docs developers (and LLMs) love