UNPKG

mdat

Version:

CLI tool and TypeScript library implementing the Markdown Autophagic Template (MDAT) system. MDAT lets you use comments as dynamic content templates in Markdown files, making it easy to generate and update readme boilerplate.

70 lines (69 loc) 2.91 kB
import { type NormalizedPackageJson } from 'read-pkg'; import { type Options, type Rules } from 'remark-mdat'; import { type Simplify } from 'type-fest'; export type Config = Simplify<Options & { assetsPath?: string; packageFile?: string; }>; export type ConfigLoaded = { addMetaComment: boolean; assetsPath: string; closingPrefix: string; keywordPrefix: string; metaCommentIdentifier: string; packageFile: string | undefined; rules: Rules; }; /** * Generously accept either string paths to .ts, .js, or .json files with * `Config` type default exports. Takes a single value, or an array of values which * will be merged right to left. */ export type ConfigToLoad = Array<Config | string> | Config | string; /** * Generously accept either string paths to .ts, .js, or .json files with * `Rules` type default exports. */ export type RulesToLoad = Array<Rules | string> | Rules | string; /** * Load and validate mdat configuration / rule sets * Uses cosmiconfig to search in the usual places. * Merge precedence: Additional Config Paths < Search Path < mdat-remark defaults * * Generic to accommodate additional Config options, so set T to your custom config type if needed. You must provide a matching configExtensionSchema as well. */ export declare function loadConfig(options?: { /** * Additional Config objects to merge. * * Strings are treated as paths to `ts`, `js`, or `json` files with `Config` type default exports. These will be dynamically loaded by Cosmiconfig. * Accepts an individual item, or an array. Objects in the array will be merged right to left. * */ additionalConfig?: ConfigToLoad; /** * Additional Rules objects to merge. * * Strings are treated as paths to `ts`, `js`, or `json` files with `Rules` type default exports. These will be dynamically loaded by Cosmiconfig. * Accepts an individual item, or an array. Objects in the array will be merged right to left, and take precedence over any rules in previously loaded Config objects as well. */ additionalRules?: RulesToLoad; /** Search for config in specific directories, mainly useful for testing. Cosmiconfig default search paths used if unset. */ searchFrom?: string; }): Promise<ConfigLoaded>; /** * Get the current MDAT config object, loading it if necessary */ export declare function getConfig(): Promise<ConfigLoaded>; /** * Convenience function for rules * Load as package json only as needed, memoize * Rules could call this themselves, but this is more convenient and efficient * @throws If no package.json is found */ export declare function getPackageJson(): Promise<NormalizedPackageJson>; /** * Convenience function for merging configs * Performs a deep merge, with the rightmost object taking precedence */ export declare function mergeConfigs(a: Config, b: Config): Config;