obsidian-dev-utils
Version:
This is the collection of useful functions that you can use for your Obsidian plugin development
69 lines (68 loc) • 3.03 kB
text/typescript
/**
* @packageDocumentation
*
* Contains utility functions for executing commands from the root folder of a project,
* resolving paths relative to the root.
*/
import type { ExecOption, ExecResult } from './Exec.mjs';
/**
* Executes a command from the root folder of the project.
*
* @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 execFromRoot(command: string | string[], options?: {
withDetails?: false;
} & ExecOption): Promise<string>;
/**
* Executes a command from the root folder of the project.
*
* @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 execFromRoot(command: string | string[], options: {
withDetails: true;
} & ExecOption): Promise<ExecResult>;
/**
* Retrieves the root folder of the project.
*
* @param cwd - The current working folder to resolve from.
* @returns The path to the root folder.
* @throws If the root folder cannot be found.
*/
export declare function getRootFolder(cwd?: string): null | string;
/**
* Resolves a path relative to the root folder of the project.
*
* @param path - The path to resolve.
* @param cwd - The current working folder to resolve from.
* @returns The resolved absolute path.
*/
export declare function resolvePathFromRoot(path: string, cwd?: string): null | string;
/**
* Resolves a path relative to the root folder, returning the resolved path or the original path if it does not exist.
*
* @param path - The path to resolve.
* @param cwd - The current working folder to resolve from.
* @returns The resolved path or the original path if it does not exist.
*/
export declare function resolvePathFromRootSafe(path: string, cwd?: string): string;
/**
* Converts an absolute path to a relative path from the root folder of the project.
*
* @param path - The absolute path to convert.
* @param cwd - The current working folder to resolve from.
* @returns The relative path from the root folder.
*/
export declare function toRelativeFromRoot(path: string, cwd?: string): null | string;