Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

767 B
Raw Blame
import {
  constants,
  readFile,
  access,
  mkdir,
} from 'node:fs/promises';

export type PackageJson = {
  name: string;
  version: string;
  keywords: string[];
};

export const checkIfFileExists = async (filePath: string) => {
  try {
    await access(filePath, constants.F_OK);
    return true;
  } catch (e) {
    return false;
  }
};

const readJsonFile = async <T>(path: string): Promise<T> => {
  const jsonFile = await readFile(path, { encoding: 'utf-8' });
  return JSON.parse(jsonFile) as T;
};

export const readPackageJson = async (path: string): Promise<PackageJson> => {
  return await readJsonFile(`${path}/package.json`);
};

export const makeFolderRecursive = async (path: string): Promise<void> => {
  await mkdir(path, { recursive: true });
};