How to use the @vuepress/shared-utils.fs.existsSync function in @vuepress/shared-utils

To help you get started, we’ve selected a few @vuepress/shared-utils 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 vuejs / vuepress / packages / @vuepress / core / lib / plugin-api / override / EnhanceAppFilesOption.js View on Github external
let destPath

      // 1.1 dynamic code
      if (isPlainObject(enhanceAppFile)) {
        const { content } = enhanceAppFile
        let { name } = enhanceAppFile
        name = name.replace(/.js$/, '')

        if (hasDefaultExport(content)) {
          destPath = await writeEnhancer(name, content)
        } else {
          destPath = await writeEnhancer(name, content, false /* do not contain default export*/)
        }
        // 1.2 pointing to a file
      } else {
        if (fs.existsSync(enhanceAppFile)) {
          const content = await fs.readFile(enhanceAppFile, 'utf-8')

          if (hasDefaultExport(content)) {
            destPath = await writeEnhancer(
              moduleId++,
              `export { default } from ${JSON.stringify(enhanceAppFile)}`
            )
          } else {
            destPath = await writeEnhancer(
              moduleId++,
              `import ${JSON.stringify(enhanceAppFile)}`,
              false /* do not contain default export*/
            )
          }
        } else {
          logger.developer(
github vuejs / vuepress / packages / @vuepress / core / lib / prepare / resolveOptions.js View on Github external
let themeLayoutPath = null
  let themeNotFoundPath = null
  let themeIndexFile = null
  let themePlugins = []

  if (useLocalTheme) {
    logger.tip(`\nApply theme located at ${localThemePath}...`)

    // use local custom theme
    themePath = localThemePath
    themeLayoutPath = path.resolve(localThemePath, 'Layout.vue')
    themeNotFoundPath = path.resolve(localThemePath, 'NotFound.vue')
    if (!fs.existsSync(themeLayoutPath)) {
      throw new Error(`[vuepress] Cannot resolve Layout.vue file in .vuepress/theme.`)
    }
    if (!fs.existsSync(themeNotFoundPath)) {
      throw new Error(`[vuepress] Cannot resolve NotFound.vue file in .vuepress/theme.`)
    }
  } else if (theme) {
    // use external theme
    try {
      // backward-compatible 0.x.x.
      themeLayoutPath = requireResolve(`vuepress-theme-${theme}/Layout.vue`)
      themePath = path.dirname(themeLayoutPath)
      themeNotFoundPath = path.resolve(themeLayoutPath, 'NotFound.vue')
    } catch (e) {
      try {
        themeIndexFile = requireResolve(`vuepress-theme-${theme}/index.js`)
      } catch (e) {
        try {
          themeIndexFile = requireResolve(`@vuepress/theme-${theme}`)
          themePath = path.dirname(themeIndexFile)
github vuejs / vuepress / packages / @vuepress / core / lib / node / loadConfig.js View on Github external
module.exports = function loadConfig (vuepressDir, bustCache = true) {
  const configPath = path.resolve(vuepressDir, 'config.js')
  const configYmlPath = path.resolve(vuepressDir, 'config.yml')
  const configTomlPath = path.resolve(vuepressDir, 'config.toml')

  if (bustCache) {
    delete require.cache[configPath]
  }

  // resolve siteConfig
  let siteConfig = {}
  if (fs.existsSync(configYmlPath)) {
    siteConfig = parseConfig(configYmlPath)
  } else if (fs.existsSync(configTomlPath)) {
    siteConfig = parseConfig(configTomlPath)
  } else if (fs.existsSync(configPath)) {
    siteConfig = require(configPath)
  }

  return siteConfig
}
github vuejs / vuepress / packages / @vuepress / core / lib / node / loadConfig.js View on Github external
module.exports = function loadConfig (vuepressDir, bustCache = true) {
  const configPath = path.resolve(vuepressDir, 'config.js')
  const configYmlPath = path.resolve(vuepressDir, 'config.yml')
  const configTomlPath = path.resolve(vuepressDir, 'config.toml')

  if (bustCache) {
    delete require.cache[configPath]
  }

  // resolve siteConfig
  let siteConfig = {}
  if (fs.existsSync(configYmlPath)) {
    siteConfig = parseConfig(configYmlPath)
  } else if (fs.existsSync(configTomlPath)) {
    siteConfig = parseConfig(configTomlPath)
  } else if (fs.existsSync(configPath)) {
    siteConfig = require(configPath)
  }

  return siteConfig
}
github vuejs / vuepress / packages / @vuepress / core / lib / prepare / resolveOptions.js View on Github external
const theme = siteConfig.theme || cliOptions.theme

  let themePath = null
  let themeLayoutPath = null
  let themeNotFoundPath = null
  let themeIndexFile = null
  let themePlugins = []

  if (useLocalTheme) {
    logger.tip(`\nApply theme located at ${localThemePath}...`)

    // use local custom theme
    themePath = localThemePath
    themeLayoutPath = path.resolve(localThemePath, 'Layout.vue')
    themeNotFoundPath = path.resolve(localThemePath, 'NotFound.vue')
    if (!fs.existsSync(themeLayoutPath)) {
      throw new Error(`[vuepress] Cannot resolve Layout.vue file in .vuepress/theme.`)
    }
    if (!fs.existsSync(themeNotFoundPath)) {
      throw new Error(`[vuepress] Cannot resolve NotFound.vue file in .vuepress/theme.`)
    }
  } else if (theme) {
    // use external theme
    try {
      // backward-compatible 0.x.x.
      themeLayoutPath = requireResolve(`vuepress-theme-${theme}/Layout.vue`)
      themePath = path.dirname(themeLayoutPath)
      themeNotFoundPath = path.resolve(themeLayoutPath, 'NotFound.vue')
    } catch (e) {
      try {
        themeIndexFile = requireResolve(`vuepress-theme-${theme}/index.js`)
      } catch (e) {
github vuejs / vuepress / packages / @vuepress / core / lib / node / loadTheme.js View on Github external
const { siteConfig, options, sourceDir, vuepressDir, pluginAPI } = ctx
  const localThemePath = resolve(vuepressDir, 'theme')
  theme = theme || siteConfig.theme || options.theme

  let path
  let name
  let shortcut
  let entry = {}

  /**
   * 1. From `.vuepress/theme` directory.
   */
  if (
    !ignoreLocal
    && !fs.existsSync(theme)
    && fs.existsSync(localThemePath)
    && fs.readdirSync(localThemePath).length > 0
  ) {
    path = localThemePath
    name = shortcut = 'local'
    logger.tip(`Apply local theme at ${chalk.gray(path)}...`)

    /**
     * 2. From deps or custom local path.
     *    - vuepress-plugin-foo
     *    - /path/to/a-theme/index.js
     */
  } else if (isString(theme)) {
    /**
     * To let theme resolver get the correct theme name.
     */
    if (theme.endsWith('/index.js')) {
github vuejs / vuepress / packages / @vuepress / markdown-loader / index.js View on Github external
.replace(/#.*$/, '')
      .replace(/\.html$/, '.md')

    const filename = shortname
      .replace(/\/$/, '/README.md')
      .replace(/^\//, sourceDir + '/')

    const altname = shortname
      .replace(/\/$/, '/index.md')
      .replace(/^\//, sourceDir + '/')

    const dir = path.dirname(this.resourcePath)
    const file = path.resolve(dir, filename)
    const altfile = altname !== filename ? path.resolve(dir, altname) : null

    if (!fs.existsSync(file) && (!altfile || !fs.existsSync(altfile))) {
      this.emitWarning(
        new Error(
          `\nFile for relative link "${link}" does not exist.\n`
          + `(Resolved file: ${file})\n`
        )
      )
    }
  })
github vuejs / vuepress / packages / @vuepress / core / lib / node / App.js View on Github external
resolveThemeAgreementFile (filepath) {
    const current = path.resolve(this.themeAPI.theme.path, filepath)
    if (fs.existsSync(current)) {
      return current
    }
    if (this.themeAPI.existsParentTheme) {
      const parent = path.resolve(this.themeAPI.parentTheme.path, filepath)
      if (fs.existsSync(parent)) {
        return parent
      }
    }
  }
github vuejs / vuepress / packages / @vuepress / core / lib / dev.js View on Github external
before (app, server) {
      if (fs.existsSync(contentBase)) {
        app.use(ctx.base, require('express').static(contentBase))
      }

      ctx.pluginAPI.options.beforeDevServer.syncApply(app, server)
    },
    after (app, server) {
github vuejs / vuepress / packages / @vuepress / core / lib / node / internal-plugins / style / index.js View on Github external
const themeStyle = path.resolve(themeAPI.theme.path, 'styles/index.styl')
    const userStyle = path.resolve(sourceDir, '.vuepress/styles/index.styl')

    const themeStyleContent = fs.existsSync(themeStyle)
      ? `@import(${JSON.stringify(themeStyle.replace(/[\\]+/g, '/'))})`
      : ''

    const userStyleContent = fs.existsSync(userStyle)
      ? `@import(${JSON.stringify(userStyle.replace(/[\\]+/g, '/'))})`
      : ''

    let styleContent = themeStyleContent + userStyleContent

    if (themeAPI.existsParentTheme) {
      const parentThemeStyle = path.resolve(themeAPI.parentTheme.path, 'styles/index.styl')
      const parentThemeStyleContent = fs.existsSync(parentThemeStyle)
        ? `@import(${JSON.stringify(parentThemeStyle.replace(/[\\]+/g, '/'))})`
        : ''
      styleContent = parentThemeStyleContent + styleContent
    }

    await writeTemp('style.styl', styleContent)
  }
})