<commit_before>import * as fs from "fs-extra";
import { join } from "path";
import { createRouter } from "@curi/router";
import { createReusable } from "@hickory/in-memory";

import pathnames from "./pathnames";

import { LocationOptions } from "@hickory/in-memory";
import { Emitted } from "@curi/types";
import { StaticConfiguration, Result } from "./types";

export default async function staticFiles(
  config: StaticConfiguration
): Promise<Array<Result>> {
  const {
    pages,
    router: { routes, options: routerOptions = () => ({}) },
    output: { render, dir },
    history: historyOptions
  } = config;

  // generate input pathname/output filename pairs
  // for the provided pages
  const io = pathnames({
    routes,
    pages
  }).map(pathname => {
    return {
      pathname,
      outputPath: join(dir, pathname, "index.html")
    };
  });

  // if there is a catch all page to be generated,
  // add it to the input/output array
  if (config.fallback) {
    const { pathname, filename } = config.fallback;
    io.push({
      pathname,
      outputPath: join(dir, filename)
    });
  }

  const reusable = createReusable(historyOptions);

  return Promise.all<Result>(
    io.map(({ pathname, outputPath }) => {
      return new Promise(resolve => {
        try {
          // create a new router for each so we don't run into any issues
          // with overlapping requests

          const router = createRouter<LocationOptions>(reusable, routes, {
            ...routerOptions(),
            // need to emit redirects or will get stuck waiting forever
            invisibleRedirects: false,
            history: {
              location: pathname
            }
          });

          router.once(
            (emitted: Emitted) => {
              try {
                const { response } = emitted;
                const html = render(emitted);<commit_msg>Remove unused line<commit_after>import * as fs from "fs-extra";
import { join } from "path";
import { createRouter } from "@curi/router";
import { createReusable } from "@hickory/in-memory";

import pathnames from "./pathnames";

import { LocationOptions } from "@hickory/in-memory";
import { Emitted } from "@curi/types";
import { StaticConfiguration, Result } from "./types";

export default async function staticFiles(
  config: StaticConfiguration
): Promise<Array<Result>> {
  const {
    pages,
    router: { routes, options: routerOptions = () => ({}) },
    output: { render, dir },
    history: historyOptions
  } = config;

  // generate input pathname/output filename pairs
  // for the provided pages
  const io = pathnames({
    routes,
    pages
  }).map(pathname => {
    return {
      pathname,
      outputPath: join(dir, pathname, "index.html")
    };
  });

  // if there is a catch all page to be generated,
  // add it to the input/output array
  if (config.fallback) {
    const { pathname, filename } = config.fallback;
    io.push({
      pathname,
      outputPath: join(dir, filename)
    });
  }

  const reusable = createReusable(historyOptions);

  return Promise.all<Result>(
    io.map(({ pathname, outputPath }) => {
      return new Promise(resolve => {
        try {
          // create a new router for each so we don't run into any issues
          // with overlapping requests

          const router = createRouter<LocationOptions>(reusable, routes, {
            ...routerOptions(),
            // need to emit redirects or will get stuck waiting forever
            invisibleRedirects: false,
            history: {
              location: pathname
            }
          });

          router.once(
            (emitted: Emitted) => {
              try {
                const html = render(emitted);
{'fraction_non_alphanumeric': 0.11644754494231285, 'fraction_numerical': 0.0, 'mean_word_length': 2.349505840071878, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, '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': '3609888', 'n_tokens_mistral': 1038, 'n_tokens_neox': 1009, 'n_words': 318}