UNPKG

bump-cli

Version:

The Bump CLI is used to interact with your API documentation hosted on Bump.sh by using the API of developers.bump.sh

53 lines (52 loc) 1.48 kB
import { CLIError } from '@oclif/core/errors'; import { readdirSync, statSync } from 'node:fs'; import { basename, extname } from 'node:path'; export const isDir = (path_or_url) => { if (isHttpUrl(path_or_url)) { return false; } try { return statSync(path_or_url).isDirectory(); } catch (error) { if (error instanceof Error) { throw new CLIError(error); } return false; } }; const isHttpUrl = (path) => { try { const url = new URL(path); return ['http:', 'https:'].includes(url.protocol); } catch { return false; } }; export class File { static supportedFormats = ['.yml', '.yaml', '.json']; static listInvalidConventionFiles(path, regex) { return File.listValidFormatFiles(path).filter(({ filename }) => { return !regex.test(filename); }); } static listValidConventionFiles(path, regex) { return File.listValidFormatFiles(path).filter(({ filename }) => { return regex.test(filename); }); } static listValidFormatFiles(path) { return readdirSync(path) .filter((file) => { return File.supportedFormats.includes(extname(file)); }) .map((file) => { return { filename: basename(file, extname(file)), label: basename(file), value: file, }; }); } }