How to use the @vuepress/shared-utils.logger.developer 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 / build.js View on Github external
const pagePaths = []
  for (const page of ctx.pages) {
    pagePaths.push(await renderPage(page))
  }

  readline.clearLine(process.stdout, 0)
  readline.cursorTo(process.stdout, 0)

  await ctx.pluginAPI.options.generated.apply(pagePaths)

  // DONE.
  const relativeDir = path.relative(cwd, outDir)
  logger.success(`Generated static files in ${chalk.cyan(relativeDir)}.`)
  const { duration } = performance.stop()
  logger.developer(`It took a total of ${chalk.cyan(`${duration}ms`)} to run the ${chalk.cyan('vuepress build')}.`)
  console.log()

  // --- helpers ---

  function compile (config) {
    return new Promise((resolve, reject) => {
      webpack(config, (err, stats) => {
        if (err) {
          return reject(err)
        }
        if (stats.hasErrors()) {
          stats.toJson().errors.forEach(err => {
            console.error(err)
          })
          reject(new Error(`Failed to compile with errors.`))
          return
github vuejs / vuepress / packages / @vuepress / core / lib / node / build / index.js View on Github external
const pagePaths = []
    for (const page of this.context.pages) {
      pagePaths.push(await this.renderPage(page))
    }

    readline.clearLine(process.stdout, 0)
    readline.cursorTo(process.stdout, 0)

    await this.context.pluginAPI.applyAsyncOption('generated', pagePaths)

    // DONE.
    const relativeDir = path.relative(this.context.cwd, this.outDir)
    logger.success(`Generated static files in ${chalk.cyan(relativeDir)}.`)
    const { duration } = performance.stop()
    logger.developer(`It took a total of ${chalk.cyan(`${duration}ms`)} to run the ${chalk.cyan('vuepress build')}.`)
    console.log()
  }
github vuejs / vuepress / packages / @vuepress / core / lib / node / Page.js View on Github external
async process ({
    computed,
    markdown,
    enhancers = [],
    preRender = {}
  }) {
    if (this._filePath) {
      logger.developer(`static_route`, chalk.cyan(this.path))
      this._content = await fs.readFile(this._filePath, 'utf-8')
    } else if (this._content) {
      logger.developer(`static_route`, chalk.cyan(this.path))
      this._filePath = await this._context.writeTemp(`temp-pages/${this.key}.md`, this._content)
    } else {
      logger.developer(`dynamic_route`, chalk.cyan(this.path))
    }

    if (this._content) {
      if (this._filePath.endsWith('.md')) {
        const { excerpt, data, content } = parseFrontmatter(this._content)
        this._strippedContent = content
        Object.assign(this.frontmatter, data)

        // infer title
        const title = inferTitle(this.frontmatter, this._strippedContent)
        if (title) {
          this.title = title
        }

        // extract headers
        const headers = extractHeaders(
github vuejs / vuepress / packages / @vuepress / core / lib / plugin-api / override / EnhanceAppFilesOption.js View on Github external
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(
            chalk.gray(`[${pluginName}] `) +
            `${chalk.cyan(enhanceAppFile)} Not Found.`
          )
        }
      }

      if (destPath) {
        manifest.push(destPath)
      }
    }

    // 2. write entry file.
    await ctx.writeTemp('internal/app-enhancers.js', pathsToModuleCode(manifest))
  }
}
github vuejs / vuepress / packages / vuepress / lib / handleUnknownCommand.js View on Github external
cli.on('command:*', async () => {
    const { args, options: commandoptions } = cli

    logger.debug('global_options', options)
    logger.debug('cli_options', commandoptions)
    logger.debug('cli_args', args)

    const [commandName] = args
    const sourceDir = args[1] ? path.resolve(args[1]) : pwd
    const inferredUserDocsDirectory = await inferUserDocsDirectory(pwd)
    logger.developer('inferredUserDocsDirectory', inferredUserDocsDirectory)
    logger.developer('sourceDir', sourceDir)

    if (inferredUserDocsDirectory && sourceDir !== inferredUserDocsDirectory) {
      logUnknownCommand(cli)
      console.log()
      logger.tip(`Did you miss to specify the target docs dir? e.g. ${chalk.cyan(`vuepress ${commandName} [targetDir]`)}.`)
      logger.tip(`A custom command registered by a plugin requires VuePress to locate your site configuration like ${chalk.cyan('vuepress dev')} or ${chalk.cyan('vuepress build')}.`)
      console.log()
      process.exit(1)
    }

    if (!inferredUserDocsDirectory) {
      logUnknownCommand(cli)
      process.exit(1)
    }

    logger.debug('Custom command', chalk.cyan(commandName))
github vuejs / vuepress / packages / vuepress / lib / handleUnknownCommand.js View on Github external
cli.on('command:*', async () => {
    const { args, options: commandoptions } = cli

    logger.debug('global_options', options)
    logger.debug('cli_options', commandoptions)
    logger.debug('cli_args', args)

    const [commandName] = args
    const sourceDir = args[1] ? path.resolve(args[1]) : pwd
    const inferredUserDocsDirectory = await inferUserDocsDirectory(pwd)
    logger.developer('inferredUserDocsDirectory', inferredUserDocsDirectory)
    logger.developer('sourceDir', sourceDir)

    if (inferredUserDocsDirectory && sourceDir !== inferredUserDocsDirectory) {
      logUnknownCommand(cli)
      console.log()
      logger.tip(`Did you miss to specify the target docs dir? e.g. ${chalk.cyan(`vuepress ${commandName} [targetDir]`)}.`)
      logger.tip(`A custom command registered by a plugin requires VuePress to locate your site configuration like ${chalk.cyan('vuepress dev')} or ${chalk.cyan('vuepress build')}.`)
      console.log()
      process.exit(1)
    }

    if (!inferredUserDocsDirectory) {
      logUnknownCommand(cli)
      process.exit(1)
    }
github vuejs / vuepress / packages / @vuepress / core / lib / node / webpack / DevLogPlugin.js View on Github external
const displayUrl = `http://${displayHost}:${port}${publicPath}`

      logger.success(
        `${chalk.gray(`[${time}]`)} Build ${chalk.italic(stats.hash.slice(0, 6))} `
        + `finished in ${stats.endTime - stats.startTime} ms! `
        + (
          isFirst
            ? ''
            : `${chalk.gray(`(${displayUrl})`)}`
        )
      )
      if (isFirst) {
        isFirst = false
        console.log(`${chalk.gray('>')} VuePress dev server listening at ${chalk.cyan(displayUrl)}`)
        const { duration } = performance.stop()
        logger.developer(`It took a total of ${chalk.cyan(`${duration}ms`)} to run the ${chalk.cyan('vuepress dev')} for the first time.`)
      }
    })
    if (shouldClearScreen) {
github vuejs / vuepress / packages / vuepress / lib / handleUnknownCommand.js View on Github external
module.exports = async function (cli, options) {
  registerUnknownCommands(cli, options)

  const argv = process.argv.slice(2)
  const inferredUserDocsDirectory = await inferUserDocsDirectory(pwd)
  logger.developer('inferredUserDocsDirectory', inferredUserDocsDirectory)

  const needPrepareBeforeLaunchCLI = inferredUserDocsDirectory
    && (isHelpFlag(argv[0]) || isUnknownCommandHelp(argv))

  logger.developer('needPrepareBeforeLaunchCLI', needPrepareBeforeLaunchCLI)

  if (needPrepareBeforeLaunchCLI) {
    let app
    let [, sourceDir] = argv

    if (!sourceDir || sourceDir.startsWith('-')) {
      sourceDir = inferredUserDocsDirectory
    } else {
      sourceDir = pwd
    }

    logger.setOptions({ logLevel: 1 })

    if (sourceDir) {
      app = createApp({ sourceDir, ...options })
      await app.process()