/** * Codumentation Helpers - Reusable validation functions for .codx modules * * These helpers wrap common validation patterns to make writing validate() functions * easier and more consistent. Import them in your .codx modules: * * ```typescript * import { assertFileExists, assertDependency } from 'codumentation/helpers'; * ``` */ /** * Asserts that a file exists at the given path * @param filePath - Path to the file (relative to cwd or absolute) * @param message - Optional custom error message * @throws Error if file doesn't exist */ export declare function assertFileExists(filePath: string, message?: string): void; /** * Asserts that all files in the array exist * @param filePaths - Array of file paths to check * @param message - Optional custom error message prefix * @throws Error if any file doesn't exist */ export declare function assertFilesExist(filePaths: string[], message?: string): void; /** * Asserts that a directory exists at the given path * @param dirPath - Path to the directory * @param message - Optional custom error message * @throws Error if directory doesn't exist or is not a directory */ export declare function assertDirectoryExists(dirPath: string, message?: string): void; /** * Asserts that a path does NOT exist (useful for ensuring cleanup) * @param targetPath - Path that should not exist * @param message - Optional custom error message * @throws Error if path exists */ export declare function assertNotExists(targetPath: string, message?: string): void; /** * Options for glob-based assertions */ export interface GlobOptions { cwd?: string; ignore?: string[]; } /** * Asserts that a glob pattern matches at least one file * @param pattern - Glob pattern to match * @param options - Optional glob options * @returns Array of matching file paths * @throws Error if no files match */ export declare function assertGlobMatches(pattern: string, options?: GlobOptions): string[]; /** * Asserts that a glob pattern matches NO files (useful for forbidden patterns) * @param pattern - Glob pattern that should not match anything * @param options - Optional glob options * @param message - Optional custom error message * @throws Error if any files match */ export declare function assertNoGlobMatches(pattern: string, options?: GlobOptions, message?: string): void; /** * Asserts that a glob pattern matches exactly N files * @param pattern - Glob pattern to match * @param expectedCount - Expected number of matches * @param options - Optional glob options * @throws Error if count doesn't match */ export declare function assertGlobCount(pattern: string, expectedCount: number, options?: GlobOptions): string[]; /** * Asserts that a glob pattern matches at least N files * @param pattern - Glob pattern to match * @param minCount - Minimum number of matches * @param options - Optional glob options * @throws Error if count is less than minimum */ export declare function assertGlobMinCount(pattern: string, minCount: number, options?: GlobOptions): string[]; /** * Reads and parses package.json from a directory * @param dir - Directory containing package.json (defaults to cwd) * @returns Parsed package.json object * @throws Error if package.json not found or invalid */ export declare function readPackageJson(dir?: string): Record; /** * Asserts that a dependency exists in package.json (either deps or devDeps) * @param name - Package name to check * @param dir - Directory containing package.json * @throws Error if dependency not found */ export declare function assertDependency(name: string, dir?: string): void; /** * Asserts that a dependency exists specifically in dependencies (not devDeps) * @param name - Package name to check * @param dir - Directory containing package.json * @throws Error if not in production dependencies */ export declare function assertProdDependency(name: string, dir?: string): void; /** * Asserts that a dependency exists specifically in devDependencies * @param name - Package name to check * @param dir - Directory containing package.json * @throws Error if not in dev dependencies */ export declare function assertDevDependency(name: string, dir?: string): void; /** * Asserts that multiple dependencies exist * @param names - Array of package names to check * @param dir - Directory containing package.json * @throws Error if any dependency not found */ export declare function assertDependencies(names: string[], dir?: string): void; /** * Asserts that an npm script exists in package.json * @param name - Script name to check * @param dir - Directory containing package.json * @throws Error if script not found */ export declare function assertScript(name: string, dir?: string): void; /** * Asserts that multiple npm scripts exist * @param names - Array of script names to check * @param dir - Directory containing package.json * @throws Error if any script not found */ export declare function assertScripts(names: string[], dir?: string): void; /** * Asserts that a bin entry exists in package.json * @param name - Bin name to check * @param dir - Directory containing package.json * @throws Error if bin entry not found */ export declare function assertBin(name: string, dir?: string): void; /** * Gets the package version from package.json * @param dir - Directory containing package.json * @returns The version string */ export declare function getPackageVersion(dir?: string): string; /** * Gets the package name from package.json * @param dir - Directory containing package.json * @returns The package name */ export declare function getPackageName(dir?: string): string; /** * Asserts that a file contains a specific string * @param filePath - Path to the file * @param searchString - String that should be in the file * @param message - Optional custom error message * @throws Error if string not found in file */ export declare function assertFileContains(filePath: string, searchString: string, message?: string): void; /** * Asserts that a file does NOT contain a specific string (for forbidden patterns) * @param filePath - Path to the file * @param searchString - String that should NOT be in the file * @param message - Optional custom error message * @throws Error if string IS found in file */ export declare function assertFileNotContains(filePath: string, searchString: string, message?: string): void; /** * Asserts that a file content matches a regex pattern * @param filePath - Path to the file * @param pattern - Regex pattern to match * @param message - Optional custom error message * @throws Error if pattern not found */ export declare function assertFileMatches(filePath: string, pattern: RegExp, message?: string): RegExpMatchArray; /** * Asserts that a file does NOT match a regex pattern (for forbidden patterns) * @param filePath - Path to the file * @param pattern - Regex pattern that should NOT match * @param message - Optional custom error message * @throws Error if pattern IS found */ export declare function assertFileNotMatches(filePath: string, pattern: RegExp, message?: string): void; /** * Asserts that NO file matching glob contains the regex pattern (forbidden code patterns) * @param globPattern - Glob pattern to find files * @param regex - Regex pattern that should NOT be found * @param message - Optional custom error message * @param options - Optional glob options * @throws Error if pattern found in any file */ export declare function assertNoCodePattern(globPattern: string, regex: RegExp, message?: string, options?: GlobOptions): void; /** * Asserts that ALL files matching glob contain the regex pattern * @param globPattern - Glob pattern to find files * @param regex - Regex pattern that SHOULD be found * @param message - Optional custom error message * @param options - Optional glob options * @throws Error if pattern not found in any file */ export declare function assertCodePattern(globPattern: string, regex: RegExp, message?: string, options?: GlobOptions): void; /** * Reads and parses tsconfig.json * @param dir - Directory containing tsconfig.json * @returns Parsed tsconfig object * @throws Error if tsconfig not found or invalid */ export declare function readTsConfig(dir?: string): Record; /** * Asserts that TypeScript strict mode is enabled * @param dir - Directory containing tsconfig.json * @throws Error if strict mode not enabled */ export declare function assertStrictMode(dir?: string): void; /** * Asserts a specific tsconfig compiler option has expected value * @param option - Compiler option name (e.g., 'target', 'module') * @param expectedValue - Expected value * @param dir - Directory containing tsconfig.json * @throws Error if option doesn't match */ export declare function assertTsConfigOption(option: string, expectedValue: any, dir?: string): void; /** * Asserts that a directory structure matches expected layout * @param expectedStructure - Object describing expected structure * @param rootDir - Root directory to check * @throws Error if structure doesn't match * * @example * assertFolderStructure({ * 'src': { * 'index.ts': 'file', * 'types': 'dir', * 'utils': 'dir' * }, * 'tests': 'dir', * 'package.json': 'file' * }); */ export declare function assertFolderStructure(expectedStructure: Record>, rootDir?: string): void; /** * Asserts that there's only one directory matching a pattern (e.g., single components folder) * @param pattern - Directory name or glob pattern * @param options - Optional glob options * @throws Error if multiple directories found */ export declare function assertSingleDirectory(pattern: string, options?: GlobOptions): string; /** * Asserts that a module exports specific named exports * @param modulePath - Path to the module * @param expectedExports - Array of expected export names * @throws Error if exports don't match */ export declare function assertModuleExports(modulePath: string, expectedExports: string[]): void; /** * Creates a validator function that checks multiple conditions * @param validators - Array of validation functions * @returns A combined validation function */ export declare function combineValidators(...validators: Array<() => void | Promise>): () => Promise; //# sourceMappingURL=helpers.d.ts.map