import { Path } from "path-class"; import { processFile, type RuntimeOptions } from "./processFile.ts"; import { type RepoConfig, repoConfigSchema } from "./RepoConfig.ts"; const { cwd } = Path; function checkForDupes(repoConfig: RepoConfig) { const resolvedPaths = Object.keys(repoConfig).map( (unresolvedPath) => Path.resolve(unresolvedPath, cwd).path, ); if (new Set(resolvedPaths).size !== resolvedPaths.length) { throw new Error( "[readme-cli-help] Multiple paths in the config resolve to the same path.", ); } } type RuntimeOptionsWithoutCwd = Omit; export async function processConfig( config: RepoConfig, runtimeOptions: RuntimeOptionsWithoutCwd, ) { // Run a duplicate path check before we (potentially) perform any modifications on files. checkForDupes(config); for (const [unresolvedPathString, pathConfig] of Object.entries( config.files, )) { await processFile(unresolvedPathString, pathConfig, { cwd, ...runtimeOptions, }); } } export async function processConfigFromPath( path: Path, runtimeOptions: RuntimeOptionsWithoutCwd, ) { const config: RepoConfig = await path.readJSON({ schema: repoConfigSchema }); await processConfig(config, runtimeOptions); return; }