@mintlify/prebuild
Version:
Helpful functions for Mintlify's prebuild step
37 lines (36 loc) • 1.43 kB
JavaScript
import { processMintIgnoreString } from '@mintlify/common';
import fse from 'fs-extra';
import pathUtil from 'path';
import { resolveFileRefs } from './prebuild/resolveRefs.js';
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);
const parsed = JSON.parse(configContents.toString());
const { resolved } = await resolveFileRefs(parsed, contentDirectoryPath);
return resolved;
};