<commit_before>'use strict';

var fs = require('graceful-fs');
var path = require('path');

var gulp = require('gulp');
var $ = require('gulp-load-plugins')();

var autoprefixer = require('autoprefixer');

var merge = require('merge-stream');
var del = require('del');
var typescript = require('typescript');


var tsLintConfig = require('./tslint-rules');
var sassLintRules = require('./sasslint-rules');
var gr = require('./gulp-reporters');

var webpack = require("webpack");

function identity(x) { return x };


// Modifiers ==============

var globalShowStats = false;

exports.showStats = function() {
  globalShowStats = true;
};

exports.hideStats = function() {
  globalShowStats = false;
};


var globalFailOnError = false;

exports.failOnError = function() {
  globalFailOnError = true;
};


// TASKS ==============

exports.taskStyle = function(opt) {
  opt = opt || {};
  var rules = opt.rules || sassLintRules;

  $.sass.compiler = require('node-sass');

  return function() {
    var errorTexts = [];

    return gulp.src('./src/client/**/*.scss')
      .pipe($.sassLint({ rules: rules }))
      .pipe(gr.sassLintReporterFactory({ errorTexts: errorTexts }))
      .pipe($.sass({
        outputStyle: 'compressed'
      }).on('error', gr.sassErrorFactory({
        errorTexts: errorTexts
      })))
      .pipe($.postcss([
        autoprefixer({
          browsers: ['> 1%', 'last 3 versions', 'Firefox ESR', 'Opera 12.1'],
          remove: false // If you have no legacy code, this option will make Autoprefixer about 10% faster.
        })
      ]))
      .pipe(gulp.dest('./build/client'))
      .on('finish', function() {
        gr.writeErrors('./webstorm/errors', errorTexts);
        if (globalFailOnError && errorTexts.length) process.exit(1);
      });
  };
};


exports.taskIcons = function() {
  return function() {
    return gulp.src('./src/client/**/*.svg')
      // Just copy for now
      .pipe(gulp.dest('./build/client'))
  };
};


exports.taskHtml = function() {
  return function() {
    return gulp.src('./src/client/**/*.html')
      // Just copy for now
      .pipe(gulp.dest('./build/client'))
  };
};


exports.taskClientTypeScript = function(opt) {
  opt = opt || {};
  var declaration = opt.declaration || false;
  var strictNullChecks = opt.strictNullChecks || false;
  var tsLintConfigHook = opt.tsLintConfigHook || identity;

  var tsProject = $.typescript.createProject({
    typescript: typescript,
    noImplicitAny: true,
    noFallthroughCasesInSwitch: true,
    noImplicitReturns: true,
    noEmitOnError: true,
    removeComments: true,
    strictNullChecks: strictNullChecks,
    target: 'ES5',
    module: 'commonjs',
    declaration: declaration,
    jsx: 'react'
  });

  return function() {
    var errorTexts = [];

    function fixPath(str) {
      return str.replace('/build/tmp/', '/src/');
    }

    var sourceFiles = gulp.src(['./src/{client,common}/**/*.{ts,tsx}'])
      .pipe($.cached('client'))
      .pipe($.tslint({configuration: tsLintConfigHook(tsLintConfig)}))
      .pipe($.tslint.report(
        gr.tscLintReporterFactory({
          errorTexts: errorTexts,
          fixPath: fixPath
        }),
        { emitError: false }
      ));

    var typeFiles = gulp.src(['./typings/**/*.d.ts']);

    var compiled = merge(sourceFiles, typeFiles)
      .pipe($.typescript(
        tsProject,
        undefined,
        gr.tscReporterFactory({
          errorTexts: errorTexts,
          fixPath: fixPath,
          onFinish: function() {
            gr.writeErrors('./webstorm/errors', errorTexts);
            if (globalFailOnError && errorTexts.length) process.exit(1);
          }
        })
      ));

    if (declaration) {
      return merge([
        compiled.dts.pipe(gulp.dest('./build')),
        compiled.js.pipe(gulp.dest('./build'))
      ])
    } else {
      return compiled.pipe(gulp.dest('./build'));
    }
  };
};


exports.taskServerTypeScript = function(opt) {
  opt = opt || {};
  var declaration = opt.declaration || false;
  var strictNullChecks = opt.strictNullChecks || false;
  var tsLintConfigHook = opt.tsLintConfigHook || identity;

  var tsProject = $.typescript.createProject({
    typescript: typescript,
    noImplicitAny: true,
    noFallthroughCasesInSwitch: true,
    noImplicitReturns: true,
    noEmitOnError: true,
    removeComments: true,
    strictNullChecks: strictNullChecks,
    target: 'ES5',
    module: 'commonjs',
    declaration: declaration
  });

  return function() {
    var errorTexts = [];

    var sourceFiles = gulp.src(['./src/{server,common}/**/*.ts'])
      .pipe($.cached('server'))
      .pipe($.tslint({configuration: tsLintConfigHook(tsLintConfig)}))
      .pipe($.tslint.report(
        gr.tscLintReporterFactory({
          errorTexts: errorTexts
        }),
        { emitError: false }
      ));

    var typeFiles = gulp.src(['./typings/**/*.d.ts']);

    var compiled = merge(sourceFiles, typeFiles)
      .pipe($.typescript(
        tsProject,
        undefined,
        gr.tscReporterFactory({
          errorTexts: errorTexts,<commit_msg>moduleREsolution: node<commit_after>'use strict';

var fs = require('graceful-fs');
var path = require('path');

var gulp = require('gulp');
var $ = require('gulp-load-plugins')();

var autoprefixer = require('autoprefixer');

var merge = require('merge-stream');
var del = require('del');
var typescript = require('typescript');


var tsLintConfig = require('./tslint-rules');
var sassLintRules = require('./sasslint-rules');
var gr = require('./gulp-reporters');

var webpack = require("webpack");

function identity(x) { return x }


// Modifiers ==============

var globalShowStats = false;

exports.showStats = function() {
  globalShowStats = true;
};

exports.hideStats = function() {
  globalShowStats = false;
};


var globalFailOnError = false;

exports.failOnError = function() {
  globalFailOnError = true;
};


// TASKS ==============

exports.taskStyle = function(opt) {
  opt = opt || {};
  var rules = opt.rules || sassLintRules;

  $.sass.compiler = require('node-sass');

  return function() {
    var errorTexts = [];

    return gulp.src('./src/client/**/*.scss')
      .pipe($.sassLint({ rules: rules }))
      .pipe(gr.sassLintReporterFactory({ errorTexts: errorTexts }))
      .pipe($.sass({
        outputStyle: 'compressed'
      }).on('error', gr.sassErrorFactory({
        errorTexts: errorTexts
      })))
      .pipe($.postcss([
        autoprefixer({
          browsers: ['> 1%', 'last 3 versions', 'Firefox ESR', 'Opera 12.1'],
          remove: false // If you have no legacy code, this option will make Autoprefixer about 10% faster.
        })
      ]))
      .pipe(gulp.dest('./build/client'))
      .on('finish', function() {
        gr.writeErrors('./webstorm/errors', errorTexts);
        if (globalFailOnError && errorTexts.length) process.exit(1);
      });
  };
};


exports.taskIcons = function() {
  return function() {
    return gulp.src('./src/client/**/*.svg')
      // Just copy for now
      .pipe(gulp.dest('./build/client'))
  };
};


exports.taskHtml = function() {
  return function() {
    return gulp.src('./src/client/**/*.html')
      // Just copy for now
      .pipe(gulp.dest('./build/client'))
  };
};


exports.taskClientTypeScript = function(opt) {
  opt = opt || {};
  var declaration = opt.declaration || false;
  var strictNullChecks = opt.strictNullChecks || false;
  var tsLintConfigHook = opt.tsLintConfigHook || identity;

  var tsProject = $.typescript.createProject({
    typescript: typescript,
    noImplicitAny: true,
    noFallthroughCasesInSwitch: true,
    noImplicitReturns: true,
    noEmitOnError: true,
    removeComments: true,
    strictNullChecks: strictNullChecks,
    target: 'ES5',
    module: 'commonjs',
    moduleResolution: 'node',
    declaration: declaration,
    jsx: 'react'
  });

  return function() {
    var errorTexts = [];

    function fixPath(str) {
      return str.replace('/build/tmp/', '/src/');
    }

    var sourceFiles = gulp.src(['./src/{client,common}/**/*.{ts,tsx}'])
      .pipe($.cached('client'))
      .pipe($.tslint({configuration: tsLintConfigHook(tsLintConfig)}))
      .pipe($.tslint.report(
        gr.tscLintReporterFactory({
          errorTexts: errorTexts,
          fixPath: fixPath
        }),
        { emitError: false }
      ));

    var typeFiles = gulp.src(['./typings/**/*.d.ts']);

    var compiled = merge(sourceFiles, typeFiles)
      .pipe($.typescript(
        tsProject,
        undefined,
        gr.tscReporterFactory({
          errorTexts: errorTexts,
          fixPath: fixPath,
          onFinish: function() {
            gr.writeErrors('./webstorm/errors', errorTexts);
            if (globalFailOnError && errorTexts.length) process.exit(1);
          }
        })
      ));

    if (declaration) {
      return merge([
        compiled.dts.pipe(gulp.dest('./build')),
        compiled.js.pipe(gulp.dest('./build'))
      ])
    } else {
      return compiled.pipe(gulp.dest('./build'));
    }
  };
};


exports.taskServerTypeScript = function(opt) {
  opt = opt || {};
  var declaration = opt.declaration || false;
  var strictNullChecks = opt.strictNullChecks || false;
  var tsLintConfigHook = opt.tsLintConfigHook || identity;

  var tsProject = $.typescript.createProject({
    typescript: typescript,
    noImplicitAny: true,
    noFallthroughCasesInSwitch: true,
    noImplicitReturns: true,
    noEmitOnError: true,
    removeComments: true,
    strictNullChecks: strictNullChecks,
    target: 'ES5',
    module: 'commonjs',
    moduleResolution: 'node',
    declaration: declaration
  });

  return function() {
    var errorTexts = [];

    var sourceFiles = gulp.src(['./src/{server,common}/**/*.ts'])
      .pipe($.cached('server'))
      .pipe($.tslint({configuration: tsLintConfigHook(tsLintConfig)}))
      .pipe($.tslint.report(
        gr.tscLintReporterFactory({
          errorTexts: errorTexts
        }),
        { emitError: false }
      ));

    var typeFiles = gulp.src(['./typings/**/*.d.ts']);

    var compiled = merge(sourceFiles, typeFiles)
      .pipe($.typescript(
        tsProject,
        undefined,
        gr.tscReporterFactory({
          errorTexts: errorTexts,
{'fraction_non_alphanumeric': 0.16415868673050615, 'fraction_numerical': 0.0021496970881375805, 'mean_word_length': 2.8304640718562872, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5339150', 'n_tokens_mistral': 3286, 'n_tokens_neox': 3228, 'n_words': 628}