<commit_before>/* eslint-disable import/no-dynamic-require, react/no-danger */

import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { renderToString, renderToStaticMarkup } from 'react-dom/server'
import fs from 'fs-extra'
import glob from 'glob'
import path from 'path'
import Helmet from 'react-helmet'
import shorthash from 'shorthash'
import { ReportChunks } from 'react-universal-component'
import Progress from 'progress'
import chalk from 'chalk'
import flushChunks from 'webpack-flush-chunks'

import { makeHtmlWithMeta } from './components/HtmlWithMeta'
import { makeHeadWithMeta } from './components/HeadWithMeta'
import { makeBodyWithMeta } from './components/BodyWithMeta'

import generateRoutes from './generateRoutes'
import { DefaultDocument } from './RootComponents'
import buildXMLandRSS from './buildXML'
import { poolAll } from '../utils/shared'
import Redirect from '../client/components/Redirect'

export { buildXMLandRSS }

const defaultOutputFileRate = 100

const Bar = (len, label) =>
  new Progress(`=> ${label ? `${label} ` : ''}[:bar] :current/:total :percent :rate/s :etas `, {
    total: len,
  })

export const prepareRoutes = async (config, opts) => {
  console.log('getRoutes')
  config.routes = await config.getRoutes(opts)
  console.log('getRoutes finish')
  const progress = Bar(config.routes.length)

  process.env.REACT_STATIC_ROUTES_PATH = path.join(config.paths.DIST, 'react-static-routes.js')

  // Dedupe all templates into an array
  const templates = []

  config.routes.forEach(route => {
    if (!route.component) {
      return
    }
    // Check if the template has already been added
    const index = templates.indexOf(route.component)
    if (index === -1) {
      // If it's new, add it
      templates.push(route.component)
      // Assign the templateID
      route.templateID = templates.length - 1
    } else {
      // Assign the existing templateID
      route.templateID = index
    }
    progress.tick()
  })<commit_msg>Update prepareRoutes: remove progress from sync op<commit_after>/* eslint-disable import/no-dynamic-require, react/no-danger */

import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { renderToString, renderToStaticMarkup } from 'react-dom/server'
import fs from 'fs-extra'
import glob from 'glob'
import path from 'path'
import Helmet from 'react-helmet'
import shorthash from 'shorthash'
import { ReportChunks } from 'react-universal-component'
import Progress from 'progress'
import chalk from 'chalk'
import flushChunks from 'webpack-flush-chunks'

import { makeHtmlWithMeta } from './components/HtmlWithMeta'
import { makeHeadWithMeta } from './components/HeadWithMeta'
import { makeBodyWithMeta } from './components/BodyWithMeta'

import generateRoutes from './generateRoutes'
import { DefaultDocument } from './RootComponents'
import buildXMLandRSS from './buildXML'
import { poolAll } from '../utils/shared'
import Redirect from '../client/components/Redirect'

export { buildXMLandRSS }

const defaultOutputFileRate = 100

const Bar = (len, label) =>
  new Progress(`=> ${label ? `${label} ` : ''}[:bar] :current/:total :percent :rate/s :etas `, {
    total: len,
  })

export const prepareRoutes = async (config, opts) => {
  config.routes = await config.getRoutes(opts)

  process.env.REACT_STATIC_ROUTES_PATH = path.join(config.paths.DIST, 'react-static-routes.js')

  // Dedupe all templates into an array
  const templates = []

  config.routes.forEach(route => {
    if (!route.component) {
      return
    }
    // Check if the template has already been added
    const index = templates.indexOf(route.component)
    if (index === -1) {
      // If it's new, add it
      templates.push(route.component)
      // Assign the templateID
      route.templateID = templates.length - 1
    } else {
      // Assign the existing templateID
      route.templateID = index
    }
  })
{'fraction_non_alphanumeric': 0.12032561689137625, 'fraction_numerical': 0.0025438819638768763, 'mean_word_length': 3.8423645320197046, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6301959', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1162, 'n_words': 339}