UNPKG

@omlet/cli

Version:

Omlet (https://omlet.dev) is a component analytics tool that uses a CLI to scan your codebase to detect components and their usage. Get real usage insights from customizable charts to measure adoption across all projects and identify opportunities to impr

106 lines (105 loc) 3.68 kB
import { type Component as ComponentData, type AnalyzeResult } from "../analyzer"; import { CliError } from "../error"; declare type MetadataValue = number | string | boolean | Date; declare type Metadata = Record<string, MetadataValue>; export interface Component { /** * Unique identifier for the component. */ id: string; /** * Name of the component as exported in the source code. */ name: string; /** * Creation date of the component, extracted from the git history. Optional. */ createdAt?: Readonly<Date>; /** * Last updated date of the component, extracted from the git history. Optional. */ updatedAt?: Readonly<Date>; /** * Package name the component belongs to. */ packageName: string; /** * File path to the component within the repository. */ filePath: string; /** * List of props of the component, including name and optional default value. */ props: readonly { name: string; defaultValue?: string; }[]; /** * List of HTML elements used within the component. */ htmlElementsUsed: readonly string[]; /** * Child components of this component. Includes only the component detected in the scan. */ children: readonly Component[]; /** * Parent components of this component. Includes only the component detected in the scan. */ parents: readonly Component[]; /** * Sets metadata for the component. * @param name The name of the metadata field. * @param value The value of the metadata field. */ setMetadata: (name: string, value: MetadataValue) => void; } export interface CliHookModule { /** * The hook function that is called after a scan operation is completed. * This hook can be used to perform additional processing on the components * found during the scan. * The function can be synchronous or return a Promise for asynchronous operations. * * @param components The list of components found during the scan. */ afterScan: (components: readonly Component[]) => void | Promise<void>; } export declare class HookComponent implements Component { private context; private component; private _props; private _htmlElements; private _children; constructor(context: HookContext, component: ComponentData); get name(): string; get id(): string; get createdAt(): Readonly<Date> | undefined; get updatedAt(): Readonly<Date> | undefined; get packageName(): string; get filePath(): string; get props(): Readonly<ComponentData["props"]>; get htmlElementsUsed(): readonly string[]; get children(): readonly Component[]; get parents(): readonly Component[]; get metadata(): Readonly<Metadata> | null; setMetadata(name: string, value: MetadataValue): void; } export declare class HookContext { private hookModule; private componentMap; private reverseDependencyMap; private componentMetadata; components: HookComponent[]; constructor(analysisData: AnalyzeResult, hookModule: CliHookModule); getComponent(id: string): HookComponent | null; findParentComponents(id: string): HookComponent[]; setComponentMetadata(id: string, name: string, value: MetadataValue): void; getComponentMetadata(id: string): Metadata | null; afterScan(): Promise<void>; } export declare class CliHookError extends CliError { readonly reason?: Error; constructor(message: string, reason?: Error); } export declare function init(hookScriptPath: string, analysisData: AnalyzeResult): Promise<HookContext>; export {};