UNPKG

obsidian-dev-utils

Version:

This is the collection of useful functions that you can use for your Obsidian plugin development

85 lines (84 loc) 2.75 kB
/** * @packageDocumentation * * Contains utility functions for executing commands. */ /** * Options for executing a command. */ export interface ExecOption { /** * A current working folder for the command execution. */ cwd?: string; /** * If true, suppresses the output of the command. */ isQuiet?: boolean; /** * If true, throws an error if the command fails. */ shouldFailIfCalledFromOutsideRoot?: boolean; /** * If true, ignores the exit code of the command. */ shouldIgnoreExitCode?: boolean; /** * If false, only returns the output of the command. */ shouldIncludeDetails?: boolean; /** * An input to be passed to the command. */ stdin?: string; } /** * A result of {@link exec}. */ export interface ExecResult { /** * An exit code of the command. A value of `null` indicates that the process did not exit normally. */ exitCode: null | number; /** * A signal that caused the process to be terminated. A value of `null` indicates that no signal was received. */ exitSignal: NodeJS.Signals | null; /** * A standard error output from the command. */ stderr: string; /** * A standard output from the command. */ stdout: string; } /** * Executes a command. * * @param command - The command to execute. It can be a string or an array of strings. * @param options - The options for the execution. * @returns A {@link Promise} that resolves with the output of the command. * @throws If the command fails with a non-zero exit code and `ignoreExitCode` is `false`. * The error message includes the exit code and stderr. * If an error occurs during the execution and `ignoreExitCode` is `true`, * the error is resolved with the stdout and stderr. */ export declare function exec(command: string | string[], options?: { withDetails?: false; } & ExecOption): Promise<string>; /** * Executes a command. * * @param command - The command to execute. It can be a string or an array of strings. * @param options - The options for the execution. * @returns A {@link Promise} that resolves with ExecResult object. * The ExecResult object contains the exit code, exit signal, stderr, and stdout. * @throws If the command fails with a non-zero exit code and ignoreExitCode is false. * The error message includes the exit code and stderr. * If an error occurs during the execution and ignoreExitCode is true, * the error is resolved with the stdout and stderr. */ export declare function exec(command: string | string[], options: { withDetails: true; } & ExecOption): Promise<ExecResult>;