@shopify/cli-kit
Version:
A set of utilities, interfaces, and models that are common across all the platform features
139 lines (138 loc) • 5.13 kB
TypeScript
import { AbortSignal } from './abort.js';
import type { Writable, Readable } from 'stream';
export interface ExecOptions {
cwd?: string;
env?: {
[key: string]: string | undefined;
};
stdin?: Readable | 'inherit';
stdout?: Writable | 'inherit';
stderr?: Writable | 'inherit';
stdio?: 'inherit';
input?: string;
signal?: AbortSignal;
externalErrorHandler?: (error: unknown) => Promise<void>;
background?: boolean;
}
/**
* Opens a URL in the user's default browser.
*
* @param url - URL to open.
* @returns A promise that resolves true if the URL was opened successfully, false otherwise.
*/
export declare function openURL(url: string): Promise<boolean>;
/**
* Runs a command asynchronously, aggregates the stdout data, and returns it.
*
* @param command - Command to be executed.
* @param args - Arguments to pass to the command.
* @param options - Optional settings for how to run the command.
* @returns A promise that resolves with the aggregatted stdout of the command.
*/
export declare function captureOutput(command: string, args: string[], options?: ExecOptions): Promise<string>;
/**
* Result from running a command with captureOutputWithExitCode.
*/
export interface CaptureOutputResult {
/** Standard output. */
stdout: string;
/** Standard error. */
stderr: string;
/** Exit code (0 = success). */
exitCode: number;
}
/**
* Runs a command asynchronously and returns stdout, stderr, and exit code.
* Unlike captureOutput, this function does NOT throw on non-zero exit codes.
*
* @param command - Command to be executed.
* @param args - Arguments to pass to the command.
* @param options - Optional settings for how to run the command.
* @returns A promise that resolves with stdout, stderr, and exitCode.
*
* @example
* ```typescript
* const result = await captureOutputWithExitCode('ls', ['-la'])
* if (result.exitCode !== 0) \{
* console.error('Command failed:', result.stderr)
* \}
* ```
*/
export declare function captureOutputWithExitCode(command: string, args: string[], options?: ExecOptions): Promise<CaptureOutputResult>;
/**
* Runs a command string asynchronously and returns stdout, stderr, and exit code.
* Parses the command string into command and arguments (handles quoted strings).
* Unlike captureOutput, this function does NOT throw on non-zero exit codes.
*
* @param command - Full command string to be executed (e.g., 'ls -la "my folder"').
* @param options - Optional settings for how to run the command.
* @returns A promise that resolves with stdout, stderr, and exitCode.
*
* @example
* ```typescript
* const result = await captureCommandWithExitCode('shopify theme push --theme "My Theme"')
* if (result.exitCode !== 0) {
* console.error('Command failed:', result.stderr)
* }
* ```
*/
export declare function captureCommandWithExitCode(command: string, options?: ExecOptions): Promise<CaptureOutputResult>;
/**
* Runs a command string asynchronously (parses command and arguments from the string).
*
* @param command - Full command string to be executed (e.g., 'ls -la "my folder"').
* @param options - Optional settings for how to run the command.
*/
export declare function execCommand(command: string, options?: ExecOptions): Promise<void>;
/**
* Runs a command asynchronously.
*
* @param command - Command to be executed.
* @param args - Arguments to pass to the command.
* @param options - Optional settings for how to run the command.
*/
export declare function exec(command: string, args: string[], options?: ExecOptions): Promise<void>;
/**
* Waits for a given number of seconds.
*
* @param seconds - Number of seconds to wait.
* @returns A Promise resolving after the number of seconds.
*/
export declare function sleep(seconds: number): Promise<void>;
/**
* Check if the standard input and output streams support prompting.
*
* @returns True if the standard input and output streams support prompting.
*/
export declare function terminalSupportsPrompting(): boolean;
/**
* Check if the current environment is a CI environment.
*
* @returns True if the current environment is a CI environment.
*/
export declare function isCI(): boolean;
/**
* Check if the current environment is a WSL environment.
*
* @returns True if the current environment is a WSL environment.
*/
export declare function isWsl(): Promise<boolean>;
/**
* Check if stdin has piped data available.
* This distinguishes between actual piped input (e.g., `echo "query" | cmd`)
* and non-TTY environments without input (e.g., CI).
*
* @returns True if stdin is receiving piped data or file redirect, false otherwise.
*/
export declare function isStdinPiped(): boolean;
/**
* Reads all data from stdin and returns it as a string.
* This is useful for commands that accept input via piping.
*
* @example
* // Usage: echo "your query" | shopify app execute
* const query = await readStdin()
*
* @returns A promise that resolves with the stdin content, or undefined if stdin is a TTY.
*/
export declare function readStdinString(): Promise<string | undefined>;