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