<commit_before>import * as glob from 'glob';
import * as path from 'path';
import * as fs from 'fs';

import {getWorkingDirectory} from './utils';

const libName = require('../package.json').name;
const imageMatchRegex = /!\[(.*)\]\((?!http?).*\\*.(png|svg|jpg|jpeg)\)/g;
const imageRegexGroup = /!\[(?<alt>(.*))\]\((?<src>(?!http?).*\.(png|svg|jpg|jpeg))\)/;

export default async (filepath = process.cwd()): Promise<void> => {
  const workingDirectory = getWorkingDirectory(filepath);
  const outputFolder = path.join(workingDirectory, libName);
  const mdGlob = path.join(workingDirectory, '!(node_modules)', '**', '*.md');
  fs.mkdirSync(outputFolder);

  glob(mdGlob, {}, async (_, files) => {
    // Go through all the files that were found
    for (const file of files) {
      const markdown = fs.readFileSync(file, 'utf8');
      const images = markdown.match(imageMatchRegex);

      // check if images are in file
      if (images) {
        console.log(
          'Extraxting images from:',
          file.replace(workingDirectory, '')
        );
        const markdownPath = path.dirname(file);

        // go through each image found
        for (const image of images) {
          // extract image details
          const groups = imageRegexGroup.exec(image)?.groups;

          // ensure all image details exist
          if (groups && groups.alt && groups.src) {
            const imageFileName = groups.src.split('/').pop() || '';
            const srcPath = path.join(markdownPath, imageFileName);
            const outputPath = path.join(outputFolder, imageFileName);

            // check if image file exists
            if (fs.existsSync(srcPath)) {
              console.log(`Saving ${srcPath} to ${outputPath}`);
              // fs.createReadStream(srcPath).pipe(
              //   fs.createWriteStream(outputPath)
              // );
            }
          }
        }
      }
    }
  });
};<commit_msg>chore: make sure temp folder exists, probably wont stay<commit_after>import * as glob from 'glob';
import * as path from 'path';
import * as fs from 'fs';

import {getWorkingDirectory} from './utils';

const libName = require('../package.json').name;
const imageMatchRegex = /!\[(.*)\]\((?!http?).*\\*.(png|svg|jpg|jpeg)\)/g;
const imageRegexGroup = /!\[(?<alt>(.*))\]\((?<src>(?!http?).*\.(png|svg|jpg|jpeg))\)/;

export default async (filepath = process.cwd()): Promise<void> => {
  const workingDirectory = getWorkingDirectory(filepath);
  const outputFolder = path.join(workingDirectory, `${libName}-temp`);
  const mdGlob = path.join(workingDirectory, '!(node_modules)', '**', '*.md');

  if (!fs.existsSync(outputFolder)) {
    fs.mkdirSync(outputFolder);
  }

  glob(mdGlob, {}, async (_, files) => {
    // Go through all the files that were found
    for (const file of files) {
      const markdown = fs.readFileSync(file, 'utf8');
      const images = markdown.match(imageMatchRegex);

      // check if images are in file
      if (images) {
        console.log(
          'Extraxting images from:',
          file.replace(workingDirectory, '')
        );
        const markdownPath = path.dirname(file);

        // go through each image found
        for (const image of images) {
          // extract image details
          const groups = imageRegexGroup.exec(image)?.groups;

          // ensure all image details exist
          if (groups && groups.alt && groups.src) {
            const imageFileName = groups.src.split('/').pop() || '';
            const srcPath = path.join(markdownPath, imageFileName);
            const outputPath = path.join(outputFolder, imageFileName);

            // check if image file exists
            if (fs.existsSync(srcPath)) {
              // fs.createReadStream(srcPath).pipe(
              //   fs.createWriteStream(outputPath)
              // );
            }
          }
        }
      }
    }
  });
};
{'fraction_non_alphanumeric': 0.15811088295687886, 'fraction_numerical': 0.000513347022587269, 'mean_word_length': 2.4274406332453826, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '3457718', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1107, 'n_words': 276}