<commit_before>import * as autoprefixer from 'autoprefixer';
import * as cssnano from 'cssnano';
import * as gulp from 'gulp';
import * as gulpLoadPlugins from 'gulp-load-plugins';
import * as merge from 'merge-stream';
import * as util from 'gulp-util';
import { join } from 'path';

import Config from '../../config';
import { CssTask } from '../css_task';

const plugins = <any>gulpLoadPlugins();
const gulpConcatCssConfig = Config.getPluginConfig('gulp-concat-css');

const processors = [
  autoprefixer({
    browsers: Config.BROWSER_LIST
  })
];

const reportPostCssError = (e: any) => util.log(util.colors.red(e.message));

const isProd = Config.ENV === 'prod';

if (isProd) {
  processors.push(
    cssnano({
      discardComments: {removeAll: true},
      discardUnused: false, // unsafe, see http://goo.gl/RtrzwF
      zindex: false, // unsafe, see http://goo.gl/vZ4gbQ
      reduceIdents: false // unsafe, see http://goo.gl/tNOPv0
    })
  );
}

/**
 * Copies all HTML files in `src/client` over to the `dist/tmp` directory.
 */
function prepareTemplates() {
  return gulp.src(join(Config.APP_SRC, '**', '*.html'))
    .pipe(gulp.dest(Config.TMP_DIR));
}

/**
 * Execute the appropriate component-stylesheet processing method based on user stylesheet preference.
 */
function processComponentStylesheets() {
  return Config.ENABLE_SCSS ?
    merge(
      processComponentScss(),
      processComponentCss())
    :
    processComponentCss();
}

/**
 * Process scss files referenced from Angular component `styleUrls` metadata
 */
function processComponentScss() {
  return gulp.src(join(Config.APP_SRC, '**', '*.scss'))
    .pipe(isProd ? plugins.cached('process-component-scss') : plugins.util.noop())
    .pipe(isProd ? plugins.progeny() : plugins.util.noop())
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.sass(Config.getPluginConfig('gulp-sass')).on('error', plugins.sass.logError))
    .pipe(plugins.postcss(processors))
    .on('error', reportPostCssError)
    .pipe(plugins.sourcemaps.write(isProd ? '.' : '', {
      sourceMappingURL: (file: any) => {
        // write absolute urls to the map files
        return `/${file.relative}.map`;
      }
    }))
    .pipe(gulp.dest(isProd ? Config.TMP_DIR : Config.APP_DEST));
}

/**
 * Processes the CSS files within `src/client` excluding those in `src/client/assets` using `postcss` with the
 * configured processors.
 */
function processComponentCss() {
  return gulp.src([<commit_msg>use Config.APP_BASE so that it's configurable<commit_after>import * as autoprefixer from 'autoprefixer';
import * as cssnano from 'cssnano';
import * as gulp from 'gulp';
import * as gulpLoadPlugins from 'gulp-load-plugins';
import * as merge from 'merge-stream';
import * as util from 'gulp-util';
import { join } from 'path';

import Config from '../../config';
import { CssTask } from '../css_task';

const plugins = <any>gulpLoadPlugins();
const gulpConcatCssConfig = Config.getPluginConfig('gulp-concat-css');

const processors = [
  autoprefixer({
    browsers: Config.BROWSER_LIST
  })
];

const reportPostCssError = (e: any) => util.log(util.colors.red(e.message));

const isProd = Config.ENV === 'prod';

if (isProd) {
  processors.push(
    cssnano({
      discardComments: {removeAll: true},
      discardUnused: false, // unsafe, see http://goo.gl/RtrzwF
      zindex: false, // unsafe, see http://goo.gl/vZ4gbQ
      reduceIdents: false // unsafe, see http://goo.gl/tNOPv0
    })
  );
}

/**
 * Copies all HTML files in `src/client` over to the `dist/tmp` directory.
 */
function prepareTemplates() {
  return gulp.src(join(Config.APP_SRC, '**', '*.html'))
    .pipe(gulp.dest(Config.TMP_DIR));
}

/**
 * Execute the appropriate component-stylesheet processing method based on user stylesheet preference.
 */
function processComponentStylesheets() {
  return Config.ENABLE_SCSS ?
    merge(
      processComponentScss(),
      processComponentCss())
    :
    processComponentCss();
}

/**
 * Process scss files referenced from Angular component `styleUrls` metadata
 */
function processComponentScss() {
  return gulp.src(join(Config.APP_SRC, '**', '*.scss'))
    .pipe(isProd ? plugins.cached('process-component-scss') : plugins.util.noop())
    .pipe(isProd ? plugins.progeny() : plugins.util.noop())
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.sass(Config.getPluginConfig('gulp-sass')).on('error', plugins.sass.logError))
    .pipe(plugins.postcss(processors))
    .on('error', reportPostCssError)
    .pipe(plugins.sourcemaps.write(isProd ? '.' : '', {
      sourceMappingURL: (file: any) => {
        // write absolute urls to the map files
        return `${Config.APP_BASE}${file.relative}.map`;
      }
    }))
    .pipe(gulp.dest(isProd ? Config.TMP_DIR : Config.APP_DEST));
}

/**
 * Processes the CSS files within `src/client` excluding those in `src/client/assets` using `postcss` with the
 * configured processors.
 */
function processComponentCss() {
  return gulp.src([
{'fraction_non_alphanumeric': 0.15314952706782048, 'fraction_numerical': 0.0008049909438518816, 'mean_word_length': 3.7834456207892204, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '3499667', 'n_tokens_mistral': 1655, 'n_tokens_neox': 1653, 'n_words': 368}