<commit_before>// Load in all the plugins ----------------------------------------------------
//
// Note: Plumber fixes an issue with Node Stream piping
//		 -> https://gist.github.com/floatdrop/8269868

var gulp 			= require('gulp'),

    plumber 		= require('gulp-plumber'),
    connect			= require('connect'),
    http			= require('http'),
    open			= require('open'),
    rimraf 			= require('gulp-rimraf'),
    jshint 			= require('gulp-jshint'),
    concat 			= require('gulp-concat'),
    uglify 			= require('gulp-uglify'),
    sass 			= require('gulp-ruby-sass'),
    autoprefixer 	= require('gulp-autoprefixer'),
    minifycss 		= require('gulp-minify-css'),
    imagemin 		= require('gulp-imagemin'),
    rename 			= require('gulp-rename'),
    cache 			= require('gulp-cache'),
    refresh 		= require('gulp-livereload'),
    useref	 		= require('gulp-useref'),
    tinylr			= require('tiny-lr'),
    livereload		= tinylr(),
    server 			= lr(),

    config			= {
				    	app: 	'app',
				    	dist: 	'dist',
				    	port:	9000,
				    	lr:		35729
				    };

// Clean up -------------------------------------------------------------------
//
// This task does the following things:
// - Clean out the dist folder before rebuilding

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

// Styles ---------------------------------------------------------------------
//
// This task does the following things:
// - Grab and compile all main .scss files
// - Auto-prefix results
// - Save and minify results to .css files
// - Reload browser

gulp.task('styles', function()
{
	return gulp.src('assets/sass/*.scss')
		.pipe(plumber())
		.pipe(sass({ style: 'nested', compass: true }))
		.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
		.pipe(rename({suffix: '.min'}))
		.pipe(minifycss())
		.pipe(gulp.dest('dist/assets/css'))
		.pipe(livereload(server));
});

// Scripts --------------------------------------------------------------------
//

gulp.task('lint-main', function()
{
	return gulp.src(['assets/js/app.js', 'assets/js/core/*.js'])
		.pipe(jshint())
		.pipe(jshint.reporter('default'));
});

gulp.task('scripts-main', ['lint-main'], function()
{
	return gulp.src(['assets/js/libs/jquery*.js', 'assets/js/libs/*.js', 'assets/js/core/*.js', 'assets/js/app.js'])
		.pipe(plumber())
		.pipe(concat('core-libs.min.js'))
		.pipe(uglify())
		.pipe(gulp.dest('dist/assets/js'))
		.pipe(livereload(server));
});

gulp.task('scripts-view', function()
{
	return gulp.src('assets/js/view/*.js')
		.pipe(jshint())
		.pipe(jshint.reporter('default'))
		.pipe(rename({suffix: '.min'}))
		.pipe(uglify())
		.pipe(gulp.dest('dist/assets/js/view'))
		.pipe(livereload(server));
});

gulp.task('scripts-ie', function()
{
	return gulp.src(['**/html5shiv.js', '**/nwmatcher-1.2.5.js', '**/selectivizr.js', '**/matchmedia.polyfill.js', '**/matchmedia.addListener.js', '**/respond.js'])
		.pipe(plumber())
		.pipe(concat('ie.min.js'))
		.pipe(uglify())
		.pipe(gulp.dest('dist/assets/js'))
		.pipe(livereload(server));
});

// Images ---------------------------------------------------------------------
//
// This task does the following things:
// - Grab all images
// - Optimize them
// - Reload browser

gulp.task('images', function()
{
	return gulp.src('assets/images/**/*')
		.pipe(plumber())
		.pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))
		.pipe(gulp.dest('dist/assets/images'))
		.pipe(livereload(server));
});

// Watch ----------------------------------------------------------------------
//
// Watch files for changes and run appropriate task

gulp.task('watch', function(cb)
{
	server.listen(35729, function(err)
	{
		if (err) { return console.log(err) };

		console.log('Started watching assets folder..')

		gulp.watch('assets/sass/*.scss', ['styles'], function(event)
		{
      		console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
    	});

		gulp.watch('assets/**/*.js', ['scripts, ie-scripts'], function(event)
		{
      		console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
      	});

		gulp.watch('assets/images/**/*', ['images'], function(event)
		{
      		console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
      	});
	});

	cb();
});

// The default task -----------------------------------------------------------
//
// Runs tasks in order when you call 'gulp' from the CLI

// TODO:
// Use dependencies instead of gulp.run()
// Not as easy as it seems though

gulp.task('default', ['clean'], function(cb)
{
	gulp.run('styles', 'scripts-main', 'scripts-view', 'scripts-ie', /*'images',*/ 'watch');
});

<commit_msg>Cleaned up, started implementing dev/prod run<commit_after>// Load in all the plugins ----------------------------------------------------
//
// Note: Plumber fixes an issue with Node Stream piping
//		 -> https://gist.github.com/floatdrop/8269868

var gulp 			= require('gulp'),

    plumber 		= require('gulp-plumber'),
    connect			= require('connect'),
    http			= require('http'),
    open			= require('open'),
    gulpif			= require('gulp-if'),
    inject			= require('gulp-inject'),
    rimraf 			= require('gulp-rimraf'),
    jshint 			= require('gulp-jshint'),
    concat 			= require('gulp-concat'),
    uglify 			= require('gulp-uglify'),
    sass 			= require('gulp-ruby-sass'),
    autoprefixer 	= require('gulp-autoprefixer'),
    minifycss 		= require('gulp-minify-css'),
    imagemin 		= require('gulp-imagemin'),
    rename 			= require('gulp-rename'),
    cache 			= require('gulp-cache'),
    refresh 		= require('gulp-livereload'),
    tinylr			= require('tiny-lr'),
    livereload		= tinylr(),
    server 			= lr(),

    config			= {
				    	app: 	'app',
				    	dev:	'dev',
				    	dist: 	'dist',
				    	port:	9000,
				    	lr:		35729
				    };

// Catch CLI parameter

var isProduction = gulp.env.type === 'production';
console.log('isProduction: ' + isProduction);

// Clean up -------------------------------------------------------------------
//

gulp.task('clean', function()
{
	return gulp.src([config.dev, config.dist], {read: false})
		.pipe(plumber())
		.pipe(rimraf());
});

// Styles ---------------------------------------------------------------------
//

gulp.task('sass', function()
{
	return gulp.src(config.app + '/sass/*.scss')
		.pipe(plumber())
		.pipe(sass({ style: 'nested', compass: true }))
		.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
		.pipe(rename({suffix: '.min'}))
		.pipe(minifycss())
		.pipe(gulpif(isProduction, gulp.dest(config.dist + '/assets/css')))
		.pipe(gulpif(!isProduction, gulp.dest(config.dev + 'dist/assets/css')))
		.pipe(gulpif(isProduction, refresh(livereload)));
});

// Scripts --------------------------------------------------------------------
//

gulp.task('lint-main', function()
{
	return gulp.src([
			config.app + '/js/app.js',
			config.app + '/js/core/*.js'
		])
		.pipe(jshint())
		.pipe(jshint.reporter('default'));
});

gulp.task('scripts-main', ['lint-main'], function()
{
	return gulp.src([
			config.app + '/js/libs/jquery*.js',
			config.app + '/js/libs/*.js',
			config.app + '/js/core/*.js',
			config.app + '/js/app.js'
		])
		.pipe(plumber())
		.pipe(gulpif(isProduction, concat('core-libs.min.js')))
		.pipe(gulpif(isProduction, uglify()))
		.pipe(gulpif(isProduction, gulp.dest(config.dist + '/assets/js')))
		.pipe(gulpif(!isProduction, gulp.dest(config.dev + '/assets/js')))
		.pipe(gulpif(isProduction, refresh(livereload)));
});

gulp.task('lint-view', function()
{
	return gulp.src(config.app + '/js/view/*.js')
		.pipe(plumber())
		.pipe(jshint())
		.pipe(jshint.reporter('default'));
});

gulp.task('scripts-view', ['lint-view'], function()
{
	return gulp.src(config.app + '/js/view/*.js')
		.pipe(rename({suffix: '.min'}))
		.pipe(uglify())
		.pipe(gulpif(isProduction, gulp.dest(config.dist + '/assets/js/view')))
		.pipe(gulpif(!isProduction, gulp.dest(config.dev + '/assets/js/view')))
		.pipe(gulpif(isProduction, refresh(livereload)));
});

gulp.task('scripts-ie', function()
{
	return gulp.src([
			'**/html5shiv.js',
			'**/nwmatcher-1.2.5.js',
			'**/selectivizr.js',
			'**/matchmedia.polyfill.js',
			'**/matchmedia.addListener.js',
			'**/respond.js'
		])
		.pipe(plumber())
		.pipe(concat('ie.min.js'))
		.pipe(uglify())
		.pipe(gulpif(isProduction, gulp.dest(config.dist + '/assets/js')))
		.pipe(gulpif(!isProduction, gulp.dest(config.dev + '/assets/js')))
		.pipe(gulpif(isProduction, refresh(livereload)));
});

// Images ---------------------------------------------------------------------
//

gulp.task('images', function()
{
	return gulp.src(config.app + '/images/**/*')
		.pipe(plumber())
		.pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))
		.pipe(gulpif(isProduction, gulp.dest(config.dist + '/assets/images')))
		.pipe(gulpif(!isProduction, gulp.dest(config.dev + 'dist/assets/images')))
		.pipe(gulpif(isProduction, refresh(livereload)));
});

// Fonts ----------------------------------------------------------------------
//

gulp.task('fonts', function()
{
    return gulp.src(config.app + '/fonts/*')
        .pipe(gulpif(isProduction, gulp.dest(config.dist + 'assets/fonts')))
        .pipe(gulpif(!isProduction, gulp.dest(config.dev + 'assets/fonts')));
});

// Misc -----------------------------------------------------------------------
//
 
gulp.task('misc', function()
{
    return gulp.src(config.app + '/misc/*')
        .pipe(gulpif(isProduction, gulp.dest(config.dist)))
        .pipe(gulpif(!isProduction, gulp.dest(config.dev)));
});

// HTML -----------------------------------------------------------------------
//
 
gulp.task('html', function()
{ 
    return gulp.src(config.app + '/html/*')
        .pipe(gulpif(isProduction, gulp.dest(config.dist)))
        .pipe(gulpif(!isProduction, gulp.dest(config.dev)));
});

// LiveReload -----------------------------------------------------------------
//

gulp.task('connect-livereload', function()
{
    var middleware = [
        require('connect-livereload')({ port: config.lr }),
        connect.static(config.app),
        connect.directory(config.app)
    ];

    var app = connect.apply(null, middleware);

    var server = http.createServer(app);

    server
        .listen(config.port)
        .on('listening', function() {
            console.log('Started connect web server on http://localhost:' + config.port + '.');

            open('http://localhost:' + config.port);
        });
});

gulp.task('tinylr', function()
{
    livereload.listen(config.lr, function(err){
        if (err) {
            return console.log(err);
        }
    });
});

gulp.task('server', ['sass', 'connect-livereload', 'tinylr'], function()
{
    console.log('Started watching assets folder..')

	gulp.watch(config.app + '/sass/*.scss', ['sass'], function(event)
	{
  		console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
	});

	gulp.watch(config.app + '/**/*.js', ['scripts', 'scripts-view', 'scripts-ie'], function(event)
	{
  		console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
  	});

	gulp.watch(config.app + '/images/**/*', ['images'], function(event)
	{
  		console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
  	});
	/*
	gulp.watch(config.app + '/html/*', ['html'], function(event)
	{
  		console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
  	});*/
});

// The default task -----------------------------------------------------------
//
// Runs when you call 'gulp' from the CLI

gulp.task('default', ['clean'], function()
{
	gulp.run('html', 'sass', 'fonts', 'misc', 'scripts-main', 'scripts-view', 'scripts-ie', 'images', 'server');
});


{'fraction_non_alphanumeric': 0.29058468755235384, 'fraction_numerical': 0.0054447981236388, 'mean_word_length': 2.254907306434024, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '1814188', 'n_tokens_mistral': 4332, 'n_tokens_neox': 4029, 'n_words': 686}