UNPKG

polen

Version:

A framework for delightful GraphQL developer portals

110 lines 3.18 kB
/** * Special key added to path objects to reference the directory itself */ export declare const DIR_KEY: "$"; /** * Input type for path maps - plain nested objects with string values */ export interface PathInput { [key: string]: string | PathInput; } /** * Processed paths with $ properties added to directories */ export type ProcessedPaths<T> = { [K in keyof T]: T[K] extends string ? string : ProcessedPaths<T[K]> & { [DIR_KEY]: string; }; } & (T extends PathInput ? { [DIR_KEY]: string; } : {}); /** * Path map containing only relative paths */ export type RelativePathMap<T extends PathInput = PathInput> = ProcessedPaths<T>; /** * Path map containing paths rooted at the PathMap's origin */ export type RootedPathMap<T extends PathInput = PathInput> = ProcessedPaths<T>; /** * Path map containing absolute paths */ export type AbsolutePathMap<T extends PathInput = PathInput> = ProcessedPaths<T>; /** * Combined path map with relative, rooted, and absolute variants */ export interface PathMap<T extends PathInput = PathInput> { /** * Paths relative to their parent directory * @example * paths.relative.template.server.app // 'app.ts' */ relative: RelativePathMap<T>; /** * Paths from the PathMap's root * @example * paths.rooted.template.server.app // 'template/server/app.ts' */ rooted: RootedPathMap<T>; /** * Absolute paths from the filesystem root * @example * paths.absolute.template.server.app // '/project/template/server/app.ts' */ absolute: AbsolutePathMap<T>; /** * The base path used for absolute paths */ base: string; } /** * Create a path map from nested path definitions * * @param paths - Nested object structure defining paths * @param base - Optional base path for absolute paths * @returns RelativePathMap if no base provided, PathMap if base provided * * @example * ```ts * // Without base - returns RelativePathMap * const paths = PathMap.create({ * src: { * lib: { * utils: 'utils.ts' * } * } * }) * * // With base - returns PathMap with all variants * const paths = PathMap.create({ * src: { * lib: { * utils: 'utils.ts' * } * } * }, '/project') * * paths.relative.src.lib.utils // 'utils.ts' * paths.rooted.src.lib.utils // 'src/lib/utils.ts' * paths.absolute.src.lib.utils // '/project/src/lib/utils.ts' * ``` */ export declare function create<T extends PathInput>(paths: T): RelativePathMap<T>; export declare function create<T extends PathInput>(paths: T, base: string): PathMap<T>; /** * Create a new PathMap with a different base path * * @param pathMap - Existing PathMap or RelativePathMap * @param base - New base path * @returns New PathMap with updated absolute paths * * @example * ```ts * const dev = PathMap.create(paths, '/dev') * const prod = PathMap.rebase(dev, '/prod') * * prod.absolute.src.lib.utils // '/prod/src/lib/utils.ts' * ``` */ export declare const rebase: <T extends PathInput>(pathMap: PathMap<T> | RelativePathMap<T>, base: string) => PathMap<T>; //# sourceMappingURL=path-map.d.ts.map