<commit_before>/* global PATH_CONFIG TASK_CONFIG */
if (!TASK_CONFIG.stylesheets) {
  return;
}

const gulp = require("gulp");
const gulpif = require("gulp-if");
const browserSync = require("browser-sync");
const sass = require("gulp-sass");
const sourcemaps = require("gulp-sourcemaps");
const handleErrors = require("../lib/handleErrors");
const projectPath = require("../lib/projectPath");
const postcss = require("gulp-postcss");
const cssnano = require("cssnano");
const path = require("path");
const postcssPresetEnv = require("postcss-preset-env");
const postcssNormalize = require("postcss-normalize");
const purgecss = require("@fullhuman/postcss-purgecss");

const stylesheetsTask = function() {
  const isProduction =
    global.production !== undefined ? global.production : false;

  const paths = {
    src: projectPath(
      PATH_CONFIG.src,
      PATH_CONFIG.stylesheets.src,
      "**/*.{" + TASK_CONFIG.stylesheets.extensions + "}"
    ),
    dest: projectPath(PATH_CONFIG.dest, PATH_CONFIG.stylesheets.dest)
  };

  if (
    TASK_CONFIG.stylesheets.sass &&
    TASK_CONFIG.stylesheets.sass.includePaths
  ) {
    TASK_CONFIG.stylesheets.sass.includePaths = TASK_CONFIG.stylesheets.sass.includePaths.map(
      function(includePath) {
        return projectPath(includePath);
      }
    );
  }

  const postcssNormalizeConfig = TASK_CONFIG.stylesheets.normalize || {};
  postcssNormalizeConfig.forceImport = true;

  const postcssPresetEnvConfig = TASK_CONFIG.stylesheets.presetEnv || {};
  postcssPresetEnvConfig.stage = 0;

  const cssnanoConfig = TASK_CONFIG.stylesheets.cssnano || {};
  cssnanoConfig.autoprefixer = false; // this should always be false, since we're autoprefixing separately

  class NucleumPurgeCSS {
    static extract(content) {
      return content.match(/[A-z0-9@\-\:\/]+/g) || [];
    }
  }

  const purgecssConfig = TASK_CONFIG.stylesheets.purgecss || {};

  if (TASK_CONFIG.html) {
    if (TASK_CONFIG.purgecss) {
      purgecssConfig.content = [
        path.join(
          projectPath(PATH_CONFIG.src, PATH_CONFIG.html.src),
          "/**/*.{" + TASK_CONFIG.html.extensions + "}"
        )
      ];

      purgecssConfig.extractors = [
        {
          extractor: NucleumPurgeCSS,
          extensions: TASK_CONFIG.html.extensions
        }
      ];
    }
  } else {
    if (TASK_CONFIG.purgecss) {
      purgecssConfig.content = [
        path.join(projectPath(), ...TASK_CONFIG.stylesheets.purgecss.content)
      ];

      purgecssConfig.extractors = [
        {
          extractor: NucleumPurgeCSS,
          extensions: TASK_CONFIG.stylesheets.purgecss.extensions
        }
      ];
    }
  }

  const postCssPlugins = [
    postcssNormalize(postcssNormalizeConfig),
    postcssPresetEnv(postcssPresetEnvConfig),
    isProduction ? cssnano(cssnanoConfig) : false,
    isProduction && TASK_CONFIG.stylesheets.purgecss !== false
      ? purgecss(purgecssConfig)
      : false
  ].filter(Boolean);

  return gulp
    .src(paths.src)
    .pipe(gulpif(!global.production, sourcemaps.init()))
    .pipe(sass(TASK_CONFIG.stylesheets.sass))
    .on("error", handleErrors)
    .pipe(postcss(postCssPlugins))
    .pipe(gulpif(!global.production, sourcemaps.write()))
    .pipe(gulp.dest(paths.dest))
    .pipe(browserSync.stream());
};

gulp.task("stylesheets", stylesheetsTask);
module.exports = stylesheetsTask;<commit_msg>Add condition to prevent purgecss from running on the build<commit_after>/* global PATH_CONFIG TASK_CONFIG */
if (!TASK_CONFIG.stylesheets) {
  return;
}

const gulp = require("gulp");
const gulpif = require("gulp-if");
const browserSync = require("browser-sync");
const sass = require("gulp-sass");
const sourcemaps = require("gulp-sourcemaps");
const handleErrors = require("../lib/handleErrors");
const projectPath = require("../lib/projectPath");
const postcss = require("gulp-postcss");
const cssnano = require("cssnano");
const path = require("path");
const postcssPresetEnv = require("postcss-preset-env");
const postcssNormalize = require("postcss-normalize");
const purgecss = require("@fullhuman/postcss-purgecss");

const stylesheetsTask = function() {
  const isProduction =
    global.production !== undefined ? global.production : false;

  const paths = {
    src: projectPath(
      PATH_CONFIG.src,
      PATH_CONFIG.stylesheets.src,
      "**/*.{" + TASK_CONFIG.stylesheets.extensions + "}"
    ),
    dest: projectPath(PATH_CONFIG.dest, PATH_CONFIG.stylesheets.dest)
  };

  if (
    TASK_CONFIG.stylesheets.sass &&
    TASK_CONFIG.stylesheets.sass.includePaths
  ) {
    TASK_CONFIG.stylesheets.sass.includePaths = TASK_CONFIG.stylesheets.sass.includePaths.map(
      function(includePath) {
        return projectPath(includePath);
      }
    );
  }

  const postcssNormalizeConfig = TASK_CONFIG.stylesheets.normalize || {};
  postcssNormalizeConfig.forceImport = true;

  const postcssPresetEnvConfig = TASK_CONFIG.stylesheets.presetEnv || {};
  postcssPresetEnvConfig.stage = 0;

  const cssnanoConfig = TASK_CONFIG.stylesheets.cssnano || {};
  cssnanoConfig.autoprefixer = false; // this should always be false, since we're autoprefixing separately

  class NucleumPurgeCSS {
    static extract(content) {
      return content.match(/[A-z0-9@\-\:\/]+/g) || [];
    }
  }

  const purgecssConfig = TASK_CONFIG.stylesheets.purgecss || {};

  if (TASK_CONFIG.html) {
    if (TASK_CONFIG.purgecss) {
      purgecssConfig.content = [
        path.join(
          projectPath(PATH_CONFIG.src, PATH_CONFIG.html.src),
          "/**/*.{" + TASK_CONFIG.html.extensions + "}"
        )
      ];

      purgecssConfig.extractors = [
        {
          extractor: NucleumPurgeCSS,
          extensions: TASK_CONFIG.html.extensions
        }
      ];
    }
  } else {
    if (TASK_CONFIG.purgecss) {
      purgecssConfig.content = [
        path.join(projectPath(), ...TASK_CONFIG.stylesheets.purgecss.content)
      ];

      purgecssConfig.extractors = [
        {
          extractor: NucleumPurgeCSS,
          extensions: TASK_CONFIG.stylesheets.purgecss.extensions
        }
      ];
    }
  }

  const postCssPlugins = [
    postcssNormalize(postcssNormalizeConfig),
    postcssPresetEnv(postcssPresetEnvConfig),
    isProduction ? cssnano(cssnanoConfig) : false,
    isProduction && TASK_CONFIG.stylesheets.purgecss
      ? purgecss(purgecssConfig)
      : false
  ].filter(Boolean);

  return gulp
    .src(paths.src)
    .pipe(gulpif(!global.production, sourcemaps.init()))
    .pipe(sass(TASK_CONFIG.stylesheets.sass))
    .on("error", handleErrors)
    .pipe(postcss(postCssPlugins))
    .pipe(gulpif(!global.production, sourcemaps.write()))
    .pipe(gulp.dest(paths.dest))
    .pipe(browserSync.stream());
};

gulp.task("stylesheets", stylesheetsTask);
module.exports = stylesheetsTask;
{'fraction_non_alphanumeric': 0.1321060382916053, 'fraction_numerical': 0.0008836524300441826, 'mean_word_length': 3.4327676240208875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7369135', 'n_tokens_mistral': 2274, 'n_tokens_neox': 2167, 'n_words': 329}