UNPKG

@mintlify/prebuild

Version:

Helpful functions for Mintlify's prebuild step

34 lines (33 loc) 1.27 kB
import { processMintIgnoreString } from '@mintlify/common'; import fse from 'fs-extra'; import pathUtil from 'path'; export const getFileExtension = (filename) => { const parsed = pathUtil.parse(filename); return parsed.ext ? parsed.ext.slice(1) : filename; }; export const getConfigPath = async (contentDirectoryPath, type) => { const path = pathUtil.join(contentDirectoryPath, `${type}.json`); if (!(await fse.pathExists(path))) return null; return path; }; export const getMintIgnorePath = async (contentDirectoryPath) => { const path = pathUtil.join(contentDirectoryPath, '.mintignore'); if (!(await fse.pathExists(path))) return null; return path; }; export const getMintIgnore = async (contentDirectoryPath) => { const path = await getMintIgnorePath(contentDirectoryPath); if (!path) return []; const content = await fse.readFile(path, 'utf-8'); return processMintIgnoreString(content); }; export const getConfigObj = async (contentDirectoryPath, type) => { const configPath = await getConfigPath(contentDirectoryPath, type); if (!configPath) return null; const configContents = await fse.readFile(configPath); return await JSON.parse(configContents.toString()); };