@settlemint/sdk-utils
Version:
Shared utilities and helper functions for SettleMint SDK modules
122 lines (120 loc) • 4.84 kB
TypeScript
import { AgentName } from "package-manager-detector";
//#region src/package-manager/download-and-extract.d.ts
/**
* Formats a directory path by removing trailing slashes and whitespace
*
* @param targetDir - The directory path to format
* @returns The formatted directory path
* @example
* import { formatTargetDir } from "@settlemint/sdk-utils/package-manager";
*
* const formatted = formatTargetDir("/path/to/dir/ "); // "/path/to/dir"
*/
declare function formatTargetDir(targetDir: string): string;
/**
* Checks if a directory is empty or contains only a .git folder
*
* @param path - The directory path to check
* @returns True if directory is empty or contains only .git, false otherwise
* @example
* import { isEmpty } from "@settlemint/sdk-utils/package-manager";
*
* if (await isEmpty("/path/to/dir")) {
* // Directory is empty
* }
*/
declare function isEmpty(path: string): Promise<boolean>;
/**
* Removes all contents of a directory except the .git folder
*
* @param dir - The directory path to empty
* @example
* import { emptyDir } from "@settlemint/sdk-utils/package-manager";
*
* await emptyDir("/path/to/dir"); // Removes all contents except .git
*/
declare function emptyDir(dir: string): Promise<void>;
//#endregion
//#region src/package-manager/get-package-manager.d.ts
/**
* Detects the package manager used in the current project
*
* @param targetDir - The directory to check for package manager (optional, defaults to process.cwd())
* @returns The name of the package manager
* @example
* import { getPackageManager } from "@settlemint/sdk-utils/package-manager";
*
* const packageManager = await getPackageManager();
* console.log(`Using ${packageManager}`);
*/
declare function getPackageManager(targetDir?: string): Promise<AgentName>;
//#endregion
//#region src/package-manager/get-package-manager-executable.d.ts
/**
* Retrieves the executable command and arguments for the package manager
*
* @param targetDir - The directory to check for package manager (optional, defaults to process.cwd())
* @returns An object containing the command and arguments for the package manager
* @example
* import { getPackageManagerExecutable } from "@settlemint/sdk-utils/package-manager";
*
* const { command, args } = await getPackageManagerExecutable();
* console.log(`Using ${command} with args: ${args.join(" ")}`);
*/
declare function getPackageManagerExecutable(targetDir?: string): Promise<{
command: string;
args: string[];
}>;
//#endregion
//#region src/package-manager/install-dependencies.d.ts
/**
* Installs one or more packages as dependencies using the detected package manager
*
* @param pkgs - A single package name or array of package names to install
* @param cwd - The directory to run the installation in
* @returns A promise that resolves when installation is complete
* @throws If package installation fails
* @example
* import { installDependencies } from "@settlemint/sdk-utils/package-manager";
*
* // Install a single package
* await installDependencies("express");
*
* // Install multiple packages
* await installDependencies(["express", "cors"]);
*/
declare function installDependencies(pkgs: string | string[], cwd?: string): Promise<void>;
//#endregion
//#region src/package-manager/is-package-installed.d.ts
/**
* Checks if a package is installed in the project's dependencies, devDependencies, or peerDependencies.
*
* @param name - The name of the package to check
* @param path - The path to the project root directory. If not provided, will be automatically determined
* @returns Whether the package is installed
* @throws If unable to read or parse the package.json file
* @example
* import { isPackageInstalled } from "@settlemint/sdk-utils/package-manager";
*
* const isInstalled = await isPackageInstalled("@settlemint/sdk-utils");
* console.log(`@settlemint/sdk-utils is installed: ${isInstalled}`);
*/
declare function isPackageInstalled(name: string, path?: string): Promise<boolean>;
//#endregion
//#region src/package-manager/set-name.d.ts
/**
* Sets the name field in the package.json file
*
* @param name - The new name to set in the package.json file
* @param path - The path to the project root directory. If not provided, will be automatically determined
* @returns A promise that resolves when the package.json has been updated
* @throws If unable to read, update or save the package.json file
* @example
* import { setName } from "@settlemint/sdk-utils/package-manager";
*
* await setName("my-new-project-name");
*/
declare function setName(name: string, path?: string): Promise<void>;
//#endregion
export { emptyDir, formatTargetDir, getPackageManager, getPackageManagerExecutable, installDependencies, isEmpty, isPackageInstalled, setName };
//# sourceMappingURL=package-manager.d.ts.map