UNPKG

@better-builds/lets-version

Version:

A package that reads your conventional commits and git history and recommends (or applies) a SemVer version bump for you

46 lines (45 loc) 1.41 kB
import fs from 'fs-extra'; import path from 'path'; /** * Utility function that returns an array of all paths * in the CWD up to the root */ function getAllFoldersUpToRoot(cwd) { const out = []; let buffer = ''; for (const char of cwd) { if (char === path.sep) out.push(buffer.length ? buffer : path.sep); buffer += char; } out.push(buffer); return out.sort((a, b) => b.localeCompare(a)); } /** * Attempts to read the nearest turboTools.config.js file (if it exists) * and returns its contents */ export async function readLetsVersionConfig(cwd) { const getLetsVersionConfigFilePath = (prefix) => { if (prefix.endsWith(path.sep)) return `${prefix}letsVersion.config.mjs`; return `${prefix}${path.sep}letsVersion.config.mjs`; }; for (const dir of getAllFoldersUpToRoot(cwd)) { const configPath = getLetsVersionConfigFilePath(dir); const isFile = fs.statSync(configPath, { throwIfNoEntry: false })?.isFile() || false; if (isFile) { const result = await import(configPath); return result.default; } } return null; } /** * Simple pass-through utility for providing TypeScript typings * in non-TS environments when defining a config override */ export function defineLetsVersionConfig(config) { return config; } export { getAllFoldersUpToRoot };