<commit_before>var	gulp = require( 'gulp' ),
	_ = require( 'underscore' );

var plugin =
{
	connect: require( 'gulp-connect' ),
	cssmin: require( 'gulp-cssmin' ),
	data: require( 'gulp-data' ),
	dom: require( 'gulp-dom' ),
	filter: require( 'gulp-filter' ),
	highlight: require( 'gulp-highlight' ),
	maps: require( 'gulp-sourcemaps' ),
	nunjucks: require( 'gulp-nunjucks-render' ),
	plumber: require( 'gulp-plumber' ),
	prefixer: require( 'gulp-autoprefixer' ),
	reload: require( 'gulp-livereload' ),
	rename: require('gulp-rename'),
	rjs: require( 'gulp-requirejs-optimize' ),
	sass: require( 'gulp-sass' ),
	watch: require( 'gulp-watch' )
};

var	source =
	{
		asset: './src/asset/',
		main: './src/main/'
	},
	destination =
	{
		asset: './dist/asset/',
		main: './dist/'
	};

gulp.task( 'default', [ 'assets', 'javascript', 'stylesheets', 'templates' ] );
gulp.task( 'develop', [ 'default', 'connect', 'watch' ] );

gulp.task( 'assets', function()
{
	gulp.src( source.asset + '*/**/*' )
		.pipe( plugin.plumber() )
		.pipe( gulp.dest( destination.asset ) )
		.pipe( plugin.reload() );

	gulp.src( source.asset + 'favicon.ico' )
		.pipe( plugin.plumber() )
		.pipe( gulp.dest( destination.main ) )
		.pipe( plugin.reload() );
} );

gulp.task( 'javascript', function()
{
	//plugin.rjs(
	//{
	//	baseUrl: source.main,
	//	name: 'main',
	//	out: 'main.js',
	//	paths:
	//	{
	//		jquery: '../asset/javascript/jquery-2.1.4'
	//	}
	//} )
	gulp.src( source.main + 'main.js' )
		.pipe( plugin.plumber() )
		.pipe( plugin.rjs(
		{
			baseUrl: source.main,
			name: 'main',
			out: 'main.js',
			paths:
			{
				jquery: '../lib/jquery-2.1.4'
			}
		} ) )
		.pipe( gulp.dest( destination.asset + '/javascript' ) )
		.pipe( plugin.reload() );
} );

gulp.task( 'stylesheets', function()
{
	gulp.src( source.main + 'main.sass' )
		.pipe( plugin.plumber() )
		.pipe( plugin.maps.init() )
		.pipe( plugin.sass( { indentedSyntax: true } ) )
		.pipe( plugin.prefixer() )
		.pipe( plugin.maps.write( '.' ) )
		.pipe( gulp.dest( destination.asset + '/stylesheet' ) )
		.pipe( plugin.filter( '*.css' ) )
		.pipe( plugin.rename( { suffix: '.min' } ) )
		.pipe( plugin.cssmin() )
		.pipe( gulp.dest( destination.asset + '/stylesheet' ) )
		.pipe( plugin.reload() );
} );

gulp.task( 'templates', function()
{
	var sitemap = require( './sitemap.json' );

	plugin.nunjucks.nunjucks.configure( [ source.main ] );

	gulp.src( source.main + '**/index.html' )
		.pipe( plugin.plumber() )
		.pipe( plugin.data(
		{
			find: function( id )
			{
				return _.find( sitemap, function( page ) { return page.id === id; } );
			},
			previous: function( current )
			{
				var i = _.indexOf( sitemap, current );

				if( i > 0 )
				{
					return sitemap[i - 1];
				}
			},
			next: function( current )
			{
				var i = _.indexOf( sitemap, current );

				if( i !== -1 && sitemap.length > i + 1 )
				{
					return sitemap[i + 1];
				}
			},
			sitemap: sitemap
		} ) )
		.pipe( plugin.nunjucks() )
		.pipe( plugin.dom( function()
		{
			var items = this.querySelectorAll( '[data-src]' );

			for( var i = 0; i < items.length; i++ )
			{
				var item = items[i];
					url = 'https://github.com/taig/scala-on-android/edit/master/src/main/' + item.getAttribute( 'data-src' );

				var a = this.createElement( 'a' );
				a.setAttribute( 'class', 'edit' );
				a.setAttribute( 'href', url );
				a.setAttribute( 'target', '_blank' );
				a.setAttribute( 'title', 'Edit on GitHub' );
				a.innerHTML = 'Edit';

				item.appendChild( a );
			}

			return this;
		} ) )
		.pipe( plugin.highlight() )
		.pipe( plugin.rename( function( path )
		{
			if( path.dirname.indexOf( 'page/' ) === 0 )
			{
				path.dirname = path.dirname.substr( 5 );
			}
		} ) )
		.pipe( gulp.dest( destination.main ) )
		.pipe( plugin.reload() );
} );

gulp.task( 'watch', function()
{
	plugin.reload.listen();

	plugin.watch( source.asset + '**/*', function() { gulp.start( 'assets' ); } );
	plugin.watch( source.main + '**/*.js', function() { gulp.start( 'javascript' ); } );
	plugin.watch( source.main + '**/*.{sass,scss}', function() { gulp.start( 'stylesheets' ); } );
	plugin.watch( source.main + '**/*.{html,md}', function() { gulp.start( 'templates' ); } );
} );

gulp.task( 'connect', function()
{
	plugin.connect.server(
	{
		root: destination.main,
		livereload: true
	} );
} );<commit_msg>Remove outdated r.js code<commit_after>var	gulp = require( 'gulp' ),
	_ = require( 'underscore' );

var plugin =
{
	connect: require( 'gulp-connect' ),
	cssmin: require( 'gulp-cssmin' ),
	data: require( 'gulp-data' ),
	dom: require( 'gulp-dom' ),
	filter: require( 'gulp-filter' ),
	highlight: require( 'gulp-highlight' ),
	maps: require( 'gulp-sourcemaps' ),
	nunjucks: require( 'gulp-nunjucks-render' ),
	plumber: require( 'gulp-plumber' ),
	prefixer: require( 'gulp-autoprefixer' ),
	reload: require( 'gulp-livereload' ),
	rename: require('gulp-rename'),
	rjs: require( 'gulp-requirejs-optimize' ),
	sass: require( 'gulp-sass' ),
	watch: require( 'gulp-watch' )
};

var	source =
	{
		asset: './src/asset/',
		main: './src/main/'
	},
	destination =
	{
		asset: './dist/asset/',
		main: './dist/'
	};

gulp.task( 'default', [ 'assets', 'javascript', 'stylesheets', 'templates' ] );
gulp.task( 'develop', [ 'default', 'connect', 'watch' ] );

gulp.task( 'assets', function()
{
	gulp.src( source.asset + '*/**/*' )
		.pipe( plugin.plumber() )
		.pipe( gulp.dest( destination.asset ) )
		.pipe( plugin.reload() );

	gulp.src( source.asset + 'favicon.ico' )
		.pipe( plugin.plumber() )
		.pipe( gulp.dest( destination.main ) )
		.pipe( plugin.reload() );
} );

gulp.task( 'javascript', function()
{
	gulp.src( source.main + 'main.js' )
		.pipe( plugin.plumber() )
		.pipe( plugin.rjs(
		{
			baseUrl: source.main,
			name: 'main',
			out: 'main.js',
			paths:
			{
				jquery: '../lib/jquery-2.1.4'
			}
		} ) )
		.pipe( gulp.dest( destination.asset + '/javascript' ) )
		.pipe( plugin.reload() );
} );

gulp.task( 'stylesheets', function()
{
	gulp.src( source.main + 'main.sass' )
		.pipe( plugin.plumber() )
		.pipe( plugin.maps.init() )
		.pipe( plugin.sass( { indentedSyntax: true } ) )
		.pipe( plugin.prefixer() )
		.pipe( plugin.maps.write( '.' ) )
		.pipe( gulp.dest( destination.asset + '/stylesheet' ) )
		.pipe( plugin.filter( '*.css' ) )
		.pipe( plugin.rename( { suffix: '.min' } ) )
		.pipe( plugin.cssmin() )
		.pipe( gulp.dest( destination.asset + '/stylesheet' ) )
		.pipe( plugin.reload() );
} );

gulp.task( 'templates', function()
{
	var sitemap = require( './sitemap.json' );

	plugin.nunjucks.nunjucks.configure( [ source.main ] );

	gulp.src( source.main + '**/index.html' )
		.pipe( plugin.plumber() )
		.pipe( plugin.data(
		{
			find: function( id )
			{
				return _.find( sitemap, function( page ) { return page.id === id; } );
			},
			previous: function( current )
			{
				var i = _.indexOf( sitemap, current );

				if( i > 0 )
				{
					return sitemap[i - 1];
				}
			},
			next: function( current )
			{
				var i = _.indexOf( sitemap, current );

				if( i !== -1 && sitemap.length > i + 1 )
				{
					return sitemap[i + 1];
				}
			},
			sitemap: sitemap
		} ) )
		.pipe( plugin.nunjucks() )
		.pipe( plugin.dom( function()
		{
			var items = this.querySelectorAll( '[data-src]' );

			for( var i = 0; i < items.length; i++ )
			{
				var item = items[i];
					url = 'https://github.com/taig/scala-on-android/edit/master/src/main/' + item.getAttribute( 'data-src' );

				var a = this.createElement( 'a' );
				a.setAttribute( 'class', 'edit' );
				a.setAttribute( 'href', url );
				a.setAttribute( 'target', '_blank' );
				a.setAttribute( 'title', 'Edit on GitHub' );
				a.innerHTML = 'Edit';

				item.appendChild( a );
			}

			return this;
		} ) )
		.pipe( plugin.highlight() )
		.pipe( plugin.rename( function( path )
		{
			if( path.dirname.indexOf( 'page/' ) === 0 )
			{
				path.dirname = path.dirname.substr( 5 );
			}
		} ) )
		.pipe( gulp.dest( destination.main ) )
		.pipe( plugin.reload() );
} );

gulp.task( 'watch', function()
{
	plugin.reload.listen();

	plugin.watch( source.asset + '**/*', function() { gulp.start( 'assets' ); } );
	plugin.watch( source.main + '**/*.js', function() { gulp.start( 'javascript' ); } );
	plugin.watch( source.main + '**/*.{sass,scss}', function() { gulp.start( 'stylesheets' ); } );
	plugin.watch( source.main + '**/*.{html,md}', function() { gulp.start( 'templates' ); } );
} );

gulp.task( 'connect', function()
{
	plugin.connect.server(
	{
		root: destination.main,
		livereload: true
	} );
} );<|endoftext|>


<commit_before>const gulp = require('gulp'),
  uglify = require('gulp-uglify'),
  rename = require('gulp-rename'),
  cleanCss = require('gulp-clean-css'),
  chmod = require('gulp-chmod'),
  clean = require('gulp-clean'),
  replace = require('gulp-replace')

gulp.task('demos:css', () => {
  return gulp.src('src/demos/*.css')
    .pipe(cleanCss())
    .pipe(rename({
      extname: '.min.css'
    }))
    .pipe(chmod(0o664))
    .pipe(gulp.dest('dist/demos'))
})

gulp.task('demos:assets', () => {
  return gulp.src([
    './node_modules/jquery/dist/jquery.js',
    './node_modules/zepto/src/zepto.js',
    './node_modules/zepto/src/event.js',
    './node_modules/zepto/src/data.js',
    './src/demos/analytics.js',
  ])
  .pipe(uglify())
  .pipe(rename({
    extname: '.min.js',
  }))
  .pipe(chmod(0o664))
  .pipe(gulp.dest('dist/demos/assets'))
})

gulp.task('demos:html', () => {
  return gulp.src('src/demos/*.html')
    .pipe(replace(/\.\.\/\.\.\/node_modules\/(?:jquery|zepto)\/(?:dist|src)\/(\w+)\.js/g, './assets/$1.min.js'))
    .pipe(replace('../tabbedcontent.', '../tabbedcontent.min.'))
    .pipe(replace('./analytics.', './assets/analytics.min.'))
    .pipe(replace('./demo.', './demo.min.'))
    .pipe(replace('./bootstrap.', './bootstrap.min.'))
    .pipe(gulp.dest('dist/demos'))
})

gulp.task('assets:js', () => {
  return gulp.src('src/tabbedcontent.js')
    .pipe(uglify({
      preserveComments: 'license'
    }))
    .pipe(rename({
      extname: '.min.js'
    }))
    .pipe(chmod(0o664))
    .pipe(gulp.dest('dist'))
})

gulp.task('clean', () => {
  return gulp
    .src(['dist/*'], { read: false })
    .pipe(clean())
})

gulp.task('assets', ['assets:js'], () => {
  return gulp.src('src/index.html')
    .pipe(replace('./tabbedcontent', './tabbedcontent.min'))
    .pipe(chmod(0o664))
    .pipe(gulp.dest('dist'))
})

gulp.task('demos', ['demos:css', 'demos:html', 'demos:assets'])
gulp.task('default', ['assets', 'demos'])
<commit_msg>Fixed demos<commit_after>const gulp = require('gulp'),
  uglify = require('gulp-uglify'),
  rename = require('gulp-rename'),
  cleanCss = require('gulp-clean-css'),
  chmod = require('gulp-chmod'),
  clean = require('gulp-clean'),
  replace = require('gulp-replace')

gulp.task('demos:css', () => {
  return gulp.src('src/demos/*.css')
    .pipe(cleanCss())
    .pipe(rename({
      extname: '.min.css'
    }))
    .pipe(chmod(0o664))
    .pipe(gulp.dest('dist/demos'))
})

gulp.task('demos:assets', () => {
  return gulp.src([
    './node_modules/jquery/dist/jquery.js',
    './node_modules/zepto/src/zepto.js',
    './node_modules/zepto/src/event.js',
    './node_modules/zepto/src/data.js',
    './src/demos/analytics.js',
  ])
  .pipe(uglify())
  .pipe(rename({
    extname: '.min.js',
  }))
  .pipe(chmod(0o664))
  .pipe(gulp.dest('dist/demos/assets'))
})

gulp.task('demos:html', () => {
  return gulp.src('src/demos/*.html')
    .pipe(replace(/\.\.\/\.\.\/node_modules\/(?:jquery|zepto)\/(?:dist|src)\/(\w+)\.js/g, './assets/$1.min.js'))
    .pipe(replace('../tabbedcontent.', './tabbedcontent.min.'))
    .pipe(replace('./analytics.', './assets/analytics.min.'))
    .pipe(replace('./demo.', './demo.min.'))
    .pipe(replace('./bootstrap.', './bootstrap.min.'))
    .pipe(gulp.dest('dist/demos'))
})

gulp.task('assets:js', () => {
  return gulp.src('src/tabbedcontent.js')
    .pipe(uglify({
      preserveComments: 'license'
    }))
    .pipe(rename({
      extname: '.min.js'
    }))
    .pipe(chmod(0o664))
    .pipe(gulp.dest('dist/demos'))
    .pipe(gulp.dest('dist'))
})

gulp.task('clean', () => {
  return gulp
    .src(['dist/*'], { read: false })
    .pipe(clean())
})

gulp.task('assets', ['assets:js'], () => {
  return gulp.src('src/index.html')
    .pipe(replace('./tabbedcontent', './tabbedcontent.min'))
    .pipe(chmod(0o664))
    .pipe(gulp.dest('dist'))
})

gulp.task('demos', ['demos:css', 'demos:html', 'demos:assets'])
gulp.task('default', ['assets', 'demos'])
<|endoftext|>


<commit_before>/*
 * Protein Features Viewer
 * https://github.com/ebi-uniprot/biojs-vis-proteinFeaturesViewer
 *
 * Copyright (c) 2014 Xavier Watkins
 * Licensed under the Apache 2 license.
 */

// browserify build config
var buildDir = "build";
var outputFile = "featuresviewer";

// packages
var gulp     = require('gulp');

// browser builds
var browserify = require('browserify');
var watchify = require('watchify');
var uglify = require('gulp-uglify');
var minifyCss = require('gulp-minify-css');

// testing
var mocha = require('gulp-mocha');
var mochaPhantomJS = require('gulp-mocha-phantomjs');
var env = require('gulp-env');

// code coverage
var istanbul = require('gulp-istanbul');

// code style
var jshint = require('gulp-jshint');

// gulp helper
var source = require('vinyl-source-stream'); // converts node streams into vinyl streams
var gzip = require('gulp-gzip');
var rename = require('gulp-rename');
var chmod = require('gulp-chmod');
var streamify = require('gulp-streamify'); // converts streams into buffers (legacy support for old plugins)
var watch = require('gulp-watch');

// path tools
var fs = require('fs');
var path = require('path');
var join = path.join;
var mkdirp = require('mkdirp');
var del = require('del');

// auto config
var outputFileMin = join(buildDir,outputFile + ".min.js");
var packageConfig = require('./package.json');

// a failing test breaks the whole build chain
gulp.task('build', ['build-browser', 'build-browser-gzip']);
gulp.task('default', ['lint', 'test', 'build']);

//test tasks
gulp.task('lint', function() {
    return gulp.src('./lib/*.js')
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

gulp.task('test', ['test-unit']);

gulp.task('test-unit', ['test-env'], function () {
    return gulp.src(['./src/**/*.js', './lib/**/*.js'])
        .pipe(istanbul())
        .pipe(istanbul.hookRequire())
        .on('finish', function() {
            gulp.src('./test/unit/**/*.js', {
                read: false
            })
                .pipe(mocha({
                    reporter: 'xunit-file'
                }))
                .pipe(istanbul.writeReports());
        });
});

gulp.task('test-env', ['init-test-reports'], function() {
    env({
        vars: {
            XUNIT_FILE: 'reports/TEST-FeaturesViewerTest.xml',
            LOG_XUNIT: true
        }
    });
});

gulp.task('init-test-reports', ['clean-test-reports'], function() {
    mkdirp('reports', function (err) {
        if (err) console.error(err)
    });
});

gulp.task('clean-test-reports', function(cb) {
    del(['reports'], cb);
});

gulp.task('test-dom', ['build-test'], function () {
    return gulp
    .src('test/index.html')
    .pipe(mochaPhantomJS());
});

// browserify debug
gulp.task('build-test',['init'], function() {
    var b = browserify({debug: true});
    b.add('./test/dom/index');
    return b.bundle()
        .pipe(source("test.js"))
        .pipe(chmod(644))
        .pipe(gulp.dest(buildDir));
});

gulp.task('test-watch', function() {
     gulp.watch(['./src/**/*.js','./lib/**/*.js', './test/**/*.js', './style/main.css'], ['test']);
});

//build tasks
// will remove everything in build
gulp.task('clean', function(cb) {
    del([buildDir], cb);
});

// just makes sure that the build dir exists
gulp.task('init', ['clean'], function() {
    mkdirp(buildDir, function (err) {
        if (err) console.error(err)
    });
});

gulp.task('copy-resources', ['init'], function() {
        gulp.src("./font/*.*")
                .pipe(gulp.dest(buildDir));
        return gulp.src("./style/*.css")
                .pipe(minifyCss({compatibility: 'ie8'}))
                .pipe(gulp.dest(buildDir));
});

// browserify debug
gulp.task('build-browser',['copy-resources'], function() {
    var b = browserify({debug: true,hasExports: true});
    exposeBundles(b);
    return b.bundle()
        .pipe(source(outputFile + ".js"))
        .pipe(chmod(644))
        .pipe(gulp.dest(buildDir));
});

// browserify min
gulp.task('build-browser-min',['copy-resources'], function() {
    var b = browserify({hasExports: true});
    exposeBundles(b);
    return b.bundle()
        .pipe(source(outputFile + ".min.js"))
        .pipe(chmod(644))
        .pipe(streamify(uglify()))
        .pipe(gulp.dest(buildDir));
});

gulp.task('build-browser-gzip', ['build-browser-min'], function() {
    return gulp.src(outputFileMin)
        .pipe(gzip({append: false, gzipOptions: { level: 9 }}))
        .pipe(rename(outputFile + ".min.gz.js"))
        .pipe(gulp.dest(buildDir));
});

// exposes the main package
// + checks the config whether it should expose other packages
function exposeBundles(b){
    b.add("./" + packageConfig.main, {expose: packageConfig.name });
    if(packageConfig.sniper !== undefined && packageConfig.sniper.exposed !== undefined){
        for(var i=0; i<packageConfig.sniper.exposed.length; i++){
            b.require(packageConfig.sniper.exposed[i]);
        }
    }
}

// watch task for browserify
// watchify has an internal cache -> subsequent builds are faster
gulp.task('watch', ['copy-resources'], function() {
    var util = require('gulp-util');

    var b = browserify({debug: true,hasExports: true, cache: {}, packageCache: {} });
    b.add("./" + packageConfig.main, {expose: packageConfig.name});
    // expose other bundles
    exposeBundles(b);

    function rebundle(ids){
        b.bundle()
        .on("error", function(error) {
            util.log(util.colors.red("Error: "), error);
         })
        .pipe(source(outputFile + ".js"))
        .pipe(chmod(644))
        .pipe(gulp.dest(buildDir));
    }

    var watcher = watchify(b);
    watcher.on("update", rebundle)
     .on("log", function(message) {
            util.log("Refreshed:", message);
    });
    return rebundle();
});
<commit_msg>Revert "Revert "Phantom tests back on""<commit_after>/*
 * Protein Features Viewer
 * https://github.com/ebi-uniprot/biojs-vis-proteinFeaturesViewer
 *
 * Copyright (c) 2014 Xavier Watkins
 * Licensed under the Apache 2 license.
 */

// browserify build config
var buildDir = "build";
var outputFile = "featuresviewer";

// packages
var gulp     = require('gulp');

// browser builds
var browserify = require('browserify');
var watchify = require('watchify');
var uglify = require('gulp-uglify');
var minifyCss = require('gulp-minify-css');

// testing
var mocha = require('gulp-mocha');
var mochaPhantomJS = require('gulp-mocha-phantomjs');
var env = require('gulp-env');

// code coverage
var istanbul = require('gulp-istanbul');

// code style
var jshint = require('gulp-jshint');

// gulp helper
var source = require('vinyl-source-stream'); // converts node streams into vinyl streams
var gzip = require('gulp-gzip');
var rename = require('gulp-rename');
var chmod = require('gulp-chmod');
var streamify = require('gulp-streamify'); // converts streams into buffers (legacy support for old plugins)
var watch = require('gulp-watch');

// path tools
var fs = require('fs');
var path = require('path');
var join = path.join;
var mkdirp = require('mkdirp');
var del = require('del');

// auto config
var outputFileMin = join(buildDir,outputFile + ".min.js");
var packageConfig = require('./package.json');

// a failing test breaks the whole build chain
gulp.task('build', ['build-browser', 'build-browser-gzip']);
gulp.task('default', ['lint', 'test', 'build']);

//test tasks
gulp.task('lint', function() {
    return gulp.src('./lib/*.js')
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

gulp.task('test', ['test-unit','test-dom']);

gulp.task('test-unit', ['test-env'], function () {
    return gulp.src(['./src/**/*.js', './lib/**/*.js'])
        .pipe(istanbul())
        .pipe(istanbul.hookRequire())
        .on('finish', function() {
            gulp.src('./test/unit/**/*.js', {
                read: false
            })
                .pipe(mocha({
                    reporter: 'xunit-file'
                }))
                .pipe(istanbul.writeReports());
        });
});

gulp.task('test-env', ['init-test-reports'], function() {
    env({
        vars: {
            XUNIT_FILE: 'reports/TEST-FeaturesViewerTest.xml',
            LOG_XUNIT: true
        }
    });
});

gulp.task('init-test-reports', ['clean-test-reports'], function() {
    mkdirp('reports', function (err) {
        if (err) console.error(err)
    });
});

gulp.task('clean-test-reports', function(cb) {
    del(['reports'], cb);
});

gulp.task('test-dom', ['build-test'], function () {
    return gulp
    .src('test/index.html')
    .pipe(mochaPhantomJS());
});

// browserify debug
gulp.task('build-test',['init'], function() {
    var b = browserify({debug: true});
    b.add('./test/dom/index');
    return b.bundle()
        .pipe(source("test.js"))
        .pipe(chmod(644))
        .pipe(gulp.dest(buildDir));
});

gulp.task('test-watch', function() {
     gulp.watch(['./src/**/*.js','./lib/**/*.js', './test/**/*.js', './style/main.css'], ['test']);
});

//build tasks
// will remove everything in build
gulp.task('clean', function(cb) {
    del([buildDir], cb);
});

// just makes sure that the build dir exists
gulp.task('init', ['clean'], function() {
    mkdirp(buildDir, function (err) {
        if (err) console.error(err)
    });
});

gulp.task('copy-resources', ['init'], function() {
        gulp.src("./font/*.*")
                .pipe(gulp.dest(buildDir));
        return gulp.src("./style/*.css")
                .pipe(minifyCss({compatibility: 'ie8'}))
                .pipe(gulp.dest(buildDir));
});

// browserify debug
gulp.task('build-browser',['copy-resources'], function() {
    var b = browserify({debug: true,hasExports: true});
    exposeBundles(b);
    return b.bundle()
        .pipe(source(outputFile + ".js"))
        .pipe(chmod(644))
        .pipe(gulp.dest(buildDir));
});

// browserify min
gulp.task('build-browser-min',['copy-resources'], function() {
    var b = browserify({hasExports: true});
    exposeBundles(b);
    return b.bundle()
        .pipe(source(outputFile + ".min.js"))
        .pipe(chmod(644))
        .pipe(streamify(uglify()))
        .pipe(gulp.dest(buildDir));
});

gulp.task('build-browser-gzip', ['build-browser-min'], function() {
    return gulp.src(outputFileMin)
        .pipe(gzip({append: false, gzipOptions: { level: 9 }}))
        .pipe(rename(outputFile + ".min.gz.js"))
        .pipe(gulp.dest(buildDir));
});

// exposes the main package
// + checks the config whether it should expose other packages
function exposeBundles(b){
    b.add("./" + packageConfig.main, {expose: packageConfig.name });
    if(packageConfig.sniper !== undefined && packageConfig.sniper.exposed !== undefined){
        for(var i=0; i<packageConfig.sniper.exposed.length; i++){
            b.require(packageConfig.sniper.exposed[i]);
        }
    }
}

// watch task for browserify
// watchify has an internal cache -> subsequent builds are faster
gulp.task('watch', ['copy-resources'], function() {
    var util = require('gulp-util');

    var b = browserify({debug: true,hasExports: true, cache: {}, packageCache: {} });
    b.add("./" + packageConfig.main, {expose: packageConfig.name});
    // expose other bundles
    exposeBundles(b);

    function rebundle(ids){
        b.bundle()
        .on("error", function(error) {
            util.log(util.colors.red("Error: "), error);
         })
        .pipe(source(outputFile + ".js"))
        .pipe(chmod(644))
        .pipe(gulp.dest(buildDir));
    }

    var watcher = watchify(b);
    watcher.on("update", rebundle)
     .on("log", function(message) {
            util.log("Refreshed:", message);
    });
    return rebundle();
});
<|endoftext|>


<commit_before>var gulp = require('gulp');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var source = require('vinyl-source-stream');
var browserify = require('browserify');
var evstream = require('event-stream');
var cleanCSS = require('gulp-clean-css');
var nodemon = require('gulp-nodemon');
var path = require('path');

gulp.task('start', function() {
    nodemon({
        script: 'server.js',
        ignore: '*.*'
    });
})

gulp.task('watch', function () {
    nodemon({
        script: 'server.js',
        ext: 'js html css',
        env: {'NODE_ENV': 'dev'},
        watch: [
            'app/',
            'config/'
        ],
        tasks: function (changedFiles) {
            var tasks = [];
            changedFiles.forEach(function (file) {
                if (path.extname(file) === '.js' && !~tasks.indexOf('minjs'))
                    tasks.push('minjs');
                if (path.extname(file) === '.css' && !~tasks.indexOf('mincss'))
                    tasks.push('mincss');
            });
            return tasks;
        }
    }).on('restart?', function () {
        gulp.start('default');
    });
});

gulp.task('default', function () {
    gulp.start('minjs');
    gulp.start('mincss');
});

gulp.task('mincss', function () {
    var files = [
        {
            src: 'app/public/css/form.css',
            name: 'form.min.css'
        },
        {
            src: 'app/public/css/home.css',
            name: 'home.min.css'
        },
        {
            src: 'app/public/css/panel.css',
            name: 'panel.min.css'
        },
        {
            src: 'app/public/css/index.css',
            name: 'index.min.css'
        }
    ];

    var tasks = files.map(function (entry) {
        return gulp.src(entry.src)
            .pipe(cleanCSS())
            .pipe(rename(entry.name))
            .pipe(gulp.dest('public/css'));
    });

    return evstream.merge.apply(null, tasks);
})

gulp.task('minjs', function () {
    gulp.start('concatjs');
    gulp.start('browserify');
});

gulp.task('concatjs', function () {
    var files = [
        {
            src: [
                'app/public/services/*.js',
                'app/public/panel/**/*.js'
            ],
            name: 'panel.min.js'
        },
        {
            src: [
                'app/public/services/*.js',
                'app/public/shimapan/**/*.js'
            ],
            name: 'shimapan.min.js'
        },
        {
            src: 'app/public/index/*.js',
            name: 'index.min.js'
        }
    ];

    var tasks = files.map(function (entry) {
        return gulp.src(entry.src)
            .pipe(concat(entry.name))
            .pipe(uglify())
            .pipe(gulp.dest('public/js'));
    });

    return evstream.merge.apply(null, tasks);
})

gulp.task('browserify', ['concatjs'], function () {
    var files = [
        {
            src: 'public/js/shimapan.min.js',
            name: 'shimapan.bundle.js'
        },
        {
            src: 'public/js/panel.min.js',
            name: 'panel.bundle.js'
        }
    ];

    var tasks = files.map(function (entry) {
        return browserify({entries: [entry.src]})
            .bundle()
            .pipe(source(entry.src))
            .pipe(rename(entry.name))
            .pipe(gulp.dest('public/js'));
    });

    return evstream.merge.apply(null, tasks);
});
<commit_msg>Add minify error logging to gulpfile<commit_after>var gulp = require('gulp');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var source = require('vinyl-source-stream');
var browserify = require('browserify');
var evstream = require('event-stream');
var cleanCSS = require('gulp-clean-css');
var nodemon = require('gulp-nodemon');
var path = require('path');

gulp.task('start', function() {
    nodemon({
        script: 'server.js',
        ignore: '*.*'
    });
})

gulp.task('watch', function () {
    nodemon({
        script: 'server.js',
        ext: 'js html css',
        env: {'NODE_ENV': 'dev'},
        watch: [
            'app/',
            'config/'
        ],
        tasks: function (changedFiles) {
            var tasks = [];
            changedFiles.forEach(function (file) {
                if (path.extname(file) === '.js' && !~tasks.indexOf('minjs'))
                    tasks.push('minjs');
                if (path.extname(file) === '.css' && !~tasks.indexOf('mincss'))
                    tasks.push('mincss');
            });
            return tasks;
        }
    }).on('restart?', function () {
        gulp.start('default');
    });
});

gulp.task('default', function () {
    gulp.start('minjs');
    gulp.start('mincss');
});

gulp.task('mincss', function () {
    var files = [
        {
            src: 'app/public/css/form.css',
            name: 'form.min.css'
        },
        {
            src: 'app/public/css/home.css',
            name: 'home.min.css'
        },
        {
            src: 'app/public/css/panel.css',
            name: 'panel.min.css'
        },
        {
            src: 'app/public/css/index.css',
            name: 'index.min.css'
        }
    ];

    var tasks = files.map(function (entry) {
        return gulp.src(entry.src)
            .pipe(cleanCSS())
            .pipe(rename(entry.name))
            .pipe(gulp.dest('public/css'));
    });

    return evstream.merge.apply(null, tasks);
})

gulp.task('minjs', function () {
    gulp.start('concatjs');
    gulp.start('browserify');
});

gulp.task('concatjs', function () {
    var files = [
        {
            src: [
                'app/public/services/*.js',
                'app/public/panel/**/*.js'
            ],
            name: 'panel.min.js'
        },
        {
            src: [
                'app/public/services/*.js',
                'app/public/shimapan/**/*.js'
            ],
            name: 'shimapan.min.js'
        },
        {
            src: 'app/public/index/*.js',
            name: 'index.min.js'
        }
    ];

    var tasks = files.map(function (entry) {
        return gulp.src(entry.src)
            .pipe(concat(entry.name))
            .pipe(uglify().on('error', function(err) {
                console.log(err.toString());
            }))
            .pipe(gulp.dest('public/js'));
    });

    return evstream.merge.apply(null, tasks);
})

gulp.task('browserify', ['concatjs'], function () {
    var files = [
        {
            src: 'public/js/shimapan.min.js',
            name: 'shimapan.bundle.js'
        },
        {
            src: 'public/js/panel.min.js',
            name: 'panel.bundle.js'
        }
    ];

    var tasks = files.map(function (entry) {
        return browserify({entries: [entry.src]})
            .bundle()
            .pipe(source(entry.src))
            .pipe(rename(entry.name))
            .pipe(gulp.dest('public/js'));
    });

    return evstream.merge.apply(null, tasks);
});
<|endoftext|>


<commit_before>var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var path = require('path');
var replace = require('gulp-replace-task');

var lessDir = './www/less';
var lessFiles = path.join(lessDir, '*', '**');
var lessMainFile = path.join(lessDir, 'main.less');
var buildDir = './www/build';
var jsDir = './www/js';
var jsFiles = [
	path.join(jsDir, 'app.js'),
	path.join(jsDir, 'services/*.js'),
	path.join(jsDir, 'snippets/*.js'),
	path.join(jsDir, 'components/controls/*.js'),
	path.join(jsDir, 'components/forms/*.js')
];

gulp.task('dev', function () {
	gulp.src(lessMainFile)
		.pipe($.sourcemaps.init())
		.pipe($.less())
		.pipe($.autoprefixer())
		.pipe($.rename({suffix: '.min'}))
		.pipe($.sourcemaps.write('.', {
			sourceRoot: '../less'
		}))
		.pipe(gulp.dest(buildDir));

	gulp.src(jsFiles)
		.pipe($.sourcemaps.init())
		.pipe($.uglify())
		.pipe($.concat('app.min.js'))
		.pipe(replace({
			patterns: [{
				json: {
					domain: {
						elastic: 'http://localhost:9200'
					}
				}
			}]
		}))
		.pipe($.sourcemaps.write('.', {
			sourceRoot: '../js'
		}))
		.pipe(gulp.dest(buildDir));
	//.pipe($.livereload());
});

gulp.task('production', function () {
	gulp.src(lessMainFile)
		.pipe($.less())
		.pipe($.autoprefixer())
		.pipe($.cssmin())
		.pipe($.rename({suffix: '.min'}))
		.pipe(gulp.dest(buildDir));
});

gulp.task('default', function() {
	gulp.start('dev');
});

gulp.task('watch', ['less'], function() {
	//Watch changes (less, )
	$.watch('www/less/**.less', ['less']);
	$.watch('www/less/**/**.less', ['less']);
	$.watch('*.html', ['less']);
});
<commit_msg>add js to production build<commit_after>var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var path = require('path');
var replace = require('gulp-replace-task');

var lessDir = './www/less';
var lessFiles = path.join(lessDir, '*', '**');
var lessMainFile = path.join(lessDir, 'main.less');
var buildDir = './www/build';
var jsDir = './www/js';
var jsFiles = [
	path.join(jsDir, 'app.js'),
	path.join(jsDir, 'services/*.js'),
	path.join(jsDir, 'snippets/*.js'),
	path.join(jsDir, 'components/controls/*.js'),
	path.join(jsDir, 'components/forms/*.js')
];

gulp.task('dev', function () {
	gulp.src(lessMainFile)
		.pipe($.sourcemaps.init())
		.pipe($.less())
		.pipe($.autoprefixer())
		.pipe($.rename({suffix: '.min'}))
		.pipe($.sourcemaps.write('.', {
			sourceRoot: '../less'
		}))
		.pipe(gulp.dest(buildDir));

	gulp.src(jsFiles)
		.pipe($.sourcemaps.init())
		.pipe($.uglify())
		.pipe($.concat('app.min.js'))
		.pipe(replace({
			patterns: [{
				json: {
					domain: {
						elastic: 'http://localhost:9200'
					}
				}
			}]
		}))
		.pipe($.sourcemaps.write('.', {
			sourceRoot: '../js'
		}))
		.pipe(gulp.dest(buildDir));
});

gulp.task('production', function () {
	gulp.src(lessMainFile)
		.pipe($.less())
		.pipe($.autoprefixer())
		.pipe($.cssmin())
		.pipe($.rename({suffix: '.min'}))
		.pipe(gulp.dest(buildDir));

	gulp.src(jsFiles)
		.pipe($.uglify())
		.pipe($.concat('app.min.js'))
		.pipe(replace({
			patterns: [{
				json: {
					domain: {
						elastic: 'https://elastic.khanovaskola.cz'
					}
				}
			}]
		}))
		.pipe(gulp.dest(buildDir));
});

gulp.task('default', function() {
	gulp.start('dev');
});

gulp.task('watch', ['less'], function() {
	//Watch changes (less, )
	$.watch('www/less/**.less', ['less']);
	$.watch('www/less/**/**.less', ['less']);
	$.watch('*.html', ['less']);
});
<|endoftext|>


<commit_before>/**
 * gulp list
 * gulp init --app myd8site
 * gulp start --app myd8site
 * gulp stop --app myd8site
 * gulp restart --app myd8site
 * gulp kill --app myd8site
 * gulp remove --app myd8site
 * gulp pull-images --app myd8site
 * gulp build-images --app myd8site
 */
var _ = require('lodash');
var gulp = require('gulp');
var gutil = require('gulp-util');
var fs = require('fs');
var path = require('path');
var am = require('./lib/appmanager.js');

var appname = gutil.env.app ? gutil.env.app : null;
if (appname) {
  try {
    var app = new am.App(appname);
  }
  catch (err) {
    throw err;
  }
}

gulp.task('list', function() {
  var apps = am.getApps();
  var i = 1;
  gutil.log(' ');
  gutil.log('Kalabox Apps:');
  for (var x in apps) {
    gutil.log('  ', i + ')', apps[x].config.name);
    i++;
  }
  gutil.log(' ');
});

// Creates app containers
gulp.task('init', ['build-images', 'pull-images'], function() {
  return app.init();
});

gulp.task('start', function() {
  gutil.log('Starting', appname);
  app.start();
});

gulp.task('stop', function() {
  gutil.log('Stopping', appname);
  app.stop();
});

gulp.task('restart', function() {
  gutil.log('Restarting', appname);
  app.restart();
});

gulp.task('kill', function() {
  gutil.log('Killing', appname);
  app.kill();
});

gulp.task('remove', function() {
  gutil.log('Removing', appname);
  app.remove();
});

gulp.task('pull-images', function() {
  gutil.log('Pulling images for', appname);
  return app.pull();
});

gulp.task('build-images', function(done) {
  gutil.log('Building images for', appname);
  return app.build(done);
});<commit_msg>changed pull/build-image to just pull/build<commit_after>/**
 * gulp list
 * gulp init --app myd8site
 * gulp start --app myd8site
 * gulp stop --app myd8site
 * gulp restart --app myd8site
 * gulp kill --app myd8site
 * gulp remove --app myd8site
 * gulp pull --app myd8site
 * gulp build --app myd8site
 */
var _ = require('lodash');
var gulp = require('gulp');
var gutil = require('gulp-util');
var fs = require('fs');
var path = require('path');
var am = require('./lib/appmanager.js');

var appname = gutil.env.app ? gutil.env.app : null;
if (appname) {
  try {
    var app = new am.App(appname);
  }
  catch (err) {
    throw err;
  }
}

gulp.task('list', function() {
  var apps = am.getApps();
  var i = 1;
  gutil.log(' ');
  gutil.log('Kalabox Apps:');
  for (var x in apps) {
    gutil.log('  ', i + ')', apps[x].config.name);
    i++;
  }
  gutil.log(' ');
});

// Creates app containers
gulp.task('init', ['build', 'pull'], function() {
  return app.init();
});

gulp.task('start', function() {
  gutil.log('Starting', appname);
  app.start();
});

gulp.task('stop', function() {
  gutil.log('Stopping', appname);
  app.stop();
});

gulp.task('restart', function() {
  gutil.log('Restarting', appname);
  app.restart();
});

gulp.task('kill', function() {
  gutil.log('Killing', appname);
  app.kill();
});

gulp.task('remove', function() {
  gutil.log('Removing', appname);
  app.remove();
});

gulp.task('pull', function() {
  gutil.log('Pulling images for', appname);
  return app.pull();
});

gulp.task('build', function(done) {
  gutil.log('Building images for', appname);
  return app.build(done);
});<|endoftext|>


<commit_before>/*jslint node: true */
"use strict";

var gulp = require('gulp');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');

gulp.task('lint', function() {
  return gulp.src('*.js')
    .pipe(jshint())
    .pipe(jshint.reporter(stylish));
});

gulp.task('default', ['lint']);
<commit_msg>Add my jshint options.<commit_after>/*jslint node: true */
"use strict";

var gulp = require('gulp');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');

gulp.task('lint', function() {
  return gulp.src(['*.js', 'test/*.js'])
        .pipe(jshint({
            laxcomma: true
            , strict: true
            , globals: { 'require': false
                         , 'describe': false
                         , 'it': false
                         , 'exports': false
                         , 'before': false
                       }
        }))
    .pipe(jshint.reporter(stylish));
});

gulp.task('default', ['lint']);
<|endoftext|>


<commit_before>// Include gulp
var gulp = require('gulp');

var outputDir = './';

// Include Our Plugins
var jshint = require('gulp-jshint')
  , templateCache = require('gulp-angular-templatecache')
  , sass = require('gulp-sass')
  , uglify = require('gulp-uglify')
  , clean = require('gulp-clean')
  , connect = require('gulp-connect')
  , usemin = require('gulp-usemin')
  , minifyHtml = require('gulp-minify-html')
  , minifyCss = require('gulp-minify-css')
  , ngAnnotate = require('gulp-ng-annotate')
  , rev = require('gulp-rev')
  , imagemin = require('gulp-imagemin')
  , pngcrush = require('imagemin-pngcrush');

gulp.task('lint', function() {
  'use strict';
  return gulp.src('./js/*.js')
    .pipe(jshint())
    .pipe(jshint.reporter('default'));
});

gulp.task('sass', ['lint'], function() {
  'use strict';
  return gulp.src('./scss/*.scss')
    .pipe(sass())
    .pipe(gulp.dest('css'));
});

gulp.task('clean', ['sass'], function() {
  'use strict';
  return gulp.src(['dist/*'], {read: false})
    .pipe(clean());
});

gulp.task('copy', ['clean'], function() {
  'use strict';
  var filesToCopy = [
    './fonts/**/*.*',
    './js/iebs/**/*.*.'
  ];
  return gulp.src(filesToCopy, { base: './' })
    .pipe(gulp.dest('dist'));
});

gulp.task('image', ['copy'], function() {
  'use strict';
  return gulp.src('./images/*')
    .pipe(imagemin({
      progressive: true,
      svgoPlugins: [
        {removeViewBox: false}
      ],
      use: [pngcrush()]
    }))
    .pipe(gulp.dest('dist/images'));
});

gulp.task('predist1', ['image'], function() {
  'use strict';
  return gulp.src(['./views/*.html'])
    .pipe(templateCache('templates.js', {
      root: './views/',
      module: 'app'
    }))
    .pipe(gulp.dest('js/'));
});

gulp.task('predist2', ['predist1'], function() {
  'use strict';
  return gulp.src('./*.html')
    .pipe(usemin({
      css: [minifyCss(), 'concat'],
      html: [minifyHtml({empty: true})],
      js: [ngAnnotate(), uglify(), rev()]
    }))
    .pipe(gulp.dest('dist/'));
});

gulp.task('dist', ['predist2'], function() {
  'use strict';
  var fs = require('fs');
  fs.writeFile('js/templates.js', '/* MOCK FILE - Used by gulp build process to store compiled AngularJS view templates */\n(function() {\n  "use strict";\n})();');
});

gulp.task('reload', function() {
  'use strict';
  return gulp.src('*')
    .pipe(connect.reload());
});

gulp.task('watch', function() {
  'use strict';
  gulp.watch('./scss/*.scss', ['sass', 'reload']);
  gulp.watch('./index.html', ['reload']);
  gulp.watch('./views/**/*.html', ['reload']);
  gulp.watch('./js/**/*.js', ['reload']);
});

gulp.task('connect', function() {
  'use strict';
  return connect.server({
    root: [outputDir],
    port: 8080, // optional
    livereload: true
  });
});

gulp.task('default', ['watch', 'connect']);
<commit_msg>Fix to remove gulp-connect errors users are seeing.<commit_after>// Include gulp
var gulp = require('gulp');

// Include Our Plugins
var jshint = require('gulp-jshint')
  , templateCache = require('gulp-angular-templatecache')
  , sass = require('gulp-sass')
  , uglify = require('gulp-uglify')
  , clean = require('gulp-clean')
  , connect = require('gulp-connect')
  , usemin = require('gulp-usemin')
  , minifyHtml = require('gulp-minify-html')
  , minifyCss = require('gulp-minify-css')
  , ngAnnotate = require('gulp-ng-annotate')
  , rev = require('gulp-rev')
  , imagemin = require('gulp-imagemin')
  , pngcrush = require('imagemin-pngcrush');

gulp.task('lint', function() {
  'use strict';
  return gulp.src('./js/*.js')
    .pipe(jshint())
    .pipe(jshint.reporter('default'));
});

gulp.task('sass', ['lint'], function() {
  'use strict';
  return gulp.src('./scss/*.scss')
    .pipe(sass())
    .pipe(gulp.dest('css'));
});

gulp.task('clean', ['sass'], function() {
  'use strict';
  return gulp.src(['dist/*'], {read: false})
    .pipe(clean());
});

gulp.task('copy', ['clean'], function() {
  'use strict';
  var filesToCopy = [
    './fonts/**/*.*',
    './js/iebs/**/*.*.'
  ];
  return gulp.src(filesToCopy, { base: './' })
    .pipe(gulp.dest('dist'));
});

gulp.task('image', ['copy'], function() {
  'use strict';
  return gulp.src('./images/*')
    .pipe(imagemin({
      progressive: true,
      svgoPlugins: [
        {removeViewBox: false}
      ],
      use: [pngcrush()]
    }))
    .pipe(gulp.dest('dist/images'));
});

gulp.task('predist1', ['image'], function() {
  'use strict';
  return gulp.src(['./views/*.html'])
    .pipe(templateCache('templates.js', {
      root: './views/',
      module: 'app'
    }))
    .pipe(gulp.dest('js/'));
});

gulp.task('predist2', ['predist1'], function() {
  'use strict';
  return gulp.src('./*.html')
    .pipe(usemin({
      css: [minifyCss(), 'concat'],
      html: [minifyHtml({empty: true})],
      js: [ngAnnotate(), uglify(), rev()]
    }))
    .pipe(gulp.dest('dist/'));
});

gulp.task('dist', ['predist2'], function() {
  'use strict';
  var fs = require('fs');
  fs.writeFile('js/templates.js', '/* MOCK FILE - Used by gulp build process to store compiled AngularJS view templates */\n(function() {\n  "use strict";\n})();');
});

gulp.task('reload', function() {
  'use strict';
  return gulp.src('*')
    .pipe(connect.reload());
});

gulp.task('watch', function() {
  'use strict';
  gulp.watch('./scss/*.scss', ['sass', 'reload']);
  gulp.watch('./index.html', ['reload']);
  gulp.watch('./views/**/*.html', ['reload']);
  gulp.watch('./js/**/*.js', ['reload']);
});

gulp.task('connect', function() {
  'use strict';
  return connect.server({
    port: 8080, // optional
    livereload: true
  });
});

gulp.task('default', ['watch', 'connect']);
<|endoftext|>


<commit_before>var gulp = require('gulp');
var jshintStylish = require('jshint-stylish');
var gutil = require('gulp-util'); // Currently unused, but gulp strongly suggested I install...
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');
var replace = require('gulp-replace');

var jsHintOptions = {
	"nonbsp": true,
	"nonew": true,
	"noarg": true,
	"loopfunc": true,
	"latedef": 'nofunc',

	"freeze": true,
	"immed": true,
	"undef": true,

	// style
	"smarttabs": true,
	"trailing": true,
	"newcap": true,

	"sub": true,
	"evil": true,
	"esnext": true,
	"node": true,
	"eqeqeq": true,

	"globals": {
		"Config": false,
		"ResourceMonitor": false,
		"toId": false,
		"toName": false,
		"string": false,
		"LoginServer": false,
		"Users": false,
		"Rooms": false,
		"Verifier": false,
		"CommandParser": false,
		"Simulator": false,
		"Tournaments": false,
		"Dnsbl": false,
		"Cidr": false,
		"Sockets": false,
		"Tools": false,
		"TeamValidator": false
	}
};

var jscsOptions = {
	"excludeFiles": ["./**/pokedex.js", "./**/formats-data.js", "./**/learnsets.js", "./**/learnsets-g6.js", "./config/config.js"],

	"preset": "google",

	"requireCurlyBraces": null,
	"requireCamelCaseOrUpperCaseIdentifiers": null,
	"maximumLineLength": null,
	"validateIndentation": "\t",
	"validateQuoteMarks": null,

	"disallowMixedSpacesAndTabs": "smart",
	"disallowMultipleVarDecl": null,

	"requireSpaceAfterKeywords": true,
	"requireSpaceBeforeBinaryOperators": true,
	"disallowSpacesInAnonymousFunctionExpression": null,
	"requireSpacesInAnonymousFunctionExpression": {
		"beforeOpeningRoundBrace": true
	},

	"validateJSDoc": null,

	"requireBlocksOnNewline": 1,
	"disallowPaddingNewlinesInBlocks": true,
	"disallowEmptyBlocks": true,
	"disallowNewlineBeforeBlockStatements": true,

	"requireCommaBeforeLineBreak": true,
	"requireOperatorBeforeLineBreak": true,

	"disallowSpaceAfterObjectKeys": true,
	"disallowSpaceAfterPrefixUnaryOperators": true,
	"disallowSpaceBeforePostfixUnaryOperators": true,

	"disallowTrailingComma": true,
	"validateLineBreaks": require('os').EOL.replace(/\r/g, 'CR').replace(/\n/g, 'LF'),
	"validateParameterSeparator": ", ",

	"requireCapitalizedConstructors": true
};

gulp.task('data', function () {
	var directories = ['./data/*.js', './mods/*/*.js'];
	jsHintOptions['es3'] = true;

	// Replacing `var` with `let` is sort of a hack that stops jsHint from
	// complaining that I'm using `var` like `let` should be used, but
	// without having to deal with iffy `let` support.

	return gulp.src(directories)
		.pipe(jscs(jscsOptions))
		.pipe(replace(/\bvar\b/g, 'let'))
		.pipe(jshint(jsHintOptions))
		.pipe(jshint.reporter(jshintStylish))
		.pipe(jshint.reporter('fail'))
		.pipe(jscs(jscsOptions));
});

gulp.task('fastlint', function () {
	var directories = ['./*.js', './tournaments/*.js', './chat-plugins/*.js', './config/*.js'];
	delete jsHintOptions['es3'];

	return gulp.src(directories)
		.pipe(jscs(jscsOptions))
		.pipe(replace(/\bvar\b/g, 'let'))
		.pipe(jshint(jsHintOptions))
		.pipe(jshint.reporter(jshintStylish))
		.pipe(jshint.reporter('fail'));
});

gulp.task('default', ['fastlint', 'data']);
gulp.task('lint', ['fastlint', 'data']);
<commit_msg>Gulpfile: Remove let hack<commit_after>var gulp = require('gulp');
var jshintStylish = require('jshint-stylish');
var gutil = require('gulp-util'); // Currently unused, but gulp strongly suggested I install...
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');
var replace = require('gulp-replace');

var jsHintOptions = {
	"nonbsp": true,
	"nonew": true,
	"noarg": true,
	"loopfunc": true,
	"latedef": 'nofunc',

	"freeze": true,
	"immed": true,
	"undef": true,

	// style
	"smarttabs": true,
	"trailing": true,
	"newcap": true,

	"sub": true,
	"evil": true,
	"esnext": true,
	"node": true,
	"eqeqeq": true,

	"globals": {
		"Config": false,
		"ResourceMonitor": false,
		"toId": false,
		"toName": false,
		"string": false,
		"LoginServer": false,
		"Users": false,
		"Rooms": false,
		"Verifier": false,
		"CommandParser": false,
		"Simulator": false,
		"Tournaments": false,
		"Dnsbl": false,
		"Cidr": false,
		"Sockets": false,
		"Tools": false,
		"TeamValidator": false
	}
};

var jscsOptions = {
	"excludeFiles": ["./**/pokedex.js", "./**/formats-data.js", "./**/learnsets.js", "./**/learnsets-g6.js", "./config/config.js"],

	"preset": "google",

	"requireCurlyBraces": null,
	"requireCamelCaseOrUpperCaseIdentifiers": null,
	"maximumLineLength": null,
	"validateIndentation": "\t",
	"validateQuoteMarks": null,

	"disallowMixedSpacesAndTabs": "smart",
	"disallowMultipleVarDecl": null,

	"requireSpaceAfterKeywords": true,
	"requireSpaceBeforeBinaryOperators": true,
	"disallowSpacesInAnonymousFunctionExpression": null,
	"requireSpacesInAnonymousFunctionExpression": {
		"beforeOpeningRoundBrace": true
	},

	"validateJSDoc": null,

	"requireBlocksOnNewline": 1,
	"disallowPaddingNewlinesInBlocks": true,
	"disallowEmptyBlocks": true,
	"disallowNewlineBeforeBlockStatements": true,

	"requireCommaBeforeLineBreak": true,
	"requireOperatorBeforeLineBreak": true,

	"disallowSpaceAfterObjectKeys": true,
	"disallowSpaceAfterPrefixUnaryOperators": true,
	"disallowSpaceBeforePostfixUnaryOperators": true,

	"disallowTrailingComma": true,
	"validateLineBreaks": require('os').EOL.replace(/\r/g, 'CR').replace(/\n/g, 'LF'),
	"validateParameterSeparator": ", ",

	"requireCapitalizedConstructors": true
};

gulp.task('data', function () {
	var directories = ['./data/*.js', './mods/*/*.js'];
	jsHintOptions['es3'] = true;
});

gulp.task('fastlint', function () {
	var directories = ['./*.js', './tournaments/*.js', './chat-plugins/*.js', './config/*.js'];
	delete jsHintOptions['es3'];

	return gulp.src(directories)
		.pipe(jscs(jscsOptions))
		.pipe(replace(/\bvar\b/g, 'let'))
		.pipe(jshint(jsHintOptions))
		.pipe(jshint.reporter(jshintStylish))
		.pipe(jshint.reporter('fail'));
});

gulp.task('default', ['fastlint', 'data']);
gulp.task('lint', ['fastlint', 'data']);
<|endoftext|>


<commit_before>var src = 'src';
var dist = 'build/dist';
var dev = 'build/dev';

var paths = {
    src: src,
    source: {
        root: src,
        scripts: src + '/scripts',
        stylesheets: src + '/stylesheets',
        images: src + '/images'
    },
    dev: {
        root: dev,
        scripts: dev + '/scripts',
        stylesheets: dev + '/stylesheets',
        dependencies: dev + '/lib',
        angular: dev + '/lib/angular',
        rxjs: dev + '/lib/rxjs',
        webapi: dev + '/lib/webapi',
        scriptsTranspiled: dev + '/scripts/transpiled',
        images: dev + '/images'
    },
    dist: {
        root: dist,
        scripts: dist + '/scripts',
        stylesheets: dist + '/stylesheets',
        dependencies: dist + '/lib',
        angular: dist + '/lib/angular',
        images: dist + '/images'
    }
}

var out = {
    index: 'index.html',
    scripts: {
        concat: 'app.js',
        minified: 'app.min.js',
        angular: 'angular.min.js'
    },
    angular: 'angular.js',
    rxjs: 'rxjs.js',
    webapi: 'webapi.js',
    dependencies: 'vendors.min.js',
    dependencyStyles: 'vendors.min.css',
    stylesheets: 'stylesheets.css'
}

var files = {
    src: {
        index: paths.src + '/' + out.index,
        typescripts: [paths.source.scripts + '/**/*.ts','typings/**/*.ts'],
        stylesheets: [paths.source.stylesheets + '/**/*.css'],
        systemjsConfig: paths.source.scripts + '/systemjs.config.js',
        images: paths.source.images + '/**/*'
    },
    dev: {
        scripts: paths.dev.scripts + '/*.js',
        scriptsTranspiled: paths.dev.scriptsTranspiled + '/**/*.js',
        scriptsBundled: paths.dev.scripts + '/' + out.scripts.minified
    },
    dist: {
        scripts: paths.dist.scripts + '/**/*.js'
    },
    dependencies: {
        appDependencies: [
            'node_modules/core-js/client/shim.min.js',
            'node_modules/zone.js/dist/zone.min.js',
            'node_modules/reflect-metadata/Reflect.js',
            'node_modules/systemjs/dist/system.js',
            paths.source.scripts + '/systemjs.config.js',
            'node_modules/jquery/dist/jquery.min.js',
            'node_modules/bootstrap/dist/js/bootstrap.min.js'
        ],
        stylesheets: [
            'node_modules/bootstrap/dist/css/bootstrap.min.css',
            'node_modules/bootstrap/dist/css/bootstrap-theme.min.css'
        ],
        fonts: 'node_modules/bootstrap/dist/fonts/*.svg',
        angular: ['node_modules/@angular/**/*',
            'node_modules/rxjs/**/*.js',
            'node_modules/angular2-in-memory-web-api/**/*.js'
        ]
    }
}

var injectables = ['/lib/*', '/stylesheets/*'];

/** Dependencies */
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var inject = require('gulp-inject');
var uglifyCss = require('gulp-uglifycss');
var embed = require('gulp-angular2-embed-templates');
var ts = require('gulp-typescript');
var tsConfig = require('./tsconfig.json');
var Builder = require('systemjs-builder');
/** End Dependencies */

function concatFiles(src, out, dest) {
    return gulp.src(src)
        .pipe(concat(out))
        .pipe(gulp.dest(dest));
}

/**
 * Concat Dependencies
 */
function concatDependencies(dest) {
    return gulp.src(files.dependencies.appDependencies)
        .pipe(concat(out.dependencies))
        .pipe(uglify())
        .pipe(gulp.dest(dest));
}

function dependenciesDev() { return concatDependencies(paths.dev.dependencies); }
gulp.task('dependencies:dev', dependenciesDev);
gulp.task('d:dev', ['dependencies:dev']);

function dependenciesDist() { return concatDependencies(paths.dist.dependencies); }
gulp.task('dependencies:dist', dependenciesDist);
gulp.task('d:dist', ['dependencies:dist']);

/**
 * Concat dependency css
 */
function concatDependencyStyles(dest) {
    return concatFiles(files.dependencies.stylesheets, out.dependencyStyles, dest);
}

function dependencyStylesDev() { return concatDependencyStyles(paths.dev.dependencies); }
gulp.task('dependencies:css:dev', dependencyStylesDev);
gulp.task('d:css:dev', dependencyStylesDev);

function dependencyStylesDist() { return concatDependencyStyles(paths.dist.dependencies); }
gulp.task('dependencies:css:dist', dependencyStylesDist);
gulp.task('d:css:dist', dependencyStylesDist);

/**
 * Fonts
 */
function copyFont(dest) {
    return gulp.src(files.dependencies.fonts)
        .pipe(gulp.dest(dest));
}

function fontsDev() { return copyFont(paths.dev.dependencies); }
gulp.task('fonts:dev', fontsDev);

function fontsDist() { return copyFont(paths.dist.dependencies); }
gulp.task('fonts:dist', fontsDist);

/**
 * Images
 */
function copyImages(dest) {
    return gulp.src(files.src.images)
        .pipe(gulp.dest(dest));
}

function imagesDev() { return copyImages(paths.dev.images); }
gulp.task('images:dev', imagesDev);

function imagesDist() { return copyImages(paths.dist.images); }
gulp.task('images:dist', imagesDist);

/**
 * Transpiling
 */
function transpile(dest) {
    return gulp.src(files.src.typescripts)
        .pipe(embed())
        .pipe(ts(tsConfig.compilerOptions))
        .pipe(gulp.dest(dest));
}

function transpileDev() { return transpile(paths.dev.scriptsTranspiled); }
gulp.task('tsc:dev', transpileDev);

/**
 * Bundle js
 */
function bundle(base, configPath, sourceFile, outFilePath) {
    var sysBuilder = new Builder(base, configPath);
    return sysBuilder.buildStatic(sourceFile, outFilePath);
}

// app
function bundleDev() { return bundle(
        '.',
        files.src.systemjsConfig,
        files.dev.scriptsTranspiled,
        paths.dev.scripts + '/' + out.scripts.minified
    );
}
gulp.task('bundle:dev', ['tsc:dev'], bundleDev);

/**
 * Uglify Transpiled
 */
function uglifyJs(src, dest) {
    return gulp.src(src)
        .pipe(uglify())
        .pipe(gulp.dest(dest));
}

function uglifyJsDist() { return uglifyJs(files.dev.scriptsBundled, paths.dist.scripts); }
gulp.task('uglify:js:dist', ['tsc:dev'], uglifyJsDist);
gulp.task('ugjs:dist', ['tsc:dev'], uglifyJsDist);

/**
 * Uglify CSS
 */
function uglifyStyles(dest) {
    return gulp.src(files.src.stylesheets)
        .pipe(uglifyCss())
        .pipe(concat(out.stylesheets))
        .pipe(gulp.dest(dest));
}

function uglifyStylesDev() { return uglifyStyles(paths.dev.stylesheets); }
gulp.task('uglify:css:dev', uglifyStylesDev);
gulp.task('ugcss:dev', ['uglify:css:dev']);

function uglifyStylesDist() { return uglifyStyles(paths.dist.stylesheets); }
gulp.task('uglify:css:dist', uglifyStylesDist);
gulp.task('ugcss:dist', ['uglify:css:dist']);

/**
 * Build index files
 */
function buildIndex(path) {
    var toInject = [];
    injectables.forEach(function(item){
        toInject.push(path + item);
    });
    var sources = gulp.src(toInject, {read: false});
    return gulp.src(files.src.index)
        .pipe(inject(sources, {ignorePath: path, addRootSlash: true}))
        .pipe(gulp.dest(path));
}

function indexDev() { return buildIndex(paths.dev.root); }
gulp.task('index:dev', [
    'dependencies:dev',
    'dependencies:css:dev',
    'bundle:dev',
    'fonts:dev',
    'tsc:dev',
    'uglify:css:dev'
], indexDev);

function indexDist() { return buildIndex(paths.dist.root); }
gulp.task('index:dist', [
    'dependencies:dist',
    'dependencies:css:dist',
    'bundle:dev',
    'fonts:dist',
    'tsc:dev',
    'uglify:js:dist',
    'uglify:css:dist'
], indexDist);

/**
 * Builds
 */
gulp.task('build:dev', [
    'dependencies:dev',
    'dependencies:css:dev',
    'bundle:dev',
    'fonts:dev',
    'images:dev',
    'tsc:dev',
    'bundle:dev',
    'uglify:css:dev',
    'index:dev'
]);

gulp.task('build:dist', [
    'dependencies:dist',
    'dependencies:css:dist',
    'bundle:dev',
    'fonts:dist',
    'images:dist',
    'tsc:dev',
    'uglify:js:dist',
    'uglify:css:dist',
    'index:dist'
]);<commit_msg>fix: broken dist, don't mangle<commit_after>var src = 'src';
var dist = 'build/dist';
var dev = 'build/dev';

var paths = {
    src: src,
    source: {
        root: src,
        scripts: src + '/scripts',
        stylesheets: src + '/stylesheets',
        images: src + '/images'
    },
    dev: {
        root: dev,
        scripts: dev + '/scripts',
        stylesheets: dev + '/stylesheets',
        dependencies: dev + '/lib',
        angular: dev + '/lib/angular',
        rxjs: dev + '/lib/rxjs',
        webapi: dev + '/lib/webapi',
        scriptsTranspiled: dev + '/scripts/transpiled',
        images: dev + '/images'
    },
    dist: {
        root: dist,
        scripts: dist + '/scripts',
        stylesheets: dist + '/stylesheets',
        dependencies: dist + '/lib',
        angular: dist + '/lib/angular',
        images: dist + '/images'
    }
}

var out = {
    index: 'index.html',
    scripts: {
        concat: 'app.js',
        minified: 'app.min.js',
        angular: 'angular.min.js'
    },
    angular: 'angular.js',
    rxjs: 'rxjs.js',
    webapi: 'webapi.js',
    dependencies: 'vendors.min.js',
    dependencyStyles: 'vendors.min.css',
    stylesheets: 'stylesheets.css'
}

var files = {
    src: {
        index: paths.src + '/' + out.index,
        typescripts: [paths.source.scripts + '/**/*.ts','typings/**/*.ts'],
        stylesheets: [paths.source.stylesheets + '/**/*.css'],
        systemjsConfig: paths.source.scripts + '/systemjs.config.js',
        images: paths.source.images + '/**/*'
    },
    dev: {
        scripts: paths.dev.scripts + '/*.js',
        scriptsTranspiled: paths.dev.scriptsTranspiled + '/**/*.js',
        scriptsBundled: paths.dev.scripts + '/' + out.scripts.minified
    },
    dist: {
        scripts: paths.dist.scripts + '/**/*.js'
    },
    dependencies: {
        appDependencies: [
            'node_modules/core-js/client/shim.min.js',
            'node_modules/zone.js/dist/zone.min.js',
            'node_modules/reflect-metadata/Reflect.js',
            'node_modules/systemjs/dist/system.js',
            paths.source.scripts + '/systemjs.config.js',
            'node_modules/jquery/dist/jquery.min.js',
            'node_modules/bootstrap/dist/js/bootstrap.min.js'
        ],
        stylesheets: [
            'node_modules/bootstrap/dist/css/bootstrap.min.css',
            'node_modules/bootstrap/dist/css/bootstrap-theme.min.css'
        ],
        fonts: 'node_modules/bootstrap/dist/fonts/*.svg',
        angular: ['node_modules/@angular/**/*',
            'node_modules/rxjs/**/*.js',
            'node_modules/angular2-in-memory-web-api/**/*.js'
        ]
    }
}

var injectables = ['/lib/*', '/stylesheets/*'];

/** Dependencies */
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var inject = require('gulp-inject');
var uglifyCss = require('gulp-uglifycss');
var embed = require('gulp-angular2-embed-templates');
var ts = require('gulp-typescript');
var tsConfig = require('./tsconfig.json');
var Builder = require('systemjs-builder');
/** End Dependencies */

function concatFiles(src, out, dest) {
    return gulp.src(src)
        .pipe(concat(out))
        .pipe(gulp.dest(dest));
}

/**
 * Concat Dependencies
 */
function concatDependencies(dest) {
    return gulp.src(files.dependencies.appDependencies)
        .pipe(concat(out.dependencies))
        .pipe(uglify())
        .pipe(gulp.dest(dest));
}

function dependenciesDev() { return concatDependencies(paths.dev.dependencies); }
gulp.task('dependencies:dev', dependenciesDev);
gulp.task('d:dev', ['dependencies:dev']);

function dependenciesDist() { return concatDependencies(paths.dist.dependencies); }
gulp.task('dependencies:dist', dependenciesDist);
gulp.task('d:dist', ['dependencies:dist']);

/**
 * Concat dependency css
 */
function concatDependencyStyles(dest) {
    return concatFiles(files.dependencies.stylesheets, out.dependencyStyles, dest);
}

function dependencyStylesDev() { return concatDependencyStyles(paths.dev.dependencies); }
gulp.task('dependencies:css:dev', dependencyStylesDev);
gulp.task('d:css:dev', dependencyStylesDev);

function dependencyStylesDist() { return concatDependencyStyles(paths.dist.dependencies); }
gulp.task('dependencies:css:dist', dependencyStylesDist);
gulp.task('d:css:dist', dependencyStylesDist);

/**
 * Fonts
 */
function copyFont(dest) {
    return gulp.src(files.dependencies.fonts)
        .pipe(gulp.dest(dest));
}

function fontsDev() { return copyFont(paths.dev.dependencies); }
gulp.task('fonts:dev', fontsDev);

function fontsDist() { return copyFont(paths.dist.dependencies); }
gulp.task('fonts:dist', fontsDist);

/**
 * Images
 */
function copyImages(dest) {
    return gulp.src(files.src.images)
        .pipe(gulp.dest(dest));
}

function imagesDev() { return copyImages(paths.dev.images); }
gulp.task('images:dev', imagesDev);

function imagesDist() { return copyImages(paths.dist.images); }
gulp.task('images:dist', imagesDist);

/**
 * Transpiling
 */
function transpile(dest) {
    return gulp.src(files.src.typescripts)
        .pipe(embed())
        .pipe(ts(tsConfig.compilerOptions))
        .pipe(gulp.dest(dest));
}

function transpileDev() { return transpile(paths.dev.scriptsTranspiled); }
gulp.task('tsc:dev', transpileDev);

/**
 * Bundle js
 */
function bundle(base, configPath, sourceFile, outFilePath) {
    var sysBuilder = new Builder(base, configPath);
    return sysBuilder.buildStatic(sourceFile, outFilePath);
}

// app
function bundleDev() { return bundle(
        '.',
        files.src.systemjsConfig,
        files.dev.scriptsTranspiled,
        paths.dev.scripts + '/' + out.scripts.minified
    );
}
gulp.task('bundle:dev', ['tsc:dev'], bundleDev);

/**
 * Uglify Transpiled
 */
function uglifyJs(src, dest) {
    return gulp.src(src)
        .pipe(uglify({mangle: false}))
        .pipe(gulp.dest(dest));
}

function uglifyJsDist() { return uglifyJs(files.dev.scriptsBundled, paths.dist.scripts); }
gulp.task('uglify:js:dist', ['tsc:dev'], uglifyJsDist);
gulp.task('ugjs:dist', ['tsc:dev'], uglifyJsDist);

/**
 * Uglify CSS
 */
function uglifyStyles(dest) {
    return gulp.src(files.src.stylesheets)
        .pipe(uglifyCss())
        .pipe(concat(out.stylesheets))
        .pipe(gulp.dest(dest));
}

function uglifyStylesDev() { return uglifyStyles(paths.dev.stylesheets); }
gulp.task('uglify:css:dev', uglifyStylesDev);
gulp.task('ugcss:dev', ['uglify:css:dev']);

function uglifyStylesDist() { return uglifyStyles(paths.dist.stylesheets); }
gulp.task('uglify:css:dist', uglifyStylesDist);
gulp.task('ugcss:dist', ['uglify:css:dist']);

/**
 * Build index files
 */
function buildIndex(path) {
    var toInject = [];
    injectables.forEach(function(item){
        toInject.push(path + item);
    });
    var sources = gulp.src(toInject, {read: false});
    return gulp.src(files.src.index)
        .pipe(inject(sources, {ignorePath: path, addRootSlash: true}))
        .pipe(gulp.dest(path));
}

function indexDev() { return buildIndex(paths.dev.root); }
gulp.task('index:dev', [
    'dependencies:dev',
    'dependencies:css:dev',
    'bundle:dev',
    'fonts:dev',
    'tsc:dev',
    'uglify:css:dev'
], indexDev);

function indexDist() { return buildIndex(paths.dist.root); }
gulp.task('index:dist', [
    'dependencies:dist',
    'dependencies:css:dist',
    'bundle:dev',
    'fonts:dist',
    'tsc:dev',
    'uglify:js:dist',
    'uglify:css:dist'
], indexDist);

/**
 * Builds
 */
gulp.task('build:dev', [
    'dependencies:dev',
    'dependencies:css:dev',
    'bundle:dev',
    'fonts:dev',
    'images:dev',
    'tsc:dev',
    'bundle:dev',
    'uglify:css:dev',
    'index:dev'
]);

gulp.task('build:dist', [
    'dependencies:dist',
    'dependencies:css:dist',
    'bundle:dev',
    'fonts:dist',
    'images:dist',
    'tsc:dev',
    'uglify:js:dist',
    'uglify:css:dist',
    'index:dist'
]);<|endoftext|>


<commit_before>/* ==========================================================================
   Yes We Work WordPress + Vagrant development kit
   ========================================================================== */

var gulp = require('gulp'),
	autoprefixer = require('autoprefixer'),
	browserSync = require('browser-sync').create(),
	del = require('del'),
	beml = require('gulp-beml'),
	concat = require('gulp-concat'),
	changed = require('gulp-changed'),
	csslint = require('gulp-csslint'),
	cssnano = require('gulp-cssnano'),
	gulpFilter = require('gulp-filter'),
	flatten = require('gulp-flatten'),
	imagemin = require('gulp-imagemin'),
	jshint = require('gulp-jshint'),
	postcss = require('gulp-postcss'),
	rename = require('gulp-rename'),
	sourcemaps = require('gulp-sourcemaps'),
	tap = require('gulp-tap'),
	fs = require('fs'),
	uglify = require('gulp-uglify'),
	lost = require('lost'),
	mainBowerFiles = require('main-bower-files'),
	postcssFontpath = require('postcss-fontpath'),
	postcssNested = require('postcss-nested'),
	postcssNestedProps = require('postcss-nested-props'),
	postcssSimpleVars = require('postcss-simple-vars'),
	shell = require('shelljs'),
	ftp = require('vinyl-ftp'),
	YAML = require('yamljs');

// Default project settings
var projectSlug = 'yww-project';
var projectUrl = 'yeswework.dev';
var projectName = 'YWW Project';
var projectAuthor = 'Yes We Work - http://yeswework.com/';

// Overwrite with defaults from Vagrant's YML file in the parent folder, if available
var projectSettings = YAML.load('site.yml');
if(typeof projectSettings.slug != 'undefined' && projectSettings.slug != '') {
	var projectSlug = projectSettings.slug;
}
if(typeof projectSettings.hostname != 'undefined' && projectSettings.hostname != '') {
	var projectUrl = projectSettings.hostname;
}
if(typeof projectSettings.title != 'undefined' && projectSettings.title != '') {
	var projectName = projectSettings.title;
}

// Paths for remapping
var base = {
	src: './dev/src/',
	build: './dev/build/',
	theme: './www/wordpress/wp-content/themes/' + projectSlug + '/'
};

// Globs for each file type
var glob = {
	acfTheme: base.theme + 'acf-json/*.json',
	acf: base.src + 'acf-json/*.json',
	bower: base.src + 'bower_components/**/*.php',
	includes: [base.src + 'includes/**/*.php', base.src + 'includes/.env'],
	controllers: base.src + 'templates/controllers/**/*.php',
	views: base.src + 'templates/**/*.twig',
	styles: base.src + 'assets/css/**/*.{css,pcss}',
	scripts: base.src + 'assets/js/**/*.js',
	images: base.src + 'assets/img/**/*',
	fonts: base.src + 'assets/fonts/**/*'
};

// Build folder slugs
var dest = {
	acf: 'acf-json',
	includes: 'inc',
	controllers: '', // need to go in the root theme folder
	views: 'views',
	styles: 'css',
	scripts: 'js',
	images: 'img',
	fonts: 'fonts'
};

// Plugin options
var options = {
	uglify: {mangle: false},
	imagemin: {optimizationLevel: 7, progressive: true, interlaced: true, multipass: true},
	postcss: [
		postcssSimpleVars,
		postcssNestedProps,
		postcssNested,
		postcssFontpath,
		lost,
		autoprefixer({browsers: ['last 3 versions']})
	],
	beml: {
		elemPrefix: '__',
		modPrefix: '--',
		modDlmtr: '-'
	}
};

// Before cleaning, retrieve latest ACF JSON from live theme (delete first)
// These are the only tasks which modify the src folder
function acfClean() {
	return del(base.src + dest.acf);
}
function acfPull() {
	return gulp.src(glob.acfTheme)
		.pipe(gulp.dest(base.src + dest.acf));
}

// Erase build and theme folders before each compile
function clean() {
	return del([base.build, base.theme], {force: true});
}

// Bower: concatenate "main files" into library script and stylesheet and copy
function bower() {
	var jsFilter = gulpFilter('**/*.js', {restore: true});
	var cssFilter = gulpFilter('**/*.css', {restore: true});
	return gulp.src(mainBowerFiles({paths: base.src}))
		.pipe(jsFilter)
		.pipe(concat('lib.js'))
		.pipe(sourcemaps.init())
		.pipe(changed(base.build + dest.scripts))
		.pipe(gulp.dest(base.build + dest.scripts))
		.pipe(gulp.dest(base.theme + dest.scripts))
		.pipe(browserSync.stream())
		.pipe(uglify(options.uglify))
		.pipe(rename('lib.min.js'))
		.pipe(sourcemaps.write('.'))
		.pipe(changed(base.build + dest.scripts))
		.pipe(gulp.dest(base.build + dest.scripts))
		.pipe(gulp.dest(base.theme + dest.scripts))
		.pipe(browserSync.stream())
		.pipe(jsFilter.restore)
		.pipe(cssFilter)
		.pipe(concat('lib.css'))
		.pipe(sourcemaps.init())
		.pipe(changed(base.build + dest.styles))
		.pipe(gulp.dest(base.build + dest.styles))
		.pipe(gulp.dest(base.theme + dest.styles))
		.pipe(browserSync.stream({match: '**/*.css'}))
		.pipe(cssnano())
		.pipe(rename('lib.min.css'))
		.pipe(sourcemaps.write('.'))
		.pipe(changed(base.build + dest.styles))
		.pipe(gulp.dest(base.build + dest.styles))
		.pipe(gulp.dest(base.theme + dest.styles))
		.pipe(browserSync.stream({match: '**/*.css'}));
}

// style.css: auto-create our theme's style.css using project info we already have
function styleCss(cb) {
	var data = '/*\r\n'
		+ 'Theme Name: ' + projectName + '\r\n'
		+ 'Theme URI: http://' + projectUrl + '\r\n'
		+ 'Author: ' + projectAuthor + '\r\n' + '*/';
	fs.writeFileSync(base.build + 'style.css', data);
	fs.writeFileSync(base.theme + 'style.css', data);
	cb(); // indicate completion
}

// Put ACF JSON back (previously saved with acfPull task)
function acf() {
	fs.mkdirSync(base.theme + dest.acf); // Create this folder under any circumstances, so ACF saves to it
	return gulp.src(glob.acf)
		.pipe(gulp.dest(base.build + dest.acf))
		.pipe(gulp.dest(base.theme + dest.acf));
}

// Includes: copy internal PHP dependencies to an inc folder and auto-create functions.php with includes
function includes() {
	fs.writeFileSync(base.build + 'functions.php', '<?php\r\n'); // create a blank functions.php
	fs.writeFileSync(base.theme + 'functions.php', '<?php\r\n');
	var nonVendorFilter = gulpFilter('*.php', {restore: true}); // only require top-level files in functions.php
	return gulp.src(glob.includes)
		.pipe(nonVendorFilter)
		.pipe(tap(function(file, t) {// write an include for this file to our functions.php automatically
			fs.appendFileSync(base.build + 'functions.php', "require_once(get_stylesheet_directory() . '/" + dest.includes + "/" + file.path.replace(file.base, '') + "');\r\n");
			fs.appendFileSync(base.theme + 'functions.php', "require_once(get_stylesheet_directory() . '/" + dest.includes + "/" + file.path.replace(file.base, '') + "');\r\n");
		}))
		.pipe(nonVendorFilter.restore)
		.pipe(changed(base.build + dest.includes))
		.pipe(gulp.dest(base.build + dest.includes))
		.pipe(gulp.dest(base.theme + dest.includes))
		.pipe(browserSync.stream());
}

// Controllers: copy PHP files, flattening tree
function controllers() {
	return gulp.src(glob.controllers)
		.pipe(flatten())
		.pipe(changed(base.build + dest.controllers))
		.pipe(gulp.dest(base.build + dest.controllers))
		.pipe(gulp.dest(base.theme + dest.controllers))
		.pipe(browserSync.stream());
}

// Views: copy Twig files, flattening tree
function views() {	return gulp.src(glob.views)
		.pipe(flatten())
		.pipe(changed(base.build + dest.views))
		// .pipe(beml(options.beml))
		.pipe(gulp.dest(base.build + dest.views))
		.pipe(gulp.dest(base.theme + dest.views))
		.pipe(browserSync.stream());
}

// Styles (CSS): lint, concatenate into one file, write source map, postcss, save full and minified versions, then copy
function styles() {
	var lintFilter = gulpFilter(['**/*', '!defaults.css', '!helpers.css'], {restore: true});
	return gulp.src(glob.styles)
		.pipe(postcss(options.postcss))
		.pipe(lintFilter) // don't lint certain files which we use on all projects
		.pipe(csslint({'font-sizes': false, 'box-model': false, 'compatible-vendor-prefixes': false, 'font-faces': false}))
		.pipe(csslint.reporter())
		.pipe(lintFilter.restore) // restore all files after linting
		.pipe(concat('main.css'))
		.pipe(sourcemaps.init())
		.pipe(changed(base.build + dest.styles))
		.pipe(gulp.dest(base.build + dest.styles))
		.pipe(gulp.dest(base.theme + dest.styles))
		.pipe(browserSync.stream({match: '**/*.css'}))
		.pipe(cssnano())
		.pipe(rename('main.min.css'))
		.pipe(sourcemaps.write('.'))
		.pipe(changed(base.build + dest.styles))
		.pipe(gulp.dest(base.build + dest.styles))
		.pipe(gulp.dest(base.theme + dest.styles))
		.pipe(browserSync.stream({match: '**/*.css'}));
}

// Scripts (JS): lint, concatenate into one file, save full and minified versions, then copy
function scripts() {
	return gulp.src(glob.scripts)
		.pipe(jshint())
		.pipe(jshint.reporter())
		.pipe(concat('main.js'))
		.pipe(sourcemaps.init())
		.pipe(changed(base.build + dest.scripts))
		.pipe(gulp.dest(base.build + dest.scripts))
		.pipe(gulp.dest(base.theme + dest.scripts))
		.pipe(browserSync.stream())
		.pipe(uglify(options.uglify))
		.pipe(rename('main.min.js'))
		.pipe(sourcemaps.write('.'))
		.pipe(changed(base.build + dest.scripts))
		.pipe(gulp.dest(base.build + dest.scripts))
		.pipe(gulp.dest(base.theme + dest.scripts))
		.pipe(browserSync.stream());
}

// Images: optimise and copy, maintaining tree
function images() {
	return gulp.src(glob.images)
		.pipe(changed(base.build + dest.images))
		.pipe(imagemin(options.imagemin))
		.pipe(gulp.dest(base.build + dest.images))
		.pipe(gulp.dest(base.theme + dest.images))
		.pipe(browserSync.stream());
}

// Fonts: just copy, maintaining tree
function fonts() {
	return gulp.src(glob.fonts)
		.pipe(changed(base.build + dest.fonts))
		.pipe(gulp.dest(base.build + dest.fonts))
		.pipe(gulp.dest(base.theme + dest.fonts))
		.pipe(browserSync.stream());
}

// Build: sequences all the other tasks
gulp.task('build', gulp.series(acfClean, acfPull, clean, bower, gulp.parallel(styleCss, acf, includes, controllers, views, styles, scripts, images, fonts)));

// Install: tell Vagrant to activate the built theme
gulp.task('install', gulp.series('build', activate));
function activate(cb) {
	shell.exec('vagrant ssh -c "wp theme activate ' + projectSlug + '"');
	cb(); // indicate completion
}

// Watch: fire build, then watch for changes
gulp.task('default', gulp.series('build', watch));
function watch() {
	browserSync.init({
		proxy: projectUrl,
		open: false
	});
	gulp.watch(glob.styles, gulp.series(styles));
	gulp.watch(glob.bower, gulp.series(bower));
	gulp.watch(glob.includes, gulp.series(includes));
	gulp.watch(glob.controllers, gulp.series(controllers));
	gulp.watch(glob.views, gulp.series(views));
	gulp.watch(glob.scripts, gulp.series(scripts));
	gulp.watch(glob.images, gulp.series(images));
	gulp.watch(glob.fonts, gulp.series(fonts));
}
<commit_msg>add watch for ACF JSON changes<commit_after>/* ==========================================================================
   Yes We Work WordPress + Vagrant development kit
   ========================================================================== */

var gulp = require('gulp'),
	autoprefixer = require('autoprefixer'),
	browserSync = require('browser-sync').create(),
	del = require('del'),
	beml = require('gulp-beml'),
	concat = require('gulp-concat'),
	changed = require('gulp-changed'),
	csslint = require('gulp-csslint'),
	cssnano = require('gulp-cssnano'),
	gulpFilter = require('gulp-filter'),
	flatten = require('gulp-flatten'),
	imagemin = require('gulp-imagemin'),
	jshint = require('gulp-jshint'),
	postcss = require('gulp-postcss'),
	rename = require('gulp-rename'),
	sourcemaps = require('gulp-sourcemaps'),
	tap = require('gulp-tap'),
	fs = require('fs'),
	uglify = require('gulp-uglify'),
	lost = require('lost'),
	mainBowerFiles = require('main-bower-files'),
	postcssFontpath = require('postcss-fontpath'),
	postcssNested = require('postcss-nested'),
	postcssNestedProps = require('postcss-nested-props'),
	postcssSimpleVars = require('postcss-simple-vars'),
	shell = require('shelljs'),
	ftp = require('vinyl-ftp'),
	YAML = require('yamljs');

// Default project settings
var projectSlug = 'yww-project';
var projectUrl = 'yeswework.dev';
var projectName = 'YWW Project';
var projectAuthor = 'Yes We Work - http://yeswework.com/';

// Overwrite with defaults from Vagrant's YML file in the parent folder, if available
var projectSettings = YAML.load('site.yml');
if(typeof projectSettings.slug != 'undefined' && projectSettings.slug != '') {
	var projectSlug = projectSettings.slug;
}
if(typeof projectSettings.hostname != 'undefined' && projectSettings.hostname != '') {
	var projectUrl = projectSettings.hostname;
}
if(typeof projectSettings.title != 'undefined' && projectSettings.title != '') {
	var projectName = projectSettings.title;
}

// Paths for remapping
var base = {
	src: './dev/src/',
	build: './dev/build/',
	theme: './www/wordpress/wp-content/themes/' + projectSlug + '/'
};

// Globs for each file type
var glob = {
	acfTheme: base.theme + 'acf-json/*.json',
	acf: base.src + 'acf-json/*.json',
	bower: base.src + 'bower_components/**/*.php',
	includes: [base.src + 'includes/**/*.php', base.src + 'includes/.env'],
	controllers: base.src + 'templates/controllers/**/*.php',
	views: base.src + 'templates/**/*.twig',
	styles: base.src + 'assets/css/**/*.{css,pcss}',
	scripts: base.src + 'assets/js/**/*.js',
	images: base.src + 'assets/img/**/*',
	fonts: base.src + 'assets/fonts/**/*'
};

// Build folder slugs
var dest = {
	acf: 'acf-json',
	includes: 'inc',
	controllers: '', // need to go in the root theme folder
	views: 'views',
	styles: 'css',
	scripts: 'js',
	images: 'img',
	fonts: 'fonts'
};

// Plugin options
var options = {
	uglify: {mangle: false},
	imagemin: {optimizationLevel: 7, progressive: true, interlaced: true, multipass: true},
	postcss: [
		postcssSimpleVars,
		postcssNestedProps,
		postcssNested,
		postcssFontpath,
		lost,
		autoprefixer({browsers: ['last 3 versions']})
	],
	beml: {
		elemPrefix: '__',
		modPrefix: '--',
		modDlmtr: '-'
	}
};

// Before cleaning, retrieve latest ACF JSON from live theme (delete first)
// These are the only tasks which modify the src folder
function acfClean() {
	return del(base.src + dest.acf);
}
function acfPull() {
	return gulp.src(glob.acfTheme)
		.pipe(gulp.dest(base.src + dest.acf));
}

// Erase build and theme folders before each compile
function clean() {
	return del([base.build, base.theme], {force: true});
}

// Bower: concatenate "main files" into library script and stylesheet and copy
function bower() {
	var jsFilter = gulpFilter('**/*.js', {restore: true});
	var cssFilter = gulpFilter('**/*.css', {restore: true});
	return gulp.src(mainBowerFiles({paths: base.src}))
		.pipe(jsFilter)
		.pipe(concat('lib.js'))
		.pipe(sourcemaps.init())
		.pipe(changed(base.build + dest.scripts))
		.pipe(gulp.dest(base.build + dest.scripts))
		.pipe(gulp.dest(base.theme + dest.scripts))
		.pipe(browserSync.stream())
		.pipe(uglify(options.uglify))
		.pipe(rename('lib.min.js'))
		.pipe(sourcemaps.write('.'))
		.pipe(changed(base.build + dest.scripts))
		.pipe(gulp.dest(base.build + dest.scripts))
		.pipe(gulp.dest(base.theme + dest.scripts))
		.pipe(browserSync.stream())
		.pipe(jsFilter.restore)
		.pipe(cssFilter)
		.pipe(concat('lib.css'))
		.pipe(sourcemaps.init())
		.pipe(changed(base.build + dest.styles))
		.pipe(gulp.dest(base.build + dest.styles))
		.pipe(gulp.dest(base.theme + dest.styles))
		.pipe(browserSync.stream({match: '**/*.css'}))
		.pipe(cssnano())
		.pipe(rename('lib.min.css'))
		.pipe(sourcemaps.write('.'))
		.pipe(changed(base.build + dest.styles))
		.pipe(gulp.dest(base.build + dest.styles))
		.pipe(gulp.dest(base.theme + dest.styles))
		.pipe(browserSync.stream({match: '**/*.css'}));
}

// style.css: auto-create our theme's style.css using project info we already have
function styleCss(cb) {
	var data = '/*\r\n'
		+ 'Theme Name: ' + projectName + '\r\n'
		+ 'Theme URI: http://' + projectUrl + '\r\n'
		+ 'Author: ' + projectAuthor + '\r\n' + '*/';
	fs.writeFileSync(base.build + 'style.css', data);
	fs.writeFileSync(base.theme + 'style.css', data);
	cb(); // indicate completion
}

// Put ACF JSON back (previously saved with acfPull task)
function acf() {
	fs.mkdirSync(base.theme + dest.acf); // Create this folder under any circumstances, so ACF saves to it
	return gulp.src(glob.acf)
		.pipe(gulp.dest(base.build + dest.acf))
		.pipe(gulp.dest(base.theme + dest.acf));
}

// Includes: copy internal PHP dependencies to an inc folder and auto-create functions.php with includes
function includes() {
	fs.writeFileSync(base.build + 'functions.php', '<?php\r\n'); // create a blank functions.php
	fs.writeFileSync(base.theme + 'functions.php', '<?php\r\n');
	var nonVendorFilter = gulpFilter('*.php', {restore: true}); // only require top-level files in functions.php
	return gulp.src(glob.includes)
		.pipe(nonVendorFilter)
		.pipe(tap(function(file, t) {// write an include for this file to our functions.php automatically
			fs.appendFileSync(base.build + 'functions.php', "require_once(get_stylesheet_directory() . '/" + dest.includes + "/" + file.path.replace(file.base, '') + "');\r\n");
			fs.appendFileSync(base.theme + 'functions.php', "require_once(get_stylesheet_directory() . '/" + dest.includes + "/" + file.path.replace(file.base, '') + "');\r\n");
		}))
		.pipe(nonVendorFilter.restore)
		.pipe(changed(base.build + dest.includes))
		.pipe(gulp.dest(base.build + dest.includes))
		.pipe(gulp.dest(base.theme + dest.includes))
		.pipe(browserSync.stream());
}

// Controllers: copy PHP files, flattening tree
function controllers() {
	return gulp.src(glob.controllers)
		.pipe(flatten())
		.pipe(changed(base.build + dest.controllers))
		.pipe(gulp.dest(base.build + dest.controllers))
		.pipe(gulp.dest(base.theme + dest.controllers))
		.pipe(browserSync.stream());
}

// Views: copy Twig files, flattening tree
function views() {	return gulp.src(glob.views)
		.pipe(flatten())
		.pipe(changed(base.build + dest.views))
		// .pipe(beml(options.beml))
		.pipe(gulp.dest(base.build + dest.views))
		.pipe(gulp.dest(base.theme + dest.views))
		.pipe(browserSync.stream());
}

// Styles (CSS): lint, concatenate into one file, write source map, postcss, save full and minified versions, then copy
function styles() {
	var lintFilter = gulpFilter(['**/*', '!defaults.css', '!helpers.css'], {restore: true});
	return gulp.src(glob.styles)
		.pipe(postcss(options.postcss))
		.pipe(lintFilter) // don't lint certain files which we use on all projects
		.pipe(csslint({'font-sizes': false, 'box-model': false, 'compatible-vendor-prefixes': false, 'font-faces': false}))
		.pipe(csslint.reporter())
		.pipe(lintFilter.restore) // restore all files after linting
		.pipe(concat('main.css'))
		.pipe(sourcemaps.init())
		.pipe(changed(base.build + dest.styles))
		.pipe(gulp.dest(base.build + dest.styles))
		.pipe(gulp.dest(base.theme + dest.styles))
		.pipe(browserSync.stream({match: '**/*.css'}))
		.pipe(cssnano())
		.pipe(rename('main.min.css'))
		.pipe(sourcemaps.write('.'))
		.pipe(changed(base.build + dest.styles))
		.pipe(gulp.dest(base.build + dest.styles))
		.pipe(gulp.dest(base.theme + dest.styles))
		.pipe(browserSync.stream({match: '**/*.css'}));
}

// Scripts (JS): lint, concatenate into one file, save full and minified versions, then copy
function scripts() {
	return gulp.src(glob.scripts)
		.pipe(jshint())
		.pipe(jshint.reporter())
		.pipe(concat('main.js'))
		.pipe(sourcemaps.init())
		.pipe(changed(base.build + dest.scripts))
		.pipe(gulp.dest(base.build + dest.scripts))
		.pipe(gulp.dest(base.theme + dest.scripts))
		.pipe(browserSync.stream())
		.pipe(uglify(options.uglify))
		.pipe(rename('main.min.js'))
		.pipe(sourcemaps.write('.'))
		.pipe(changed(base.build + dest.scripts))
		.pipe(gulp.dest(base.build + dest.scripts))
		.pipe(gulp.dest(base.theme + dest.scripts))
		.pipe(browserSync.stream());
}

// Images: optimise and copy, maintaining tree
function images() {
	return gulp.src(glob.images)
		.pipe(changed(base.build + dest.images))
		.pipe(imagemin(options.imagemin))
		.pipe(gulp.dest(base.build + dest.images))
		.pipe(gulp.dest(base.theme + dest.images))
		.pipe(browserSync.stream());
}

// Fonts: just copy, maintaining tree
function fonts() {
	return gulp.src(glob.fonts)
		.pipe(changed(base.build + dest.fonts))
		.pipe(gulp.dest(base.build + dest.fonts))
		.pipe(gulp.dest(base.theme + dest.fonts))
		.pipe(browserSync.stream());
}

// Build: sequences all the other tasks
gulp.task('build', gulp.series(acfClean, acfPull, clean, bower, gulp.parallel(styleCss, acf, includes, controllers, views, styles, scripts, images, fonts)));

// Install: tell Vagrant to activate the built theme
gulp.task('install', gulp.series('build', activate));
function activate(cb) {
	shell.exec('vagrant ssh -c "wp theme activate ' + projectSlug + '"');
	cb(); // indicate completion
}

// Watch: fire build, then watch for changes
gulp.task('default', gulp.series('build', watch));
function watch() {
	browserSync.init({
		proxy: projectUrl,
		open: false
	});
	gulp.watch(glob.styles, gulp.series(styles));
	gulp.watch(glob.bower, gulp.series(bower));
	gulp.watch(glob.includes, gulp.series(includes));
	gulp.watch(glob.controllers, gulp.series(controllers));
	gulp.watch(glob.views, gulp.series(views));
	gulp.watch(glob.scripts, gulp.series(scripts));
	gulp.watch(glob.images, gulp.series(images));
	gulp.watch(glob.fonts, gulp.series(fonts));
	gulp.watch(glob.acfTheme, gulp.series(acfClean, acfPull));
}
<|endoftext|>