UNPKG

@boost/core

Version:

Robust pipeline for creating dev tools that separate logic into routines and tasks.

84 lines 3.31 kB
import { Arguments } from 'yargs-parser'; import { Debugger } from '@boost/debug'; import Tool, { ToolConfig } from './Tool'; import { PackageConfig } from './types'; export interface ConfigLike { extends?: ToolConfig['extends']; [key: string]: unknown; } export declare type ConfigPathOrObject = string | ConfigLike; export interface ParseOptions { errorOnFunction?: boolean; } export default class ConfigLoader { debug: Debugger; package: PackageConfig; parsedFiles: Set<string>; tool: Tool<any>; workspaceRoot: string; constructor(tool: Tool<any>); /** * Find the config using the --config file path option. */ findConfigFromArg(filePath?: string): ConfigPathOrObject | null; /** * Find the config in the package.json block under the application name. */ findConfigInPackageJSON(pkg: PackageConfig): ConfigPathOrObject | null; /** * Find the config using local files commonly located in a configs/ folder. */ findConfigInLocalFiles(root: string): ConfigPathOrObject | null; /** * Find the config within the root when in a workspace. */ findConfigInWorkspaceRoot(root: string): ConfigPathOrObject | null; /** * Return the config name used for file names and the package.json property. */ getConfigName(): string; /** * Inherit configuration settings from defined CLI options. */ inheritFromArgs<T>(config: T, args: Arguments): T; /** * Load a local configuration file relative to the current working directory, * or from within a package.json property of the same appName. * * Support both JSON and JS file formats by globbing the config directory. */ loadConfig<T>(args: Arguments): T; /** * Load the "package.json" from the current working directory, * as we require the dev tool to be ran from the project root. */ loadPackageJSON(): PackageConfig; /** * If an `extends` option exists, recursively merge the current configuration * with the preset configurations defined within `extends`, * and return the new configuration object. */ parseAndExtend(fileOrConfig: ConfigPathOrObject): ConfigLike; /** * Parse a configuration file at the defined file system path. * If the file ends in "json" or "json5", parse it with JSON5. * If the file ends in "js", import the file and use the default object. * Otherwise throw an error. */ parseFile<T>(filePath: string, args?: any[], options?: ParseOptions): T; /** * Resolve file system paths for the `extends` configuration value * using the following guidelines: * * - Absolute paths should be normalized and used as is. * - Relative paths should be resolved relative to the CWD. * - Strings that match a node module name should resolve to a config file relative to the CWD. * - Strings that start with "<plugin>:" should adhere to the previous rule. */ resolveExtendPaths(extendPaths: string[], baseDir?: string): string[]; /** * Resolve a Node/NPM module path to an app config file. */ resolveModuleConfigPath(configName: string, moduleName: string, preset?: boolean, ext?: string): string; } //# sourceMappingURL=ConfigLoader.d.ts.map