How to use fs-exists-sync - 3 common examples

To help you get started, we’ve selected a few fs-exists-sync examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hashicorp / boundary / website / components / temporary_docs-page / server.js View on Github external
export async function renderPageMdx(root, pagePath, components) {
  // get the page being requested - figure out if its index page or leaf
  // prefer leaf if both are present
  const leafPath = path.join(root, `${pagePath}.mdx`)
  const indexPath = path.join(root, `${pagePath}/index.mdx`)
  let page, filePath

  if (existsSync(leafPath)) {
    page = fs.readFileSync(leafPath, 'utf8')
    filePath = leafPath
  } else if (existsSync(indexPath)) {
    page = fs.readFileSync(indexPath, 'utf8')
    filePath = indexPath
  } else {
    // NOTE: if we decide to let docs pages render dynamically, we should replace this
    // error with a straight 404, at least in production.
    throw new Error(
      `We went looking for "${leafPath}" and "${indexPath}" but neither one was found.`
    )
  }

  const { data: frontMatter, content } = matter(page)
  const mdxSource = await renderToString(content, {
    mdxOptions: markdownDefaults({
github hashicorp / boundary / website / components / temporary_docs-page / server.js View on Github external
export async function renderPageMdx(root, pagePath, components) {
  // get the page being requested - figure out if its index page or leaf
  // prefer leaf if both are present
  const leafPath = path.join(root, `${pagePath}.mdx`)
  const indexPath = path.join(root, `${pagePath}/index.mdx`)
  let page, filePath

  if (existsSync(leafPath)) {
    page = fs.readFileSync(leafPath, 'utf8')
    filePath = leafPath
  } else if (existsSync(indexPath)) {
    page = fs.readFileSync(indexPath, 'utf8')
    filePath = indexPath
  } else {
    // NOTE: if we decide to let docs pages render dynamically, we should replace this
    // error with a straight 404, at least in production.
    throw new Error(
      `We went looking for "${leafPath}" and "${indexPath}" but neither one was found.`
    )
  }

  const { data: frontMatter, content } = matter(page)
  const mdxSource = await renderToString(content, {
    mdxOptions: markdownDefaults({
      resolveIncludes: path.join(process.cwd(), 'content/partials'),
    }),
    components,
github lbryio / lbry.tech / app / components / markdown.js View on Github external
function partialFinder(markdownBody) {
  const regexToFindPartials = /<\w+ ?\/>/g;
  const partials = markdownBody.match(regexToFindPartials);

  if (partials) {
    for (const partial of partials) {
      const filename = decamelize(partial, "-").replace("<", "")
        .replace("/>", "")
        .trim();
      const fileExistsTest = exists(`./app/components/${filename}.js`);

      if (!fileExistsTest)
        markdownBody = markdownBody.replace(partial, "");

      else {
        const partialFunction = require(path.join(__dirname, "..", `./components/${filename}.js`));

        if (filename === "glossary-toc") markdownBody = markdownBody.replace(partial, partialFunction.default);
        else markdownBody = markdownBody.replace(partial, `${partialFunction.default()}<div class="page__markup">`);
      }
    }
  }

  return ("<div class="\&quot;page__markup\&quot;">" + markdownBody + "</div>").replace(/<div class="page__markup">\s*&lt;\/div&gt;/, "");
}
</div></div>

fs-exists-sync

Drop-in replacement for `fs.existsSync` with zero dependencies. Other libs I found either have crucial differences from fs.existsSync, or unnecessary dependencies. See README.md for more info.

MIT
Latest version published 9 years ago

Package Health Score

65 / 100
Full package analysis

Popular fs-exists-sync functions