<commit_before>var browserSync = require('browser-sync').create();
var clean = require('gulp-clean');
var concat = require('gulp-concat');
var gulp = require('gulp');
var gutil = require('gulp-util');
var karma = require('karma').server;
var minifyCss = require('gulp-minify-css');
var nwBuilder = require('node-webkit-builder');
var runSequence = require('run-sequence');
var uglify = require('gulp-uglify');

var source = require('vinyl-source-stream');
var browserify = require('browserify');
var watchify = require('watchify');
var reactify = require('reactify');

var bases = {
 src: 'src/',
 dist: 'dist/',
 concat: 'dist/concat/',
 webkit: 'dist/build/'
};

var paths = {
	main: ['src/js/main.js'], // since we need to browserify this file specifically
	scripts: ['js/shell/*.js', 'js/support/*.js'],
	libs: ['js/lib/*.*', 'css/lib/*.*', 'css/fonts/*.*', 'css/lib/fonts/*.*'],
	styles: ['css/*.*'],
	html: ['index.html'],
	images: ['assets/*.*'],
	extras: ['package.json'],
    chrome_extension: ['extension/manifest.json', 'extension/background.js']	
};

var filesToMove = paths.libs.concat(paths.html)										
					.concat(paths.images)
					.concat(paths.extras)
                    .concat(paths.chrome_extension);
					
gulp.task('clean', function() {
	return gulp.src(bases.dist)
		.pipe(clean());
});
					
gulp.task('browserify', function () {
    return gulp.src(paths.main, {cwd: bases.src})
        .pipe(browserify({
            transform: 'reactify',
            debug : true
        }))
        .pipe(concat('main.js'))	
		.pipe(uglify())		
        .pipe(gulp.dest(bases.concat + 'js/'));
});

gulp.task('build-scripts', function() {
	return gulp.src(paths.scripts, {cwd: bases.src})
		.pipe(concat('support.js'))
		.pipe(uglify())
		.pipe(gulp.dest(bases.concat + 'js/'));
});

gulp.task('build-css', function() {
  return gulp.src(paths.styles, {cwd: bases.src})
	.pipe(concat('style.css'))
    .pipe(minifyCss())
    .pipe(gulp.dest(bases.concat + 'css/'));
});

gulp.task('dev-browserify', function () {
    return gulp.src(paths.main, {cwd: bases.src})
        .pipe(browserify({
            transform: 'reactify',
            debug : true
        }))
        .pipe(concat('main.js'))			
        .pipe(gulp.dest(bases.concat + 'js/'));
});

gulp.task('dev-build-scripts', function() {
	return gulp.src(paths.scripts, {cwd: bases.src})
		.pipe(concat('support.js'))		
		.pipe(gulp.dest(bases.concat + 'js/'));
});

gulp.task('dev-build-css', function() {
  return gulp.src(paths.styles, {cwd: bases.src})
	.pipe(concat('style.css'))    
    .pipe(gulp.dest(bases.concat + 'css/'));
});

gulp.task('copy-extras', function () {	
	return gulp.src(filesToMove, { base: bases.src, cwd: bases.src })
		.pipe(gulp.dest(bases.concat));
});

gulp.task('webkit-build', function () {
    var nw = new nwBuilder({
        version: '0.12.0',
        files: [ bases.dist + '**'],
        platforms: ['win'],
		buildDir: bases.webkit,
		winIco: 'lazymine.ico'
    });

    nw.on('log', function (msg) {
        gutil.log('node-webkit-builder', msg);
    });

    return nw.build().catch(function (err) {
        gutil.log('node-webkit-builder', err);
    });
});

gulp.task('test', function (done) {
	return karma.start({
		configFile: __dirname + '/karma.conf.js',
		singleRun: true
	}, function(code) {
		if(code != 0) {
			gutil.log(gutil.colors.red('ONE OR MORE TEST CASES HAVE FAILED! BUILD STOPPED!'));
			process.exit(code);
		}
		else {
			done();
		}
    });
});

gulp.task('default', function(callback) {
	runSequence(['clean'],
				['dev-build-scripts', 'dev-build-css', 'copy-extras'],
                ['browserify-With-Watch'],
                ['watch'],
				callback);		
});

gulp.task('ci', function(callback) {
    runSequence('clean',
        ['browserify-Without-Watch', 'build-scripts', 'build-css', 'copy-extras'],
        'webkit-build',
        callback);
});

gulp.task('build', function(callback) {
	runSequence(['clean', 'test'],
				['browserify', 'build-scripts', 'build-css', 'copy-extras'],
				'webkit-build',
				callback);
});

// ===========================================================
// TRIAL AND ERROR AREA 


gulp.task('watch', function () {
    gulp.watch('src/css/*.*', ['dev-build-css']);
});


gulp.task('browserify-With-Watch', function() {
    var bundler = browserify({
        entries: [paths.main], // Only need initial file, browserify finds the deps
        transform: [reactify], // We want to convert JSX to normal javascript
        debug: true, // Gives us sourcemapping
        cache: {}, packageCache: {}, fullPaths: true // Requirement of watchify
    });
    var watcher  = watchify(bundler);

    return watcher
        .on('update', function () { // When any files update
            var updateStart = Date.now();
            console.log('Updating!');
            watcher.bundle() // Create new bundle that uses the cache for high performance
                .pipe(source('main.js'))
                // This is where you add uglifying etc.
                .pipe(gulp.dest(bases.concat + 'js/'));
            console.log('Updated!', (Date.now() - updateStart) + 'ms');
        })
        .bundle() // Create the initial bundle when starting the task
        .pipe(source('main.js'))
        .pipe(gulp.dest(bases.concat + 'js/'));
});

gulp.task('browserify-Without-Watch', function() {
    var bundler = browserify({
        entries: [paths.main], // Only need initial file, browserify finds the deps
        transform: [reactify], // We want to convert JSX to normal javascript
        debug: true, // Gives us sourcemapping
        cache: {}, packageCache: {}, fullPaths: true // Requirement of watchify
    });
    
    return bundler
        .bundle() // Create the initial bundle when starting the task
        .pipe(source('main.js'))
        .pipe(gulp.dest(bases.concat + 'js/'));
});

// ===========================================================<commit_msg>JSLINT fix<commit_after>/*global require, console, process, __dirname*/
var browserSync = require('browser-sync').create(),
    clean = require('gulp-clean'),
    concat = require('gulp-concat'),
    gulp = require('gulp'),
    gutil = require('gulp-util'),
    karma = require('karma').server,
    minifyCss = require('gulp-minify-css'),
    NwBuilder = require('node-webkit-builder'),
    runSequence = require('run-sequence'),
    uglify = require('gulp-uglify'),
    source = require('vinyl-source-stream'),
    browserify = require('browserify'),
    watchify = require('watchify'),
    reactify = require('reactify');

var bases = {
    src: 'src/',
    dist: 'dist/',
    concat: 'dist/concat/',
    webkit: 'dist/build/'
};

var paths = {
    main: ['src/js/main.js'], // since we need to browserify this file specifically
    scripts: ['js/shell/*.js', 'js/support/*.js'],
    libs: ['js/lib/*.*', 'css/lib/*.*', 'css/fonts/*.*', 'css/lib/fonts/*.*'],
    styles: ['css/*.*'],
    html: ['index.html'],
    images: ['assets/*.*'],
    extras: ['package.json'],
    chrome_extension: ['extension/manifest.json', 'extension/background.js']
};

var filesToMove = paths.libs.concat(paths.html)
                    .concat(paths.images)
                    .concat(paths.extras)
                    .concat(paths.chrome_extension);

gulp.task('clean', function () {
    "use strict";
    return gulp.src(bases.dist)
        .pipe(clean());
});

gulp.task('browserify', function () {
    "use strict";
    return gulp.src(paths.main, {cwd: bases.src})
        .pipe(browserify({
            transform: 'reactify',
            debug : true
        }))
        .pipe(concat('main.js'))
        .pipe(uglify())
        .pipe(gulp.dest(bases.concat + 'js/'));
});

gulp.task('build-scripts', function () {
    "use strict";
    return gulp.src(paths.scripts, {cwd: bases.src})
        .pipe(concat('support.js'))
        .pipe(uglify())
        .pipe(gulp.dest(bases.concat + 'js/'));
});

gulp.task('build-css', function () {
    "use strict";
    return gulp.src(paths.styles, {cwd: bases.src})
        .pipe(concat('style.css'))
        .pipe(minifyCss())
        .pipe(gulp.dest(bases.concat + 'css/'));
});

gulp.task('dev-browserify', function () {
    "use strict";
    return gulp.src(paths.main, {cwd: bases.src})
        .pipe(browserify({
            transform: 'reactify',
            debug : true
        }))
        .pipe(concat('main.js'))
        .pipe(gulp.dest(bases.concat + 'js/'));
});

gulp.task('dev-build-scripts', function () {
    "use strict";
    return gulp.src(paths.scripts, {cwd: bases.src})
        .pipe(concat('support.js'))
        .pipe(gulp.dest(bases.concat + 'js/'));
});

gulp.task('dev-build-css', function () {
    "use strict";
    return gulp.src(paths.styles, {cwd: bases.src})
        .pipe(concat('style.css'))
        .pipe(gulp.dest(bases.concat + 'css/'));
});

gulp.task('copy-extras', function () {
    "use strict";
    return gulp.src(filesToMove, { base: bases.src, cwd: bases.src })
        .pipe(gulp.dest(bases.concat));
});

gulp.task('webkit-build', function () {
    "use strict";
    var nw = new NwBuilder({
        version: '0.12.0',
        files: [ bases.dist + '**'],
        platforms: ['win'],
        buildDir: bases.webkit,
        winIco: 'lazymine.ico'
    });

    nw.on('log', function (msg) {
        gutil.log('node-webkit-builder', msg);
    });

    return nw.build().catch(function (err) {
        gutil.log('node-webkit-builder', err);
    });
});

gulp.task('test', function (done) {
    "use strict";
    return karma.start({
        configFile: __dirname + '/karma.conf.js',
        singleRun: true
    }, function (code) {
        if (code !== 0) {
            gutil.log(gutil.colors.red('ONE OR MORE TEST CASES HAVE FAILED! BUILD STOPPED!'));
            process.exit(code);
        } else {
            done();
        }
    });
});

gulp.task('default', function (callback) {
    "use strict";
    runSequence(['clean'],
                ['dev-build-scripts', 'dev-build-css', 'copy-extras'],
                ['browserify-With-Watch'],
                ['watch'],
                callback);
});

gulp.task('ci', function (callback) {
    "use strict";
    runSequence('clean',
        ['browserify-Without-Watch', 'build-scripts', 'build-css', 'copy-extras'],
        'webkit-build',
        callback);
});

gulp.task('build', function (callback) {
    "use strict";
    runSequence(['clean', 'test'],
                ['browserify', 'build-scripts', 'build-css', 'copy-extras'],
                'webkit-build',
                callback);
});

// ===========================================================
// TRIAL AND ERROR AREA 


gulp.task('watch', function () {
    "use strict";
    gulp.watch('src/css/*.*', ['dev-build-css']);
});


gulp.task('browserify-With-Watch', function () {
    "use strict";
    var bundler = browserify({
            entries: [paths.main], // Only need initial file, browserify finds the deps
            transform: [reactify], // We want to convert JSX to normal javascript
            debug: true, // Gives us sourcemapping
            cache: {},
            packageCache: {},
            fullPaths: true // Requirement of watchify
        }),
        watcher  = watchify(bundler);

    return watcher.on('update', function () { // When any files update
        var updateStart = Date.now();
        console.log('Updating!');
        watcher.bundle() // Create new bundle that uses the cache for high performance
            .pipe(source('main.js'))
            .pipe(gulp.dest(bases.concat + 'js/')); // This is where you add uglifying etc.
        console.log('Updated!', (Date.now() - updateStart) + 'ms');
    }).bundle() // Create the initial bundle when starting the task
        .pipe(source('main.js'))
        .pipe(gulp.dest(bases.concat + 'js/'));
});

gulp.task('browserify-Without-Watch', function () {
    "use strict";
    var bundler = browserify({
        entries: [paths.main], // Only need initial file, browserify finds the deps
        transform: [reactify], // We want to convert JSX to normal javascript
        debug: true, // Gives us sourcemapping
        cache: {},
        packageCache: {},
        fullPaths: true // Requirement of watchify
    });

    return bundler.bundle() // Create the initial bundle when starting the task
        .pipe(source('main.js'))
        .pipe(gulp.dest(bases.concat + 'js/'));
});

// ===========================================================
{'fraction_non_alphanumeric': 0.20433039294306335, 'fraction_numerical': 0.0008019246190858059, 'mean_word_length': 2.6820194862710363, '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': '2296959', 'n_tokens_mistral': 4108, 'n_tokens_neox': 3945, 'n_words': 821}