@settlemint/sdk-utils
Version:
Shared utilities and helper functions for SettleMint SDK modules
64 lines (62 loc) • 2.53 kB
text/typescript
import { PathLike } from "node:fs";
//#region src/filesystem/project-root.d.ts
/**
* Finds the root directory of the current project by locating the nearest package.json file
*
* @param fallbackToCwd - If true, will return the current working directory if no package.json is found
* @param cwd - The directory to start searching for the package.json file from (defaults to process.cwd())
* @returns Promise that resolves to the absolute path of the project root directory
* @throws Will throw an error if no package.json is found in the directory tree
* @example
* import { projectRoot } from "@settlemint/sdk-utils/filesystem";
*
* // Get project root path
* const rootDir = await projectRoot();
* console.log(`Project root is at: ${rootDir}`);
*/
declare function projectRoot(fallbackToCwd?: boolean, cwd?: string): Promise<string>;
//#endregion
//#region src/filesystem/exists.d.ts
/**
* Checks if a file or directory exists at the given path
*
* @param path - The file system path to check for existence
* @returns Promise that resolves to true if the path exists, false otherwise
* @example
* import { exists } from "@settlemint/sdk-utils/filesystem";
*
* // Check if file exists before reading
* if (await exists('/path/to/file.txt')) {
* // File exists, safe to read
* }
*/
declare function exists(path: PathLike): Promise<boolean>;
//#endregion
//#region src/filesystem/mono-repo.d.ts
/**
* Finds the root directory of a monorepo
*
* @param startDir - The directory to start searching from
* @returns The root directory of the monorepo or null if not found
* @example
* import { findMonoRepoRoot } from "@settlemint/sdk-utils/filesystem";
*
* const root = await findMonoRepoRoot("/path/to/your/project");
* console.log(root); // Output: /path/to/your/project/packages/core
*/
declare function findMonoRepoRoot(startDir: string): Promise<string | null>;
/**
* Finds all packages in a monorepo
*
* @param projectDir - The directory to start searching from
* @returns An array of package directories
* @example
* import { findMonoRepoPackages } from "@settlemint/sdk-utils/filesystem";
*
* const packages = await findMonoRepoPackages("/path/to/your/project");
* console.log(packages); // Output: ["/path/to/your/project/packages/core", "/path/to/your/project/packages/ui"]
*/
declare function findMonoRepoPackages(projectDir: string): Promise<string[]>;
//#endregion
export { exists, findMonoRepoPackages, findMonoRepoRoot, projectRoot };
//# sourceMappingURL=filesystem.d.cts.map