Skip to main content

fs

Library of helper functions for handling files and folders.

fsOutputAdapter​

const fsOutputAdapter: OutputAdapter;

Defined in: fs.ts:124

The default output destination: the local filesystem.

Used whenever no custom outputAdapter is configured, so the out-of-the-box behaviour is unchanged. Content arrives already prettified - prettifying is the renderer's job, not the destination's.

Example​

import { fsOutputAdapter } from "@graphql-markdown/utils/fs";

await fsOutputAdapter.writeFile("./docs/api/query.md", "# Query");

ensureDir()​

function ensureDir(location, options?): Promise<void>;

Defined in: fs.ts:61

Asynchronously create a folder structure if it does not exist.

Parameters​

location​

string

folder structure in path format.

options?​

EnsureDirOptions

Returns​

Promise<void>

Example​

import { ensureDir } from "@graphql-markdown/utils/fs";

await ensureDir("./.temp/local");

// Creates both folders if they do not exists.

fileExists()​

function fileExists(location): Promise<boolean>;

Defined in: fs.ts:36

Asynchronously check if a file or folder exists at the path location.

Parameters​

location​

string

file or folder location.

Returns​

Promise<boolean>

true if the path is valid, else false if not.

Example​

import { fileExists } from "@graphql-markdown/utils/fs";

await fileExists("./.temp/local");

// Expected true if path is valid, false if not

saveFile()​

function saveFile(location, content, prettify?): Promise<void>;

Defined in: fs.ts:98

Asynchronously save a file with a string content at specified location in local FS. Override the file content if the file already exists. The function calls ensureDir(dirname(location)) to create the folder structure if missing.

Parameters​

location​

string

file location.

content​

string

data to be written into the file (UTF-8 string).

prettify?​

PrettifyCallbackFunction

optional callback function for prettifying the content.

Returns​

Promise<void>

true if the path is valid, else false if not.

Example​

import { saveFile } from "@graphql-markdown/utils/fs";

await saveFile("./.temp/local.md", "foobar");

// Created .temp folder if it does not exists, and save data into local.md