<commit_before>var fs = require('fs');
var gulp = require('gulp');
var gulpif = require('gulp-if');
var rjs = require('gulp-requirejs');
var compass = require('gulp-compass');
var babel = require('gulp-babel');
var uglify = require('gulp-uglify');
var clean = require('gulp-clean');
var jshint = require('gulp-jshint');
var rename = require("gulp-rename");
var nwBuilder = require('node-webkit-builder');
var htmlreplace = require('gulp-html-replace');
var sequence = require('gulp-sequence');

var CURRENT_ENVIRONMENT = 'development';

// TODO
// we have to double check **/*.js is a right expression or not
const SCSS_FILES = './src/frontend/scss/**/*.scss';
const FRONTEND_JS_FILES = './src/frontend/js/**/*.js';
const BACKEND_JS_FILES = './src/backend/**/*.js';
const VENDOR_FILES = './src/frontend/vendor/**/*';
const COMPONENTS_FILES = './src/frontend/js/components/**/*.js';
const DIST_FILES = './dist';
const INDEX_TEMPLATE_FILE = './_index.html';
const INDEX_FILE = './index.html';

function isProduction() {
  return CURRENT_ENVIRONMENT === 'production';
}

gulp.task('cleanup', function() {
  return gulp
    .src([DIST_FILES], {
      read: false
    })
    .pipe(clean());
});

gulp.task('6to5:frontend', function() {
  return gulp
    .src(FRONTEND_JS_FILES)
    .pipe(babel({
      // we only process react here
      whitelist: ['react']
    }))
    .pipe(gulp.dest('./dist/frontend'));
});

gulp.task('6to5:backend', function() {
  // we just want to move all files to the right place
  return gulp
    .src(BACKEND_JS_FILES)
    .pipe(gulp.dest('./dist/backend'));
});

gulp.task('linter', function() {
  return gulp
    .src([
      './src/frontend/js/**/*.js',
      './src/backend/**/*.js'
    ])
    .pipe(jshint())
    .pipe(jshint.reporter('jshint-stylish'));
});

gulp.task('copy:vendor', function() {
  return gulp
    .src(VENDOR_FILES)
    .pipe(gulp.dest('./dist/vendor'));
});

gulp.task('rjs', function(done) {
  // all frontend + backend js -> main.js
  fs.readFile('./config/rjs_config.json', 'utf-8', function(error, rawData) {
    if (error) {
      console.log(error);
      return;
    }
    else {
      var rjsConfig = JSON.parse(rawData);
      rjs(rjsConfig)
        .pipe(gulp.dest('dist/'))
        .on('end', done);
    }
  });
});

gulp.task('compass', function() {
  return gulp
    .src(SCSS_FILES)
    .pipe(compass({
      config_file: './config/compass_config.rb',
      css: 'src/frontend/css',
      sass: 'src/frontend/scss'
    }))
    .pipe(gulp.dest('./src/frontend/css'));
});

gulp.task('override', function() {
  // TODO
  // we have to minify css later
  return gulp
    .src(INDEX_TEMPLATE_FILE)
    .pipe(gulpif(isProduction(), htmlreplace({
      css: [
        'dist/frontend/vendor/bootstrap/dist/css/bootstrap.min.css',
        'dist/frontend/vendor/components-font-awesome/css/font-awesome.min.css',
        'dist/frontend/vendor/video.js/dist/video-js/video-js.min.css',
        'dist/frontend/css/index.css'
      ],
      backend_js: [
        'dist/backend/main.js'
      ],
      frontend_js: {
        src: 'dist/main',
        tpl: '<script data-main="%s" src="src/frontend/vendor/requirejs/require.js"></script>'
      }
    })))
    .pipe(rename(INDEX_FILE))
    .pipe(gulp.dest('./'));
});

gulp.task('watch', function() {
  gulp.watch(SCSS_FILES, ['compass']);
  gulp.watch([
    FRONTEND_JS_FILES,
    BACKEND_JS_FILES,
    INDEX_TEMPLATE_FILE,
    '!' + COMPONENTS_FILES<commit_msg>fixed watch task problem that would not trigger<commit_after>var fs = require('fs');
var gulp = require('gulp');
var gulpif = require('gulp-if');
var rjs = require('gulp-requirejs');
var compass = require('gulp-compass');
var babel = require('gulp-babel');
var uglify = require('gulp-uglify');
var clean = require('gulp-clean');
var jshint = require('gulp-jshint');
var rename = require("gulp-rename");
var nwBuilder = require('node-webkit-builder');
var htmlreplace = require('gulp-html-replace');
var sequence = require('gulp-sequence');

var CURRENT_ENVIRONMENT = 'development';

// TODO
// we have to double check **/*.js is a right expression or not
const SCSS_FILES = './src/frontend/scss/**/*.scss';
const FRONTEND_JS_FILES = './src/frontend/js/**/*.js';
const BACKEND_JS_FILES = './src/backend/**/*.js';
const VENDOR_FILES = './src/frontend/vendor/**/*';
const DIST_FILES = './dist';
const INDEX_TEMPLATE_FILE = './_index.html';
const INDEX_FILE = './index.html';

function isProduction() {
  return CURRENT_ENVIRONMENT === 'production';
}

gulp.task('cleanup', function() {
  return gulp
    .src([DIST_FILES], {
      read: false
    })
    .pipe(clean());
});

gulp.task('6to5:frontend', function() {
  return gulp
    .src(FRONTEND_JS_FILES)
    .pipe(babel({
      // we only process react here
      whitelist: ['react']
    }))
    .pipe(gulp.dest('./dist/frontend'));
});

gulp.task('6to5:backend', function() {
  // we just want to move all files to the right place
  return gulp
    .src(BACKEND_JS_FILES)
    .pipe(gulp.dest('./dist/backend'));
});

gulp.task('linter', function() {
  return gulp
    .src([
      './src/frontend/js/**/*.js',
      './src/backend/**/*.js'
    ])
    .pipe(jshint())
    .pipe(jshint.reporter('jshint-stylish'));
});

gulp.task('copy:vendor', function() {
  return gulp
    .src(VENDOR_FILES)
    .pipe(gulp.dest('./dist/vendor'));
});

gulp.task('rjs', function(done) {
  // all frontend + backend js -> main.js
  fs.readFile('./config/rjs_config.json', 'utf-8', function(error, rawData) {
    if (error) {
      console.log(error);
      return;
    }
    else {
      var rjsConfig = JSON.parse(rawData);
      rjs(rjsConfig)
        .pipe(gulp.dest('dist/'))
        .on('end', done);
    }
  });
});

gulp.task('compass', function() {
  return gulp
    .src(SCSS_FILES)
    .pipe(compass({
      config_file: './config/compass_config.rb',
      css: 'src/frontend/css',
      sass: 'src/frontend/scss'
    }))
    .pipe(gulp.dest('./src/frontend/css'));
});

gulp.task('override', function() {
  // TODO
  // we have to minify css later
  return gulp
    .src(INDEX_TEMPLATE_FILE)
    .pipe(gulpif(isProduction(), htmlreplace({
      css: [
        'dist/frontend/vendor/bootstrap/dist/css/bootstrap.min.css',
        'dist/frontend/vendor/components-font-awesome/css/font-awesome.min.css',
        'dist/frontend/vendor/video.js/dist/video-js/video-js.min.css',
        'dist/frontend/css/index.css'
      ],
      backend_js: [
        'dist/backend/main.js'
      ],
      frontend_js: {
        src: 'dist/main',
        tpl: '<script data-main="%s" src="src/frontend/vendor/requirejs/require.js"></script>'
      }
    })))
    .pipe(rename(INDEX_FILE))
    .pipe(gulp.dest('./'));
});

gulp.task('watch', function() {
  gulp.watch(SCSS_FILES, ['compass']);
  gulp.watch([
    FRONTEND_JS_FILES,
    BACKEND_JS_FILES,
    INDEX_TEMPLATE_FILE
{'fraction_non_alphanumeric': 0.19140568099053168, 'fraction_numerical': 0.0014566642388929353, 'mean_word_length': 3.1237237237237236, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2788791', 'n_tokens_mistral': 2513, 'n_tokens_neox': 2466, 'n_words': 428}