<commit_before>import { join, relative, basename } from 'path';
import { mkdirpSync } from 'fs-extra';
import * as Constants from './constants';
import { copyFileAsync, getBooleanPropertyValue, readDirAsync, unlinkAsync } from './helpers';
import { BuildContext } from './interfaces';

export function purgeSourceMapsIfNeeded(context: BuildContext): Promise<any> {
  if (getBooleanPropertyValue(Constants.ENV_VAR_GENERATE_SOURCE_MAP)) {
    // keep the source maps and just return
    return Promise.resolve([]);
  }
  return readDirAsync(context.buildDir).then((fileNames) => {
    const sourceMaps = fileNames.filter(fileName => fileName.endsWith('.map'));
    const fullPaths = sourceMaps.map(sourceMap => join(context.buildDir, sourceMap));
    const promises: Promise<void>[] = [];
    const copyBeforePurge = getBooleanPropertyValue(Constants.ENV_VAR_MOVE_SOURCE_MAPS);
    for (const fullPath of fullPaths) {
      if (copyBeforePurge) {
        mkdirpSync(context.sourcemapDir)
        const relativeTo = relative(fullPath, context.sourcemapDir)
        const fileName = basename(fullPath)
        promises.push(copyFileAsync(fullPath, join(context.sourcemapDir, fileName)).then(() => {
          return unlinkAsync(fullPath)
        }))
      } else {
        promises.push(unlinkAsync(fullPath))
      }
    }
    return Promise.all(promises);
  });
}<commit_msg>feat(sourcemaps): copy for prod and dev<commit_after>import { join, relative, basename } from 'path';
import { mkdirpSync } from 'fs-extra';
import * as Constants from './constants';
import { copyFileAsync, getBooleanPropertyValue, readDirAsync, unlinkAsync } from './helpers';
import { BuildContext } from './interfaces';

function copySourcemaps(context: BuildContext, shouldPurge: boolean) {
  return readDirAsync(context.buildDir).then((fileNames) => {
    const sourceMaps = fileNames.filter(fileName => fileName.endsWith('.map'));
    const fullPaths = sourceMaps.map(sourceMap => join(context.buildDir, sourceMap));
    const promises: Promise<void>[] = [];
    const copyBeforePurge = getBooleanPropertyValue(Constants.ENV_VAR_MOVE_SOURCE_MAPS);
    for (const fullPath of fullPaths) {
      if (copyBeforePurge) {
        mkdirpSync(context.sourcemapDir)
        const relativeTo = relative(fullPath, context.sourcemapDir)
        const fileName = basename(fullPath);
        if (fileName.indexOf('vendor.js') < 0) {
          promises.push(copyFileAsync(fullPath, join(context.sourcemapDir, fileName)));
        }
      }

      if (shouldPurge) {
        promises.push(unlinkAsync(fullPath))
      }
    }
    return Promise.all(promises);
  });
}

export function purgeSourceMapsIfNeeded(context: BuildContext): Promise<any> {
  if (getBooleanPropertyValue(Constants.ENV_VAR_GENERATE_SOURCE_MAP)) {
    // keep the source maps and just return
    return copySourcemaps(context, false);
  }

  return copySourcemaps(context, true);
}
{'fraction_non_alphanumeric': 0.11792937949948577, 'fraction_numerical': 0.00034281796366129587, 'mean_word_length': 4.229390681003585, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 14, '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': '6476565', 'n_tokens_mistral': 848, 'n_tokens_neox': 851, 'n_words': 182}