<commit_before>function hash_set_value(key, value) {
    'use strict';
    // Set value for key in hash
    var hash = $(location).attr('hash').substring(2).toLowerCase().replace(/\/$/, '');
    var keys;
    var values;

    if (!value) {
        value = '';
    }

    if (hash.length > 0) {
        keys = hash.split('/').filter(function(element, index) { return (index % 2 === 0); });
        values = hash.split('/').filter(function(element, index) { return (index % 2 === 1); });
    }
    else {
        keys = [];
        values = [];
    }

    var index_of_key = keys.indexOf(key);

    if (index_of_key > -1) {
        values[index_of_key] = value;
    }
    else {
        keys.push(key);
        values.push(value);
    }

    hash = '/';
    for (var i=0; i < keys.length; i++) {
        if (values[i].length > 0 ) {
            hash += keys[i] + '/' + values[i] + '/';
        }
    }

    $(location).attr('hash', hash);
}

function hash_get_value(key) {
    'use strict';
    // Get value for key in hash
    var hash = $(location).attr('hash').substring(2).toLowerCase();
    var keys = hash.split('/').filter(function(element, index) { return (index % 2 === 0); });
    var values = hash.split('/').filter(function(element, index) { return (index % 2 === 1); });
    var index_of_key = keys.indexOf(key);
    if (index_of_key > -1) {
        return values[index_of_key].toLowerCase();
    }

    return;
}

function set_dropdown_value(elm, value) {
    'use strict';
    elm.val(value);
}

function pad2(number) {
    // Pad numbers
    // snippet from
    // http://www.electrictoolbox.com/pad-number-two-digits-javascript/
    'use strict';
    return (number < 10 ? '0' : '') + number;
}

function append_to_formset(event) {
    'use strict';
    event.preventDefault();
    var button_obj = $(event.currentTarget);
    var formset_obj = button_obj.closest('.formset');
    var block_obj = formset_obj.find('.copyblock').first();
    var new_block_obj = block_obj.clone();
    var prefix = formset_obj.data('prefix');
    var total_forms_obj = formset_obj.parent().children('#id_' + prefix + '-TOTAL_FORMS');
    var append_after_obj = block_obj;

    if (button_obj.hasClass('voting-add-rangepoll-button') ||
        button_obj.hasClass('voting-add-radiopoll-button')) {
        var input = new_block_obj.find('#inner-rangepoll-formset, #inner-radiopoll-formset');
        input.not(':first').remove();
    }

    if (block_obj.siblings('.copyblock').length > 0) {
        append_after_obj = block_obj.siblings('.copyblock').last();
    }

    function attr_update(selector, attr, prepend){
        new_block_obj.find(selector + prefix + "]").each(function (index, item) {
            var item_obj = $(item);
            var obj_length = total_forms_obj.val().length;
            var prologue_length = 2 + prepend.length + prefix.length + obj_length;
            var item_id = item_obj.attr(attr).substr(prologue_length - obj_length);
            var newid = prepend + prefix + '-' + total_forms_obj.val() + item_id;
            item_obj.attr(attr, newid);
        });
    }
    attr_update('[id*=id_', 'id', 'id_');
    attr_update('[name*=', 'name', '');
    attr_update('[data-prefix*=', 'data-prefix', '');
    attr_update('[for*=id_', 'for', 'id_');

    new_block_obj.insertAfter(append_after_obj);

    // Cleanup
    new_block_obj.find('input,select,textarea,label').each(function (index, item) {
        var item_obj = $(item);
        if (item_obj.is('input:hidden')) {
            return;
        }
        if (item_obj.is('input:checkbox') || item_obj.is('input:radio')) {
            item_obj.attr('checked', false);
        } else if (item_obj.is('select')) {
            item_obj.val($('options:first', item_obj).val());
            item_obj.trigger('change');
        } else {
            item_obj.val('');
        }
    });

    total_forms_obj.val(parseInt(total_forms_obj.val(), 10) + 1);
}

function format_hour(date_obj) {
    // Format date_obj to HH:MM.
    'use strict';
    return pad2(date_obj.getHours()) + ':' + pad2(date_obj.getMinutes());
}

function showMessage(options) {
    // Show a message the same way we use django messages
    'use strict';

    var defaults = {
        'id': '#client-message-container',
        'replace': false,
        'hide': false
    };

    options = $.extend(defaults, options);

    if (options.replace) {
        $('.message').remove();
    }

    var container = $(options.id).clone();
    container.removeAttr('id');
    container.addClass('message');
    container.insertAfter(options.id);

    var alertbox = container.children('.alert-box');
    alertbox.addClass(options.tag);
    alertbox.prepend(options.msg);

    container.show();

    if (options.hide) {
        setTimeout(function() {container.hide();}, 5000);
    }

}

function prettyDate() {
    'use strict';
    $('*').find('*[data-time]').prettyDate({attribute:'data-time', interval: 60000, isUTC:true});
}

function paginatorSelector(selector) {
    'use strict';
    selector = typeof selector !== 'undefined' ? selector : '#page-select';
    $(selector).on('change', function() {
        window.location = $(this).val();
    });
}

function addAttributionOSM(map) {
    var attribution = '© OpenStreetMap contributors';
    map.attributionControl.addAttribution(attribution);
}

/*
 * Initialize date picker widget and set ISO date format
 * If the field is empty, pre-populate with current date
 * unless is explicity defined not to
 */
function initDatePicker (prepopulate_date) {
    var prepopulate_flag = (prepopulate_date === undefined) ? true : false;
    var $input = $('input.datepicker');
    $input.datepicker({
        autoSize: true,
        dateFormat: 'dd MM yy'
    });

    if ($input.val() === '' && prepopulate_flag) {
        $input.datepicker('setDate', new Date());
    }
    else {
        var savedDate = new Date($input.val());
        $input.datepicker('setDate', savedDate);
    }
}
<commit_msg>[fix bug 1115125] Missing favicon in tab display for some of the categories<commit_after>function hash_set_value(key, value) {
    'use strict';
    // Set value for key in hash
    var hash = $(location).attr('hash').substring(2).toLowerCase().replace(/\/$/, '');
    var keys;
    var values;

    if (!value) {
        value = '';
    }

    if (hash.length > 0) {
        keys = hash.split('/').filter(function(element, index) { return (index % 2 === 0); });
        values = hash.split('/').filter(function(element, index) { return (index % 2 === 1); });
    }
    else {
        keys = [];
        values = [];
    }

    var index_of_key = keys.indexOf(key);

    if (index_of_key > -1) {
        values[index_of_key] = value;
    }
    else {
        keys.push(key);
        values.push(value);
    }

    hash = '/';
    for (var i=0; i < keys.length; i++) {
        if (values[i].length > 0 ) {
            hash += keys[i] + '/' + values[i] + '/';
        }
    }

    $(location).attr('hash', hash);

    (function() {
        var url = $("link[rel='shortcut icon']").remove().attr('href');
        var favicon = document.createElement('link');
        favicon.type = 'image/x-icon';
        favicon.rel = 'shortcut icon';
        favicon.href = url;
        $('head').append(favicon);
    }());

}

function hash_get_value(key) {
    'use strict';
    // Get value for key in hash
    var hash = $(location).attr('hash').substring(2).toLowerCase();
    var keys = hash.split('/').filter(function(element, index) { return (index % 2 === 0); });
    var values = hash.split('/').filter(function(element, index) { return (index % 2 === 1); });
    var index_of_key = keys.indexOf(key);
    if (index_of_key > -1) {
        return values[index_of_key].toLowerCase();
    }

    return;
}

function set_dropdown_value(elm, value) {
    'use strict';
    elm.val(value);
}

function pad2(number) {
    // Pad numbers
    // snippet from
    // http://www.electrictoolbox.com/pad-number-two-digits-javascript/
    'use strict';
    return (number < 10 ? '0' : '') + number;
}

function append_to_formset(event) {
    'use strict';
    event.preventDefault();
    var button_obj = $(event.currentTarget);
    var formset_obj = button_obj.closest('.formset');
    var block_obj = formset_obj.find('.copyblock').first();
    var new_block_obj = block_obj.clone();
    var prefix = formset_obj.data('prefix');
    var total_forms_obj = formset_obj.parent().children('#id_' + prefix + '-TOTAL_FORMS');
    var append_after_obj = block_obj;

    if (button_obj.hasClass('voting-add-rangepoll-button') ||
        button_obj.hasClass('voting-add-radiopoll-button')) {
        var input = new_block_obj.find('#inner-rangepoll-formset, #inner-radiopoll-formset');
        input.not(':first').remove();
    }

    if (block_obj.siblings('.copyblock').length > 0) {
        append_after_obj = block_obj.siblings('.copyblock').last();
    }

    function attr_update(selector, attr, prepend){
        new_block_obj.find(selector + prefix + "]").each(function (index, item) {
            var item_obj = $(item);
            var obj_length = total_forms_obj.val().length;
            var prologue_length = 2 + prepend.length + prefix.length + obj_length;
            var item_id = item_obj.attr(attr).substr(prologue_length - obj_length);
            var newid = prepend + prefix + '-' + total_forms_obj.val() + item_id;
            item_obj.attr(attr, newid);
        });
    }
    attr_update('[id*=id_', 'id', 'id_');
    attr_update('[name*=', 'name', '');
    attr_update('[data-prefix*=', 'data-prefix', '');
    attr_update('[for*=id_', 'for', 'id_');

    new_block_obj.insertAfter(append_after_obj);

    // Cleanup
    new_block_obj.find('input,select,textarea,label').each(function (index, item) {
        var item_obj = $(item);
        if (item_obj.is('input:hidden')) {
            return;
        }
        if (item_obj.is('input:checkbox') || item_obj.is('input:radio')) {
            item_obj.attr('checked', false);
        } else if (item_obj.is('select')) {
            item_obj.val($('options:first', item_obj).val());
            item_obj.trigger('change');
        } else {
            item_obj.val('');
        }
    });

    total_forms_obj.val(parseInt(total_forms_obj.val(), 10) + 1);
}

function format_hour(date_obj) {
    // Format date_obj to HH:MM.
    'use strict';
    return pad2(date_obj.getHours()) + ':' + pad2(date_obj.getMinutes());
}

function showMessage(options) {
    // Show a message the same way we use django messages
    'use strict';

    var defaults = {
        'id': '#client-message-container',
        'replace': false,
        'hide': false
    };

    options = $.extend(defaults, options);

    if (options.replace) {
        $('.message').remove();
    }

    var container = $(options.id).clone();
    container.removeAttr('id');
    container.addClass('message');
    container.insertAfter(options.id);

    var alertbox = container.children('.alert-box');
    alertbox.addClass(options.tag);
    alertbox.prepend(options.msg);

    container.show();

    if (options.hide) {
        setTimeout(function() {container.hide();}, 5000);
    }

}

function prettyDate() {
    'use strict';
    $('*').find('*[data-time]').prettyDate({attribute:'data-time', interval: 60000, isUTC:true});
}

function paginatorSelector(selector) {
    'use strict';
    selector = typeof selector !== 'undefined' ? selector : '#page-select';
    $(selector).on('change', function() {
        window.location = $(this).val();
    });
}

function addAttributionOSM(map) {
    var attribution = '© OpenStreetMap contributors';
    map.attributionControl.addAttribution(attribution);
}

/*
 * Initialize date picker widget and set ISO date format
 * If the field is empty, pre-populate with current date
 * unless is explicity defined not to
 */
function initDatePicker (prepopulate_date) {
    var prepopulate_flag = (prepopulate_date === undefined) ? true : false;
    var $input = $('input.datepicker');
    $input.datepicker({
        autoSize: true,
        dateFormat: 'dd MM yy'
    });

    if ($input.val() === '' && prepopulate_flag) {
        $input.datepicker('setDate', new Date());
    }
    else {
        var savedDate = new Date($input.val());
        $input.datepicker('setDate', savedDate);
    }
}
<|endoftext|>


<commit_before>var gulp = require('gulp'),
		gp_rename = require('gulp-rename'),
		gp_uglify = require('gulp-uglify');
		gp_watch = require('gulp-watch'),
		concat = require('gulp-concat-util'),
		vinylPaths = require('vinyl-paths'),
		del = require('del'),
		scanner = require('i18next-scanner'),
		hash = require('sha1'),
		fs = require('fs');

var options = {
	attr: {
		list: ['data-i18n'],
		extensions: ['.html', '.htm']
	},
	func: {
		list: ['i18next.t', 'i18n.t', 't'],
		extensions: ['.js', '.jsx']
	},
	lngs: ['en', 'id'], // supported languages
	resource: {
		loadPath: 'www/i18n/{{lng}}.json',
		savePath: 'www/i18n/{{lng}}.json',
		jsonIndent: 2
	}
}

var customTransform = function _transform(file, enc, done) {
	var parser = this.parser;
	var content = fs.readFileSync(file.path, enc);

	parser.parseFuncFromString(content, {
		list: ['i18n._', 'i18next._', '_']
	}, function (key) {
		var value = key;
		var defaultKey = hash(value);
		parser.set(defaultKey, value);
	});

	done();
};

gulp.task('clean_i18n', function () {
	return del(['www/i18n/*.json']);
});

gulp.task('i18n', ['clean_i18n'], function () {
	return gulp.src(['src/**/*.js', '*.html'])
		.pipe(scanner(options, customTransform))
		.pipe(gulp.dest('./'));
});

gulp.task('vendor', function(){
	return gulp.src(['src/vendor/**/*.js'])
		.pipe(gulp.dest('www/js/vendor'));
});

gulp.task('globals', function(){
	return gulp.src(['src/globals/**/*.js'])
		.pipe(concat('globals.js'))
		.pipe(concat.header('Bot = {};'))
		.pipe(gulp.dest('www/js'));
});

gulp.task('definitions', function(){
	return gulp.src(['src/definitions/**/*.js'])
		.pipe(concat('definitions.js'))
		.pipe(concat.header('Bot.Definitions = function Definitions(){'))
		.pipe(concat.footer('};'))
		.pipe(gulp.dest('www/js'));
});

gulp.task('code_generators', function(){
	return gulp.src(['src/code_generators/**/*.js'])
		.pipe(concat('code_generators.js'))
		.pipe(concat.header('Bot.CodeGenerators = function CodeGenerators(){'))
		.pipe(concat.footer('};'))
		.pipe(gulp.dest('www/js'));
});

gulp.task('utils', function(){
	return gulp.src(['src/utils/**/*.js'])
		.pipe(concat('utils.js'))
		.pipe(gulp.dest('www/js'));
});

gulp.task('tours', function(){
	return gulp.src(['src/tours/**/*.js'])
		.pipe(concat('tours.js'))
		.pipe(gulp.dest('www/js'));
});

gulp.task('after_all', function(){
	return gulp.src(['src/after_all.js'])
		.pipe(gulp.dest('www/js'));
});

gulp.task('build', ['vendor', 'globals', 'definitions', 'code_generators', 'utils', 'tours', 'after_all'], function(){
	return gulp.src(['www/js/{globals,definitions,code_generators,utils,tours,after_all}.js'])
		.pipe(vinylPaths(del))
		.pipe(concat('binary-bot.js'))
		.pipe(gulp.dest('www/js'))
		.pipe(gp_rename('binary-bot.min.js'))
		.pipe(gp_uglify())
		.pipe(gulp.dest('www/js'));
});

gulp.task('watch', ['i18n', 'build'], function () {
	gp_watch(['src/**/*.js', '*.html'], function(){
		gulp.run('i18n');
	});
});
<commit_msg>Added build to gulp watch<commit_after>var gulp = require('gulp'),
		gp_rename = require('gulp-rename'),
		gp_uglify = require('gulp-uglify');
		gp_watch = require('gulp-watch'),
		concat = require('gulp-concat-util'),
		vinylPaths = require('vinyl-paths'),
		del = require('del'),
		scanner = require('i18next-scanner'),
		hash = require('sha1'),
		fs = require('fs');

var options = {
	attr: {
		list: ['data-i18n'],
		extensions: ['.html', '.htm']
	},
	func: {
		list: ['i18next.t', 'i18n.t', 't'],
		extensions: ['.js', '.jsx']
	},
	lngs: ['en', 'id'], // supported languages
	resource: {
		loadPath: 'www/i18n/{{lng}}.json',
		savePath: 'www/i18n/{{lng}}.json',
		jsonIndent: 2
	}
}

var customTransform = function _transform(file, enc, done) {
	var parser = this.parser;
	var content = fs.readFileSync(file.path, enc);

	parser.parseFuncFromString(content, {
		list: ['i18n._', 'i18next._', '_']
	}, function (key) {
		var value = key;
		var defaultKey = hash(value);
		parser.set(defaultKey, value);
	});

	done();
};

gulp.task('clean_i18n', function () {
	return del(['www/i18n/*.json']);
});

gulp.task('i18n', ['clean_i18n'], function () {
	return gulp.src(['src/**/*.js', '*.html'])
		.pipe(scanner(options, customTransform))
		.pipe(gulp.dest('./'));
});

gulp.task('vendor', function(){
	return gulp.src(['src/vendor/**/*.js'])
		.pipe(gulp.dest('www/js/vendor'));
});

gulp.task('globals', function(){
	return gulp.src(['src/globals/**/*.js'])
		.pipe(concat('globals.js'))
		.pipe(concat.header('Bot = {};'))
		.pipe(gulp.dest('www/js'));
});

gulp.task('definitions', function(){
	return gulp.src(['src/definitions/**/*.js'])
		.pipe(concat('definitions.js'))
		.pipe(concat.header('Bot.Definitions = function Definitions(){'))
		.pipe(concat.footer('};'))
		.pipe(gulp.dest('www/js'));
});

gulp.task('code_generators', function(){
	return gulp.src(['src/code_generators/**/*.js'])
		.pipe(concat('code_generators.js'))
		.pipe(concat.header('Bot.CodeGenerators = function CodeGenerators(){'))
		.pipe(concat.footer('};'))
		.pipe(gulp.dest('www/js'));
});

gulp.task('utils', function(){
	return gulp.src(['src/utils/**/*.js'])
		.pipe(concat('utils.js'))
		.pipe(gulp.dest('www/js'));
});

gulp.task('tours', function(){
	return gulp.src(['src/tours/**/*.js'])
		.pipe(concat('tours.js'))
		.pipe(gulp.dest('www/js'));
});

gulp.task('after_all', function(){
	return gulp.src(['src/after_all.js'])
		.pipe(gulp.dest('www/js'));
});

gulp.task('build', ['vendor', 'globals', 'definitions', 'code_generators', 'utils', 'tours', 'after_all'], function(){
	return gulp.src(['www/js/{globals,definitions,code_generators,utils,tours,after_all}.js'])
		.pipe(vinylPaths(del))
		.pipe(concat('binary-bot.js'))
		.pipe(gulp.dest('www/js'))
		.pipe(gp_rename('binary-bot.min.js'))
		.pipe(gp_uglify())
		.pipe(gulp.dest('www/js'));
});

gulp.task('watch', ['i18n', 'build'], function () {
	gp_watch(['src/**/*.js', '*.html'], function(){
		gulp.run(['i18n', 'build']);
	});
});
<|endoftext|>


<commit_before>"use strict";

let gulp = require("gulp");
let sass = require("gulp-sass");
let server = require('gulp-server-livereload');
let watch = require("gulp-watch");
let browserify = require('gulp-browserify');
let glob = require("multi-glob").glob;
let path = require("path");
let commandLineArgs = require('command-line-args');
let gulpif = require('gulp-if');
let uglify = require('gulp-uglify');
let cssnano = require('gulp-cssnano');
let ts = require('gulp-typescript');
let merge = require('merge2');
let tslint = require("gulp-tslint");
let tsfmt = require("gulp-tsfmt");
let changedInPlace = require("gulp-changed-in-place");

let cli = commandLineArgs([
    {name: 'production', alias: 'p', type: Boolean, defaultOption: false}
]);

let options = cli.parse();

let sassGlob = './sass/**/*.scss';
let tsGlob = "./src/**/*.ts";

let sassOutputGlob = './css/**/*.css';
let tsOutputGlob = './dist/**/*.ts';
let htmlGlob = './index.html';

function swallowError(error) {

    // If you want details of the error in the console
    console.log(error.toString());

    this.emit('end');
}

gulp.task('sass', () => {
    gulp.src(sassGlob)
        .pipe(sass().on('error', sass.logError))
        .pipe(gulpif(options.production, cssnano()))
        .pipe(gulp.dest('./css'));
});

gulp.task('ts', function () {
    var tsResult = gulp.src('src/**/*.ts')
        .pipe(ts({
            declaration: true,
            noExternalResolve: true,
            module: "commonjs"
        }));

    return merge([
        tsResult.dts.pipe(gulp.dest('dist')),
        tsResult.js
            .pipe(browserify({
                insertGlobals: false
            }))
            .pipe(gulpif(options.production, uglify()))
            .pipe(gulp.dest('dist'))
    ]);
});

gulp.task("watch", ['sass', 'ts'], () => {
    gulp.watch(sassGlob, ['sass']);
    gulp.watch(tsGlob, ['ts']);
});

gulp.task('serve', ["watch"], () => {
    gulp.src('./')
        .pipe(server({
            livereload: {
                enable: true,
                filter: function (filePath, cb) {
                    glob([tsOutputGlob, sassOutputGlob, htmlGlob], function (err, files) {
                        cb(files.map(function (file) {
                                return path.resolve(file);
                            }).indexOf(filePath) > -1);
                    });
                }
            },
            open: true
        }));
});

gulp.task('lint', function () {
    return gulp.src('./src/**/*.ts')
        .pipe(tslint())
        .pipe(tslint.report("prose", {
            emitError: false
        }))
});

gulp.task('format', () => {
    gulp.src('src/**/*.ts')
        .pipe(tsfmt({
            options: {}}))
        .pipe(gulp.dest(file => path.dirname(file.path)));
});

gulp.task('default', ['serve']);<commit_msg>made linter not look in typings<commit_after>"use strict";

let gulp = require("gulp");
let sass = require("gulp-sass");
let server = require('gulp-server-livereload');
let watch = require("gulp-watch");
let browserify = require('gulp-browserify');
let glob = require("multi-glob").glob;
let path = require("path");
let commandLineArgs = require('command-line-args');
let gulpif = require('gulp-if');
let uglify = require('gulp-uglify');
let cssnano = require('gulp-cssnano');
let ts = require('gulp-typescript');
let merge = require('merge2');
let tslint = require("gulp-tslint");
let tsfmt = require("gulp-tsfmt");
let changedInPlace = require("gulp-changed-in-place");

let cli = commandLineArgs([
    {name: 'production', alias: 'p', type: Boolean, defaultOption: false}
]);

let options = cli.parse();

let sassGlob = './sass/**/*.scss';
let tsGlob = "./src/**/*.ts";

let sassOutputGlob = './css/**/*.css';
let tsOutputGlob = './dist/**/*.ts';
let htmlGlob = './index.html';

function swallowError(error) {

    // If you want details of the error in the console
    console.log(error.toString());

    this.emit('end');
}

gulp.task('sass', () => {
    gulp.src(sassGlob)
        .pipe(sass().on('error', sass.logError))
        .pipe(gulpif(options.production, cssnano()))
        .pipe(gulp.dest('./css'));
});

gulp.task('ts', function () {
    var tsResult = gulp.src('src/**/*.ts')
        .pipe(ts({
            declaration: true,
            noExternalResolve: true,
            module: "commonjs"
        }));

    return merge([
        tsResult.dts.pipe(gulp.dest('dist')),
        tsResult.js
            .pipe(browserify({
                insertGlobals: false
            }))
            .pipe(gulpif(options.production, uglify()))
            .pipe(gulp.dest('dist'))
    ]);
});

gulp.task("watch", ['sass', 'ts'], () => {
    gulp.watch(sassGlob, ['sass']);
    gulp.watch(tsGlob, ['ts']);
});

gulp.task('serve', ["watch"], () => {
    gulp.src('./')
        .pipe(server({
            livereload: {
                enable: true,
                filter: function (filePath, cb) {
                    glob([tsOutputGlob, sassOutputGlob, htmlGlob], function (err, files) {
                        cb(files.map(function (file) {
                                return path.resolve(file);
                            }).indexOf(filePath) > -1);
                    });
                }
            },
            open: true
        }));
});

gulp.task('lint', function () {
    return gulp.src('./src/*.ts')
        .pipe(tslint())
        .pipe(tslint.report("prose", {
            emitError: false
        }))
});

gulp.task('format', () => {
    gulp.src('src/**/*.ts')
        .pipe(tsfmt({
            options: {}}))
        .pipe(gulp.dest(file => path.dirname(file.path)));
});

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


<commit_before>var placeholders = {};
var responseHandlersMap = {};
var ws = new WebSocket("ws://localhost:3001");
ws.onmessage = function (msg) {
	try {
		var data = JSON.parse(msg.data);
		if(data.type) {
			if(data.type === 'revo-config') {
				data.config.placeholders.forEach(function(ph){
					var name = Object.keys(ph)[0];
					placeholders[name] = ph[name];
				});
				placeholders.main = placeholders.main || 'body';
			} else if(data.type === 'revo-event') {
				if(data.event) {
					if(data.event === 'load') {
						var placeholder = placeholders[data.payload.placeholder] || placeholders.main;
			 			$(placeholder).load(['components', data.component, 'index.html'].join('/'));
					} else {
						if(data.event.endsWith('.response')) {
							if(data.payload && data.payload.error) {
								revo.handleError(data.payload.error);
							} else {
								var responseHandler = responseHandlersMap[data.event];
								invokeHandler(responseHandler);
							}
						}
					}
				}
			}
			setTimeout(function(){registerFormHandlers();}, 100);//todo:replace timeout with onload
		} else {
			console.log('unknown message type:', data);
		}
	} catch(err) {
		// console.log(err)
		console.log(msg.data);
	}
}
function invokeHandler(handler) {
	if(handler) {
		if(handler.startsWith('revo:')) {
			handler = /revo:(.*)/.exec(handler)[1];
			var action = /^(.*):.*/.exec(handler)[1];
			var data = /.*:(.*)/.exec(handler)[1];
			revo[action]({component:data});
		} else {
			console.log('todo: invoke custom handler', handler);
		}
	}
}
function registerFormHandlers() {
	delete responseHandlersMap;
	$('form').each(function(i, formEl){
		if($(formEl).attr('model')) {
			$(formEl).on('submit', function(event) {
				event.preventDefault();
				var model = $(formEl).attr('model');
				var action = $(formEl).attr('request');
				var responseHandler = $(formEl).attr('onresponse');
				if(responseHandler) {
					var key = model+':'+action+'.response';
					responseHandlersMap[key] = responseHandler;
				}
				var data = {};
				$(formEl).find('input').each(function(i, inputEl){
					var fieldName = $(inputEl).attr('field');
					if(fieldName) data[fieldName] = $(inputEl).val();
				})
				// console.log(action, model, data)
				revo.emit({ model: model, action: action, data: data });
			});
		}
	})
}
window.revo = {
	handle: function(data) {
		ws.send(JSON.stringify(data))
	},
	load: function(data) {
		console.log('loading:', data.component);
		//todo trigger custom browser event
		if(data.component) {
			revo.handle({
				type: "from-web",
				event: "load",
				component: data.component,
				payload: { placeholder: data.placeholder||"main" }
			});
		} else {
			console.log('missing "component" key in load()')
		}
	},
	emit: function(data) {
		revo.handle({
			type: "from-web",
			event: data.action,
			model: data.model,
			data: data.data
		});
	},
	handleError: function(error) {
		//todo: trigger a local error event
		alert(error.message)
	}
}

function dummy() {
	console.log('dummy handler');
}<commit_msg>cleanup<commit_after>var placeholders = {};
var responseHandlersMap = {};
var ws = new WebSocket("ws://localhost:3001");
ws.onmessage = function (msg) {
	try {
		var data = JSON.parse(msg.data);
		if(data.type) {
			if(data.type === 'revo-config') {
				data.config.placeholders.forEach(function(ph){
					var name = Object.keys(ph)[0];
					placeholders[name] = ph[name];
				});
				placeholders.main = placeholders.main || 'body';
			} else if(data.type === 'revo-event') {
				if(data.event) {
					if(data.event === 'load') {
						var placeholder = placeholders[data.payload.placeholder] || placeholders.main;
			 			$(placeholder).load(['components', data.component, 'index.html'].join('/'));
					} else {
						if(data.event.endsWith('.response')) {
							if(data.payload && data.payload.error) {
								revo.handleError(data.payload.error);
							} else {
								var responseHandler = responseHandlersMap[data.event];
								invokeHandler(responseHandler);
							}
						}
					}
				}
			}
			setTimeout(function(){registerFormHandlers();}, 100);//todo:replace timeout with onload
		} else {
			console.log('unknown message type:', data);
		}
	} catch(err) {
		// console.log(err)
		console.log(msg.data);
	}
}
function invokeHandler(handler) {
	if(handler) {
		if(handler.startsWith('revo:')) {
			handler = /revo:(.*)/.exec(handler)[1];
			var action = /^(.*):.*/.exec(handler)[1];
			var data = /.*:(.*)/.exec(handler)[1];
			revo[action]({component:data});
		} else {
			console.log('todo: invoke custom handler', handler);
		}
	}
}
function registerFormHandlers() {
	delete responseHandlersMap;
	$('form').each(function(i, formEl){
		if($(formEl).attr('model')) {
			$(formEl).on('submit', function(event) {
				event.preventDefault();
				var model = $(formEl).attr('model');
				var action = $(formEl).attr('request');
				var responseHandler = $(formEl).attr('onresponse');
				if(responseHandler) {
					var key = model+':'+action+'.response';
					responseHandlersMap[key] = responseHandler;
				}
				var data = {};
				$(formEl).find('input').each(function(i, inputEl){
					var fieldName = $(inputEl).attr('field');
					if(fieldName) data[fieldName] = $(inputEl).val();
				})
				// console.log(action, model, data)
				revo.emit({ model: model, action: action, data: data });
			});
		}
	})
}
window.revo = {
	handle: function(data) {
		ws.send(JSON.stringify(data))
	},
	load: function(data) {
		console.log('loading:', data.component);
		//todo trigger custom browser event
		if(data.component) {
			revo.handle({
				type: "from-web",
				event: "load",
				component: data.component,
				payload: { placeholder: data.placeholder||"main" }
			});
		} else {
			console.log('missing "component" key in load()')
		}
	},
	emit: function(data) {
		revo.handle({
			type: "from-web",
			event: data.action,
			model: data.model,
			data: data.data
		});
	},
	handleError: function(error) {
		//todo: trigger a local error event
		alert(error.message)
	}
}
<|endoftext|>


<commit_before>'use strict'

// Foundation for Emails
//
// The tasks are grouped into these categories:
//   1. Libraries
//   2. Variables
//   3. Cleaning files
//   4. Stylesheets
//   5. HTML
//   6. Syntax Transformer
//   7. GO FORTH AND BUILD
//   8. Serve/Watch Tasks

// 1. LIBRARIES
// - - - - - - - - - - - - - - -

var gulp = require('gulp'),
    sass = require('gulp-ruby-sass'),
    html2txt = require('gulp-html2txt'),
    inlineCss = require('gulp-inline-css'),
    rename = require('gulp-rename'),
    connect = require('gulp-connect'),
    minifyHTML = require('gulp-minify-html'),
    concat = require('gulp-concat'),
    grab   = require('gulp-zurb-foundation-email'),
    rimraf = require('rimraf');

var p = require('./package.json');

// 2. VARIABLES
// - - - - - - - - - - - - - - -

var dirs = {
  styles: 'scss/*.scss',
  html: 'html/*.html',
  js: 'js/**/*.js',
  images: 'images/*',
  build: './build'
};

// 3. CLEANIN' FILES
// - - - - - - - - - - - - - - -

// Clean build directory
gulp.task('clean', function(cb) {
  rimraf('./build', cb);
});

// Clean the HTML directory
gulp.task('clean:html', function(cb) {
  rimraf('./build/html', cb);
});

// Clean the JS directory
gulp.task('clean:js', function(cb) {
  rimraf('./build/js', cb);
})

// 4. STYLESHEETS
// - - - - - - - - - - - - - - -

// Compile SASS files
gulp.task('sass', function() {
  return gulp.src(dirs.styles)
    .pipe(sass({ "sourcemap=none": true, style: 'compact' }))
    .pipe(gulp.dest(dirs.build + '/css'))
    .pipe(connect.reload())
});

// Inline Styles
gulp.task('inline', function() {
  return gulp.src(dirs.build + '/*.html')
    .pipe(inlineCss())
    .pipe(rename(function(path) {
      path.basename += '-inline'
    }))
    .pipe(gulp.dest(dirs.build))
});

// 5. HTML
// - - - - - - - - - - - - - - -

// Minify and smoosh together HTML
gulp.task('minify-html', function() {
  var opts = {
    comments: false,
    spare: true
  };

  gulp.src(dirs.html)
    .pipe(minifyHTML(opts))
    .pipe(gulp.dest(dirs.build))
    .pipe(connect.reload())
});

// Convert HTML to plain text, just in caseies
gulp.task('html-plaintext', function() {
  gulp.src(dirs.html)
    .pipe(html2txt())
    .pipe(rename(function(path) {
      path.basename += '-plaintext'
    }))
    .pipe(gulp.dest(dirs.build));
});

// Task to copy HTML directly, without minifying
gulp.task('copy-html', function() {
  return gulp.src(dirs.html)
  .pipe(gulp.dest(dirs.build))
  .pipe(connect.reload())
});

// 6. Syntax Transformer
// - - - - - - - - - - - - - - -

// Copy jquery
gulp.task('jquery', function() {
  return gulp.src('node_modules/jquery/dist/jquery.js')
    .pipe(gulp.dest(dirs.build + '/js/'));
});

gulp.task('inky-prime', function() {
  return gulp.src(dirs.js)
    .pipe(concat('inky-prime.js'))
    .pipe(gulp.dest(dirs.build + '/js/'))
    .pipe(connect.reload());
})

gulp.task('js', ['clean:js', 'jquery'], function() {
  gulp.start('inky-prime');
});

gulp.task('query', function() {
  gulp.src(dirs.html)
    .pipe(grab('body'))
    .pipe(gulp.dest('./output'));
});

// 7. GO FORTH AND BUILD
// - - - - - - - - - - - - - - -

// Wipes build folder, then compiles SASS, then minifies and copies HTML
gulp.task('build', ['clean', 'sass', 'js'], function() {
  gulp.start('minify-html');
});

// 8. Serve/Watch Tasks
// - - - - - - - - - - - - - - -

// Starts a server
// Default Port: 8080
gulp.task('serve', function() {
  return connect.server({
    root: dirs.build,
    livereload: true
  });
});

// Start a server
// Watch all HTML files and SCSS files for changes
// Live reloads on change
gulp.task('watch', ['serve'], function() {
  gulp.watch([dirs.html], ['minify-html']);
  gulp.watch([dirs.js], ['js']);
  gulp.watch([dirs.styles], ['sass']);
});

// Default task
gulp.task('default', ['serve', 'watch']);
<commit_msg>Changed method name to something better so that it doesn't read 'grab body'<commit_after>'use strict'

// Foundation for Emails
//
// The tasks are grouped into these categories:
//   1. Libraries
//   2. Variables
//   3. Cleaning files
//   4. Stylesheets
//   5. HTML
//   6. Syntax Transformer
//   7. GO FORTH AND BUILD
//   8. Serve/Watch Tasks

// 1. LIBRARIES
// - - - - - - - - - - - - - - -

var gulp = require('gulp'),
    sass = require('gulp-ruby-sass'),
    html2txt = require('gulp-html2txt'),
    inlineCss = require('gulp-inline-css'),
    rename = require('gulp-rename'),
    connect = require('gulp-connect'),
    minifyHTML = require('gulp-minify-html'),
    concat = require('gulp-concat'),
    inky  = require('gulp-zurb-foundation-email'),
    rimraf = require('rimraf');

var p = require('./package.json');

// 2. VARIABLES
// - - - - - - - - - - - - - - -

var dirs = {
  styles: 'scss/*.scss',
  html: 'html/*.html',
  js: 'js/**/*.js',
  images: 'images/*',
  build: './build'
};

// 3. CLEANIN' FILES
// - - - - - - - - - - - - - - -

// Clean build directory
gulp.task('clean', function(cb) {
  rimraf('./build', cb);
});

// Clean the HTML directory
gulp.task('clean:html', function(cb) {
  rimraf('./build/html', cb);
});

// Clean the JS directory
gulp.task('clean:js', function(cb) {
  rimraf('./build/js', cb);
})

// 4. STYLESHEETS
// - - - - - - - - - - - - - - -

// Compile SASS files
gulp.task('sass', function() {
  return gulp.src(dirs.styles)
    .pipe(sass({ "sourcemap=none": true, style: 'compact' }))
    .pipe(gulp.dest(dirs.build + '/css'))
    .pipe(connect.reload())
});

// Inline Styles
gulp.task('inline', function() {
  return gulp.src(dirs.build + '/*.html')
    .pipe(inlineCss())
    .pipe(rename(function(path) {
      path.basename += '-inline'
    }))
    .pipe(gulp.dest(dirs.build))
});

// 5. HTML
// - - - - - - - - - - - - - - -

// Minify and smoosh together HTML
gulp.task('minify-html', function() {
  var opts = {
    comments: false,
    spare: true
  };

  gulp.src(dirs.html)
    .pipe(minifyHTML(opts))
    .pipe(gulp.dest(dirs.build))
    .pipe(connect.reload())
});

// Convert HTML to plain text, just in caseies
gulp.task('html-plaintext', function() {
  gulp.src(dirs.html)
    .pipe(html2txt())
    .pipe(rename(function(path) {
      path.basename += '-plaintext'
    }))
    .pipe(gulp.dest(dirs.build));
});

// Task to copy HTML directly, without minifying
gulp.task('copy-html', function() {
  return gulp.src(dirs.html)
  .pipe(gulp.dest(dirs.build))
  .pipe(connect.reload())
});

// 6. Syntax Transformer
// - - - - - - - - - - - - - - -

// Copy jquery
gulp.task('jquery', function() {
  return gulp.src('node_modules/jquery/dist/jquery.js')
    .pipe(gulp.dest(dirs.build + '/js/'));
});

gulp.task('inky-prime', function() {
  return gulp.src(dirs.js)
    .pipe(concat('inky-prime.js'))
    .pipe(gulp.dest(dirs.build + '/js/'))
    .pipe(connect.reload());
})

gulp.task('js', ['clean:js', 'jquery'], function() {
  gulp.start('inky-prime');
});

gulp.task('query', function() {
  gulp.src(dirs.html)
    .pipe(inky('body'))
    .pipe(gulp.dest('./output'));
});

// 7. GO FORTH AND BUILD
// - - - - - - - - - - - - - - -

// Wipes build folder, then compiles SASS, then minifies and copies HTML
gulp.task('build', ['clean', 'sass', 'js'], function() {
  gulp.start('minify-html');
});

// 8. Serve/Watch Tasks
// - - - - - - - - - - - - - - -

// Starts a server
// Default Port: 8080
gulp.task('serve', function() {
  return connect.server({
    root: dirs.build,
    livereload: true
  });
});

// Start a server
// Watch all HTML files and SCSS files for changes
// Live reloads on change
gulp.task('watch', ['serve'], function() {
  gulp.watch([dirs.html], ['minify-html']);
  gulp.watch([dirs.js], ['js']);
  gulp.watch([dirs.styles], ['sass']);
});

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


<commit_before>// Gulp packages
var gulp = require('gulp');
var sass = require('gulp-sass');
var fileinclude = require('gulp-file-include');
var inlineCss = require('gulp-inline-css');
var minifyHTML = require('gulp-minify-html');
var imagemin = require('gulp-imagemin');
var zip = require('gulp-zip');
var gulpIf = require('gulp-if');
var changed = require('gulp-changed');
var replace = require('gulp-replace');
var gutil = require('gulp-util');
var plumber = require('gulp-plumber');
var clipboard = require('gulp-clipboard');
var rename = require('gulp-rename');
var argv = require('yargs').argv;
var del = require('del');
var browserSync = require('browser-sync').create();
// Config file
var config = require('./gulp.config')();

// Local web server (Default localhost:8080)
// Pass argument --port=XXXX to change
gulp.task('connect', ['html'], function() {
  browserSync.init({
          // Serve files from the local directory
          server: {
              baseDir: config.localDir,
              directory: true
          },
          port: argv.port ? argv.port : config.browsersync.port,
          open: config.browsersync.open || (argv.open || false),
          notify: config.browsersync.notify
      });

    gulp.watch([config.sourcePath.sass, config.sourcePath.html], ['html']);
    gulp.watch(config.sourcePath.images, ['images:local']);

    gulp.watch(config.localFiles)
      .on('change', browserSync.reload);
});

// Build CSS files
gulp.task('sass', function() {
  log('Compiling SASS to CSS');
  return gulp.src('source/stylesheets/*.scss')
    .pipe(plumber({ errorHandler: handleError }))
    .pipe(sass())
    .pipe(gulp.dest(config.localDir + '/css'));
});

// Compile Layouts into HTML files
gulp.task('html', ['sass'], function() {
  log('Compiling HTML Templates');
  return gulp.src(config.sourcePath.layouts)
      .pipe(fileinclude({
          prefix: '{{ ',
          suffix: ' }}',
          basepath: '@file'
      }))
      .pipe(gulp.dest(config.localDir));
});

// Inline all CSS styles
// Minify HTML (Optional argument: --minify)
gulp.task('inline-css', ['html'], function() {
  log('Moving CSS inline');
  return gulp.src(config.localDir + '/*.html')
    .pipe(inlineCss({
            applyStyleTags: true,
            applyLinkTags: true,
            removeStyleTags: false,
            removeLinkTags: true
    }))
    .pipe(gulpIf(argv.minify, minifyHTML({ conditionals: true, spare: true, quotes: true})))
    .pipe(gulp.dest(config.productionDir));
});

// Copy Images folder
gulp.task('images:local', function () {
  log('Copying images');
  gulp.src(config.sourcePath.images)
    .pipe(gulp.dest(config.localDir + '/images'));
});

// Copy Images folder and Minify for production
gulp.task('images:production', function () {
  log('Minifying and Copying images');
  return gulp.src(config.sourcePath.images)
    .pipe(changed(config.productionDir + '/images'))
    .pipe(imagemin({ progressive: true }))
    .pipe(gulp.dest(config.productionDir + '/images'));
});

// Zip all files or images only
gulp.task('zip', ['images:production'], function () {
  if (! argv.zip)
    return;
  log('Compressing images into zip file');
  if(argv.zip == 'all') {
    return gulp.src(config.productionDir + '/**/**')
      .pipe(zip('all_files.zip'))
      .pipe(gulp.dest(config.productionDir));
  } else {
    return gulp.src(config.productionDir + '/images/**/*')
      .pipe(zip('images.zip'))
      .pipe(gulp.dest(config.productionDir));
  }
});

// Empty distribution folders
gulp.task('clean', function () {
  log('Cleaning up generated files');
  del([
    config.productionDir + '/**/**',
    config.localDir + '/**/**'
  ]);
});

// Copy a template to the clipboard
// Pass a template name as an argument --template=NAME or -t NAME
gulp.task('copy', function() {
  var template = argv.template ? argv.template : (argv.t ? argv.t : null);

  if (! template) {
    return log('***ERROR***: File missing.\n', 'red');
  }
  // Copy to Clipboard
  gulp.src(config.productionDir + '/' + template + '.html')
    .pipe(clipboard());

  return log('Copied ' + gutil.colors.magenta(template + '.html') + ' to clipboard.\n');
});

// Clone a Template
gulp.task('clone', function() {

  if (! argv.from) {
    return log('***ERROR***: You need to specify a source template.\n', 'red');
  }
  if (! argv.to) {
    return log('***ERROR***: You need to specify a name for the new template.\n', 'red');
  }
  // Clone layout
  gulp.src([config.sourceDir + '/layouts/' + argv.from + '.html'])
    .pipe(rename(argv.to + '.html'))
    .pipe(replace(argv.from, argv.to))
    .pipe(gulp.dest(config.sourceDir + '/layouts/'));
  // Clone partials
  gulp.src([config.sourceDir + '/partials/' + argv.from + '/*'])
    .pipe(gulp.dest(config.sourceDir + '/partials/' + argv.to));

  return gutil.log('Cloned to ' + gutil.colors.magenta(argv.to) + ' successfully.\n');
});
/* Tasks */
// Build for local and start browsersync server
gulp.task('serve', ['sass', 'html', 'images:local', 'connect']);

// Build for Production
gulp.task('build', ['sass', 'html', 'inline-css', 'images:production', 'zip']);

// Default
gulp.task('default', ['serve']);

/* Global functions */
// Injects custom messages into stream
function log(msg, color) {
  var msgColor = color ? gutil.colors[color] : gutil.colors.blue;
  if (typeof(msg) === 'object') {
    for (var item in msg) {
      if(msg.hasOwnProperty(item)) {
        gutil.log(msgColor(msg[item]));
      }
    }
  } else {
    gutil.log(msgColor(msg));
  }
}
// Handles error without breaking stream
function handleError(err) {
  gutil.beep();
  console.log(err.toString());
  this.emit('end');
}
<commit_msg>error messaging updated<commit_after>// Gulp packages
var gulp = require('gulp');
var sass = require('gulp-sass');
var fileinclude = require('gulp-file-include');
var inlineCss = require('gulp-inline-css');
var minifyHTML = require('gulp-minify-html');
var imagemin = require('gulp-imagemin');
var zip = require('gulp-zip');
var gulpIf = require('gulp-if');
var changed = require('gulp-changed');
var replace = require('gulp-replace');
var gutil = require('gulp-util');
var plumber = require('gulp-plumber');
var clipboard = require('gulp-clipboard');
var rename = require('gulp-rename');
var argv = require('yargs').argv;
var del = require('del');
var browserSync = require('browser-sync').create();
// Config file
var config = require('./gulp.config')();

// Local web server (Default localhost:8080)
// Pass argument --port=XXXX to change
gulp.task('connect', ['html'], function() {
  browserSync.init({
          // Serve files from the local directory
          server: {
              baseDir: config.localDir,
              directory: true
          },
          port: argv.port ? argv.port : config.browsersync.port,
          open: config.browsersync.open || (argv.open || false),
          notify: config.browsersync.notify
      });

    gulp.watch([config.sourcePath.sass, config.sourcePath.html], ['html']);
    gulp.watch(config.sourcePath.images, ['images:local']);

    gulp.watch(config.localFiles)
      .on('change', browserSync.reload);
});

// Build CSS files
gulp.task('sass', function() {
  log('Compiling SASS to CSS');
  return gulp.src('source/stylesheets/*.scss')
    .pipe(plumber({ errorHandler: handleError }))
    .pipe(sass())
    .pipe(gulp.dest(config.localDir + '/css'));
});

// Compile Layouts into HTML files
gulp.task('html', ['sass'], function() {
  log('Compiling HTML Templates');
  return gulp.src(config.sourcePath.layouts)
      .pipe(fileinclude({
          prefix: '{{ ',
          suffix: ' }}',
          basepath: '@file'
      }))
      .pipe(gulp.dest(config.localDir));
});

// Inline all CSS styles
// Minify HTML (Optional argument: --minify)
gulp.task('inline-css', ['html'], function() {
  log('Moving CSS inline');
  return gulp.src(config.localDir + '/*.html')
    .pipe(inlineCss({
            applyStyleTags: true,
            applyLinkTags: true,
            removeStyleTags: false,
            removeLinkTags: true
    }))
    .pipe(gulpIf(argv.minify, minifyHTML({ conditionals: true, spare: true, quotes: true})))
    .pipe(gulp.dest(config.productionDir));
});

// Copy Images folder
gulp.task('images:local', function () {
  log('Copying images');
  gulp.src(config.sourcePath.images)
    .pipe(gulp.dest(config.localDir + '/images'));
});

// Copy Images folder and Minify for production
gulp.task('images:production', function () {
  log('Minifying and Copying images');
  return gulp.src(config.sourcePath.images)
    .pipe(changed(config.productionDir + '/images'))
    .pipe(imagemin({ progressive: true }))
    .pipe(gulp.dest(config.productionDir + '/images'));
});

// Zip all files or images only
gulp.task('zip', ['images:production'], function () {
  if (! argv.zip)
    return;
  log('Compressing images into zip file');
  if(argv.zip == 'all') {
    return gulp.src(config.productionDir + '/**/**')
      .pipe(zip('all_files.zip'))
      .pipe(gulp.dest(config.productionDir));
  } else {
    return gulp.src(config.productionDir + '/images/**/*')
      .pipe(zip('images.zip'))
      .pipe(gulp.dest(config.productionDir));
  }
});

// Empty distribution folders
gulp.task('clean', function () {
  log('Cleaning up generated files');
  del([
    config.productionDir + '/**/**',
    config.localDir + '/**/**'
  ]);
});

// Copy a template to the clipboard
// Pass a template name as an argument --template=NAME or -t NAME
gulp.task('copy', function() {
  var template = argv.template ? argv.template : (argv.t ? argv.t : null);

  if (! template) {
    return log('***ERROR***: Name of template is missing.\n', 'red');
  }
  // Copy to Clipboard
  gulp.src(config.productionDir + '/' + template + '.html')
    .pipe(clipboard());

  return log('Copied ' + gutil.colors.magenta(template + '.html') + ' to clipboard.\n');
});

// Clone a Template
gulp.task('clone', function() {

  if (! argv.from) {
    return log('***ERROR***: You need to specify a source template.\n', 'red');
  }
  if (! argv.to) {
    return log('***ERROR***: You need to specify a name for the new template.\n', 'red');
  }
  // Clone layout
  gulp.src([config.sourceDir + '/layouts/' + argv.from + '.html'])
    .pipe(rename(argv.to + '.html'))
    .pipe(replace(argv.from, argv.to))
    .pipe(gulp.dest(config.sourceDir + '/layouts/'));
  // Clone partials
  gulp.src([config.sourceDir + '/partials/' + argv.from + '/*'])
    .pipe(gulp.dest(config.sourceDir + '/partials/' + argv.to));

  return gutil.log('Cloned to ' + gutil.colors.magenta(argv.to) + ' successfully.\n');
});
/* Tasks */
// Build for local and start browsersync server
gulp.task('serve', ['sass', 'html', 'images:local', 'connect']);

// Build for Production
gulp.task('build', ['sass', 'html', 'inline-css', 'images:production', 'zip']);

// Default
gulp.task('default', ['serve']);

/* Global functions */
// Injects custom messages into stream
function log(msg, color) {
  var msgColor = color ? gutil.colors[color] : gutil.colors.blue;
  if (typeof(msg) === 'object') {
    for (var item in msg) {
      if(msg.hasOwnProperty(item)) {
        gutil.log(msgColor(msg[item]));
      }
    }
  } else {
    gutil.log(msgColor(msg));
  }
}
// Handles error without breaking stream
function handleError(err) {
  gutil.beep();
  console.log(err.toString());
  this.emit('end');
}
<|endoftext|>


<commit_before>var gulp = require('gulp'),
    sourcemaps = require('gulp-sourcemaps'),
    autoprefixer = require('gulp-autoprefixer'),
    minifyCss = require('gulp-minify-css'),
    concat = require('gulp-concat'),
    uglify = require('gulp-uglify'),
    postcss = require('gulp-postcss'),
    watch = require('gulp-watch'),
    customProperties = require("postcss-custom-properties");

// Configure paths
var paths = {

  // Inputs
  js: ['./src/gui/js/**/*.js'],
  css: ['./src/gui/css/**/*.css'],

  // Static assets
  images: ['./src/gui/i/**/*.*'],
  templates: ['./src/**/*.html'],

  // Outputs
  jsOutput: 'main.js',
  cssOutput: 'styles.css',

  // Destinations
  jsDest: './dist/gui/js/',
  cssDest: './dist/gui/css/',
  imgDest: './dist/gui/i/',
  tplDest: './dist/'

};

// Process stylesheets
gulp.task('css', function () {
  return gulp.src(paths.css)
    .pipe(sourcemaps.init())
    .pipe(autoprefixer({browsers: ['last 2 versions']}))
    .pipe(postcss([customProperties()]))
    .pipe(concat(paths.cssOutput))
    .pipe(minifyCss({compatibility: 'ie8'}))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest(paths.cssDest));
});

// Concatenate and minify JavaScript
gulp.task('js', function () {
  return gulp.src(paths.js)
    .pipe(sourcemaps.init())
    .pipe(concat(paths.jsOutput))
    .pipe(uglify())
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest(paths.jsDest))
});

// Watch for changes in JS and CSS
gulp.task('watch', function() {
  watch(paths.css, function() {
    gulp.start(['css']);
  });
  watch(paths.js, function() {
    gulp.start(['js']);
  });
  watch(paths.images, function() {
    gulp.start(['images']);
  });
  watch(paths.templates, function() {
    gulp.start(['templates']);
  });
});

// Copy image assets into /dist
gulp.task('images', function(){
  gulp.src(paths.images)
    .pipe(gulp.dest(paths.imgDest));
});

// Copy template assets into /dist
gulp.task('templates', function () {
  gulp.src(paths.templates)
    .pipe(gulp.dest(paths.tplDest));
});

gulp.task('default', ['watch', 'css', 'js', 'images', 'templates']);
<commit_msg>Phrasing...<commit_after>var gulp = require('gulp'),
    sourcemaps = require('gulp-sourcemaps'),
    autoprefixer = require('gulp-autoprefixer'),
    minifyCss = require('gulp-minify-css'),
    concat = require('gulp-concat'),
    uglify = require('gulp-uglify'),
    postcss = require('gulp-postcss'),
    watch = require('gulp-watch'),
    customProperties = require("postcss-custom-properties");

// Configure paths
var paths = {

  // Inputs
  js: ['./src/gui/js/**/*.js'],
  css: ['./src/gui/css/**/*.css'],

  // Static assets
  images: ['./src/gui/i/**/*.*'],
  templates: ['./src/**/*.html'],

  // Outputs
  jsOutput: 'main.js',
  cssOutput: 'styles.css',

  // Destinations
  jsDest: './dist/gui/js/',
  cssDest: './dist/gui/css/',
  imgDest: './dist/gui/i/',
  tplDest: './dist/'

};

// Process stylesheets
gulp.task('css', function () {
  return gulp.src(paths.css)
    .pipe(sourcemaps.init())
    .pipe(autoprefixer({browsers: ['last 2 versions']}))
    .pipe(postcss([customProperties()]))
    .pipe(concat(paths.cssOutput))
    .pipe(minifyCss({compatibility: 'ie8'}))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest(paths.cssDest));
});

// Concatenate and minify JavaScript
gulp.task('js', function () {
  return gulp.src(paths.js)
    .pipe(sourcemaps.init())
    .pipe(concat(paths.jsOutput))
    .pipe(uglify())
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest(paths.jsDest))
});

// Watch for changes
gulp.task('watch', function() {
  watch(paths.css, function() {
    gulp.start(['css']);
  });
  watch(paths.js, function() {
    gulp.start(['js']);
  });
  watch(paths.images, function() {
    gulp.start(['images']);
  });
  watch(paths.templates, function() {
    gulp.start(['templates']);
  });
});

// Copy image assets into /dist
gulp.task('images', function(){
  gulp.src(paths.images)
    .pipe(gulp.dest(paths.imgDest));
});

// Copy template assets into /dist
gulp.task('templates', function () {
  gulp.src(paths.templates)
    .pipe(gulp.dest(paths.tplDest));
});

gulp.task('default', ['watch', 'css', 'js', 'images', 'templates']);
<|endoftext|>


<commit_before>// ## Globals
var argv         = require('minimist')(process.argv.slice(2));
var autoprefixer = require('gulp-autoprefixer');
var browserSync  = require('browser-sync').create();
var changed      = require('gulp-changed');
var concat       = require('gulp-concat');
var flatten      = require('gulp-flatten');
var gulp         = require('gulp');
var gulpif       = require('gulp-if');
var imagemin     = require('gulp-imagemin');
var jshint       = require('gulp-jshint');
var lazypipe     = require('lazypipe');
var less         = require('gulp-less');
var merge        = require('merge-stream');
var minifyCss    = require('gulp-minify-css');
var plumber      = require('gulp-plumber');
var rev          = require('gulp-rev');
var runSequence  = require('run-sequence');
var sass         = require('gulp-sass');
var sourcemaps   = require('gulp-sourcemaps');
var uglify       = require('gulp-uglify');
var uncss        = require('gulp-uncss');

// See https://github.com/austinpray/asset-builder
var manifest = require('asset-builder')('./assets/manifest.json');

// `path` - Paths to base asset directories. With trailing slashes.
// - `path.source` - Path to the source files. Default: `assets/`
// - `path.dist` - Path to the build directory. Default: `dist/`
var path = manifest.paths;

// `config` - Store arbitrary configuration values here.
var config = manifest.config || {};

// `globs` - These ultimately end up in their respective `gulp.src`.
// - `globs.js` - Array of asset-builder JS dependency objects. Example:
//   ```
//   {type: 'js', name: 'main.js', globs: []}
//   ```
// - `globs.css` - Array of asset-builder CSS dependency objects. Example:
//   ```
//   {type: 'css', name: 'main.css', globs: []}
//   ```
// - `globs.fonts` - Array of font path globs.
// - `globs.images` - Array of image path globs.
// - `globs.bower` - Array of all the main Bower files.
var globs = manifest.globs;

// `project` - paths to first-party assets.
// - `project.js` - Array of first-party JS assets.
// - `project.css` - Array of first-party CSS assets.
var project = manifest.getProjectGlobs();

// CLI options
var enabled = {
  // Enable static asset revisioning when `--production`
  rev: argv.production,
  // Disable source maps when `--production`
  maps: !argv.production,
  // Fail styles task on error when `--production`
  failStyleTask: argv.production,
  // Fail due to JSHint warnings only when `--production`
  failJSHint: argv.production,
  // Strip debug statments from javascript when `--production`
  stripJSDebug: argv.production
};

// Path to the compiled assets manifest in the dist directory
var revManifest = path.dist + 'assets.json';

// ## Reusable Pipelines
// See https://github.com/OverZealous/lazypipe

// ### CSS processing pipeline
// Example
// ```
// gulp.src(cssFiles)
//   .pipe(cssTasks('main.css')
//   .pipe(gulp.dest(path.dist + 'styles'))
// ```
var cssTasks = function(filename) {
  return lazypipe()
    .pipe(function() {
      return gulpif(!enabled.failStyleTask, plumber());
    })
    .pipe(function() {
      return gulpif(enabled.maps, sourcemaps.init());
    })
    .pipe(function() {
      return gulpif('*.less', less());
    })
    .pipe(function() {
      return gulpif('*.scss', sass({
        outputStyle: 'nested', // libsass doesn't support expanded yet
        precision: 10,
        includePaths: ['.'],
        errLogToConsole: !enabled.failStyleTask
      }));
    })
    .pipe(concat, filename)
    .pipe(autoprefixer, {
      browsers: [
        'last 2 versions',
        'ie 8',
        'ie 9',
        'android 2.3',
        'android 4',
        'opera 12'
      ]
    })
    .pipe(minifyCss, {
      advanced: false,
      rebase: false
    })
    .pipe(function() {
      return gulpif(enabled.rev, rev());
    })
    .pipe(function() {
      return gulpif(enabled.maps, sourcemaps.write('.', {
        sourceRoot: 'assets/styles/'
      }));
    })();
};

// ### JS processing pipeline
// Example
// ```
// gulp.src(jsFiles)
//   .pipe(jsTasks('main.js')
//   .pipe(gulp.dest(path.dist + 'scripts'))
// ```
var jsTasks = function(filename) {
  return lazypipe()
    .pipe(function() {
      return gulpif(enabled.maps, sourcemaps.init());
    })
    .pipe(concat, filename)
    .pipe(uglify, {
      compress: {
        'drop_debugger': enabled.stripJSDebug
      }
    })
    .pipe(function() {
      return gulpif(enabled.rev, rev());
    })
    .pipe(function() {
      return gulpif(enabled.maps, sourcemaps.write('.', {
        sourceRoot: 'assets/scripts/'
      }));
    })();
};

// ### Write to rev manifest
// If there are any revved files then write them to the rev manifest.
// See https://github.com/sindresorhus/gulp-rev
var writeToManifest = function(directory) {
  return lazypipe()
    .pipe(gulp.dest, path.dist + directory)
    .pipe(browserSync.stream, {match: '**/*.{js,css}'})
    .pipe(rev.manifest, revManifest, {
      base: path.dist,
      merge: true
    })
    .pipe(gulp.dest, path.dist)();
};

// ## Gulp tasks
// Run `gulp -T` for a task summary

// ### Styles
// `gulp styles` - Compiles, combines, and optimizes Bower CSS and project CSS.
// By default this task will only log a warning if a precompiler error is
// raised. If the `--production` flag is set: this task will fail outright.
gulp.task('styles', ['wiredep'], function() {
  var merged = merge();
  manifest.forEachDependency('css', function(dep) {
    var cssTasksInstance = cssTasks(dep.name);
    if (!enabled.failStyleTask) {
      cssTasksInstance.on('error', function(err) {
        console.error(err.message);
        this.emit('end');
      });
    }
    merged.add(gulp.src(dep.globs, {base: 'styles'})
      .pipe(cssTasksInstance));
  });
  return merged
    .pipe(writeToManifest('styles'));
});

// ### Scripts
// `gulp scripts` - Runs JSHint then compiles, combines, and optimizes Bower JS
// and project JS.
gulp.task('scripts', ['jshint'], function() {
  var merged = merge();
  manifest.forEachDependency('js', function(dep) {
    merged.add(
      gulp.src(dep.globs, {base: 'scripts'})
        .pipe(jsTasks(dep.name))
    );
  });
  return merged
    .pipe(writeToManifest('scripts'));
});

// ### Fonts
// `gulp fonts` - Grabs all the fonts and outputs them in a flattened directory
// structure. See: https://github.com/armed/gulp-flatten
gulp.task('fonts', function() {
  return gulp.src(globs.fonts)
    .pipe(flatten())
    .pipe(gulp.dest(path.dist + 'fonts'))
    .pipe(browserSync.stream());
});

// ### Images
// `gulp images` - Run lossless compression on all the images.
gulp.task('images', function() {
  return gulp.src(globs.images)
    .pipe(imagemin({
      progressive: true,
      interlaced: true,
      svgoPlugins: [{removeUnknownsAndDefaults: false}, {cleanupIDs: false}]
    }))
    .pipe(gulp.dest(path.dist + 'images'))
    .pipe(browserSync.stream());
});

// ### JSHint
// `gulp jshint` - Lints configuration JSON and project JS.
gulp.task('jshint', function() {
  return gulp.src([
    'bower.json', 'gulpfile.js'
  ].concat(project.js))
    .pipe(jshint())
    .pipe(jshint.reporter('jshint-stylish'))
    .pipe(gulpif(enabled.failJSHint, jshint.reporter('fail')));
});

// ### Clean
// `gulp clean` - Deletes the build folder entirely.
gulp.task('clean', require('del').bind(null, [path.dist]));

// ### Watch
// `gulp watch` - Use BrowserSync to proxy your dev server and synchronize code
// changes across devices. Specify the hostname of your dev server at
// `manifest.config.devUrl`. When a modification is made to an asset, run the
// build step for that asset and inject the changes into the page.
// See: http://www.browsersync.io
gulp.task('watch', function() {
  browserSync.init({
    files: ['{lib,templates}/**/*.php', '*.php'],
    proxy: config.devUrl,
    snippetOptions: {
      whitelist: ['/wp-admin/admin-ajax.php'],
      blacklist: ['/wp-admin/**']
    }
  });
  gulp.watch([path.source + 'styles/**/*'], ['styles']);
  gulp.watch([path.source + 'scripts/**/*'], ['jshint', 'scripts']);
  gulp.watch([path.source + 'fonts/**/*'], ['fonts']);
  gulp.watch([path.source + 'images/**/*'], ['images']);
  gulp.watch(['bower.json', 'assets/manifest.json'], ['build']);
});

// ### Build
// `gulp build` - Run all the build tasks but don't clean up beforehand.
// Generally you should be running `gulp` instead of `gulp build`.
gulp.task('build', function(callback) {
  runSequence('styles',
              'scripts',
              ['fonts', 'images'],
              callback);
});

// ### Wiredep
// `gulp wiredep` - Automatically inject Less and Sass Bower dependencies. See
// https://github.com/taptapship/wiredep
gulp.task('wiredep', function() {
  var wiredep = require('wiredep').stream;
  return gulp.src(project.css)
    .pipe(wiredep())
    .pipe(changed(path.source + 'styles', {
      hasChanged: changed.compareSha1Digest
    }))
    .pipe(gulp.dest(path.source + 'styles'));
});

// ### Gulp
// `gulp` - Run a complete build. To compile for production run `gulp --production`.
gulp.task('default', ['clean'], function() {
  gulp.start('build');
});
<commit_msg>write simple gulp uncss task<commit_after>// ## Globals
var argv         = require('minimist')(process.argv.slice(2));
var autoprefixer = require('gulp-autoprefixer');
var browserSync  = require('browser-sync').create();
var changed      = require('gulp-changed');
var concat       = require('gulp-concat');
var flatten      = require('gulp-flatten');
var gulp         = require('gulp');
var gulpif       = require('gulp-if');
var imagemin     = require('gulp-imagemin');
var jshint       = require('gulp-jshint');
var lazypipe     = require('lazypipe');
var less         = require('gulp-less');
var merge        = require('merge-stream');
var minifyCss    = require('gulp-minify-css');
var plumber      = require('gulp-plumber');
var rev          = require('gulp-rev');
var runSequence  = require('run-sequence');
var sass         = require('gulp-sass');
var sourcemaps   = require('gulp-sourcemaps');
var uglify       = require('gulp-uglify');
var uncss        = require('gulp-uncss');

// See https://github.com/austinpray/asset-builder
var manifest = require('asset-builder')('./assets/manifest.json');

// `path` - Paths to base asset directories. With trailing slashes.
// - `path.source` - Path to the source files. Default: `assets/`
// - `path.dist` - Path to the build directory. Default: `dist/`
var path = manifest.paths;

// `config` - Store arbitrary configuration values here.
var config = manifest.config || {};

// `globs` - These ultimately end up in their respective `gulp.src`.
// - `globs.js` - Array of asset-builder JS dependency objects. Example:
//   ```
//   {type: 'js', name: 'main.js', globs: []}
//   ```
// - `globs.css` - Array of asset-builder CSS dependency objects. Example:
//   ```
//   {type: 'css', name: 'main.css', globs: []}
//   ```
// - `globs.fonts` - Array of font path globs.
// - `globs.images` - Array of image path globs.
// - `globs.bower` - Array of all the main Bower files.
var globs = manifest.globs;

// `project` - paths to first-party assets.
// - `project.js` - Array of first-party JS assets.
// - `project.css` - Array of first-party CSS assets.
var project = manifest.getProjectGlobs();

// CLI options
var enabled = {
  // Enable static asset revisioning when `--production`
  rev: argv.production,
  // Disable source maps when `--production`
  maps: !argv.production,
  // Fail styles task on error when `--production`
  failStyleTask: argv.production,
  // Fail due to JSHint warnings only when `--production`
  failJSHint: argv.production,
  // Strip debug statments from javascript when `--production`
  stripJSDebug: argv.production
};

// Path to the compiled assets manifest in the dist directory
var revManifest = path.dist + 'assets.json';

// ## Reusable Pipelines
// See https://github.com/OverZealous/lazypipe

// ### CSS processing pipeline
// Example
// ```
// gulp.src(cssFiles)
//   .pipe(cssTasks('main.css')
//   .pipe(gulp.dest(path.dist + 'styles'))
// ```
var cssTasks = function(filename) {
  return lazypipe()
    .pipe(function() {
      return gulpif(!enabled.failStyleTask, plumber());
    })
    .pipe(function() {
      return gulpif(enabled.maps, sourcemaps.init());
    })
    .pipe(function() {
      return gulpif('*.less', less());
    })
    .pipe(function() {
      return gulpif('*.scss', sass({
        outputStyle: 'nested', // libsass doesn't support expanded yet
        precision: 10,
        includePaths: ['.'],
        errLogToConsole: !enabled.failStyleTask
      }));
    })
    .pipe(concat, filename)
    .pipe(autoprefixer, {
      browsers: [
        'last 2 versions',
        'ie 8',
        'ie 9',
        'android 2.3',
        'android 4',
        'opera 12'
      ]
    })
    .pipe(minifyCss, {
      advanced: false,
      rebase: false
    })
    .pipe(function() {
      return gulpif(enabled.rev, rev());
    })
    .pipe(function() {
      return gulpif(enabled.maps, sourcemaps.write('.', {
        sourceRoot: 'assets/styles/'
      }));
    })();
};

// ### JS processing pipeline
// Example
// ```
// gulp.src(jsFiles)
//   .pipe(jsTasks('main.js')
//   .pipe(gulp.dest(path.dist + 'scripts'))
// ```
var jsTasks = function(filename) {
  return lazypipe()
    .pipe(function() {
      return gulpif(enabled.maps, sourcemaps.init());
    })
    .pipe(concat, filename)
    .pipe(uglify, {
      compress: {
        'drop_debugger': enabled.stripJSDebug
      }
    })
    .pipe(function() {
      return gulpif(enabled.rev, rev());
    })
    .pipe(function() {
      return gulpif(enabled.maps, sourcemaps.write('.', {
        sourceRoot: 'assets/scripts/'
      }));
    })();
};

// ### Write to rev manifest
// If there are any revved files then write them to the rev manifest.
// See https://github.com/sindresorhus/gulp-rev
var writeToManifest = function(directory) {
  return lazypipe()
    .pipe(gulp.dest, path.dist + directory)
    .pipe(browserSync.stream, {match: '**/*.{js,css}'})
    .pipe(rev.manifest, revManifest, {
      base: path.dist,
      merge: true
    })
    .pipe(gulp.dest, path.dist)();
};

// ## Gulp tasks
// Run `gulp -T` for a task summary

// ### Styles
// `gulp styles` - Compiles, combines, and optimizes Bower CSS and project CSS.
// By default this task will only log a warning if a precompiler error is
// raised. If the `--production` flag is set: this task will fail outright.
gulp.task('styles', ['wiredep'], function() {
  var merged = merge();
  manifest.forEachDependency('css', function(dep) {
    var cssTasksInstance = cssTasks(dep.name);
    if (!enabled.failStyleTask) {
      cssTasksInstance.on('error', function(err) {
        console.error(err.message);
        this.emit('end');
      });
    }
    merged.add(gulp.src(dep.globs, {base: 'styles'})
      .pipe(cssTasksInstance));
  });
  return merged
    .pipe(writeToManifest('styles'));
});

// ### Scripts
// `gulp scripts` - Runs JSHint then compiles, combines, and optimizes Bower JS
// and project JS.
gulp.task('scripts', ['jshint'], function() {
  var merged = merge();
  manifest.forEachDependency('js', function(dep) {
    merged.add(
      gulp.src(dep.globs, {base: 'scripts'})
        .pipe(jsTasks(dep.name))
    );
  });
  return merged
    .pipe(writeToManifest('scripts'));
});

// ### Fonts
// `gulp fonts` - Grabs all the fonts and outputs them in a flattened directory
// structure. See: https://github.com/armed/gulp-flatten
gulp.task('fonts', function() {
  return gulp.src(globs.fonts)
    .pipe(flatten())
    .pipe(gulp.dest(path.dist + 'fonts'))
    .pipe(browserSync.stream());
});

// ### Images
// `gulp images` - Run lossless compression on all the images.
gulp.task('images', function() {
  return gulp.src(globs.images)
    .pipe(imagemin({
      progressive: true,
      interlaced: true,
      svgoPlugins: [{removeUnknownsAndDefaults: false}, {cleanupIDs: false}]
    }))
    .pipe(gulp.dest(path.dist + 'images'))
    .pipe(browserSync.stream());
});

// ### JSHint
// `gulp jshint` - Lints configuration JSON and project JS.
gulp.task('jshint', function() {
  return gulp.src([
    'bower.json', 'gulpfile.js'
  ].concat(project.js))
    .pipe(jshint())
    .pipe(jshint.reporter('jshint-stylish'))
    .pipe(gulpif(enabled.failJSHint, jshint.reporter('fail')));
});

// ### Clean
// `gulp clean` - Deletes the build folder entirely.
gulp.task('clean', require('del').bind(null, [path.dist]));

// ### Watch
// `gulp watch` - Use BrowserSync to proxy your dev server and synchronize code
// changes across devices. Specify the hostname of your dev server at
// `manifest.config.devUrl`. When a modification is made to an asset, run the
// build step for that asset and inject the changes into the page.
// See: http://www.browsersync.io
gulp.task('watch', function() {
  browserSync.init({
    files: ['{lib,templates}/**/*.php', '*.php'],
    proxy: config.devUrl,
    snippetOptions: {
      whitelist: ['/wp-admin/admin-ajax.php'],
      blacklist: ['/wp-admin/**']
    }
  });
  gulp.watch([path.source + 'styles/**/*'], ['styles']);
  gulp.watch([path.source + 'scripts/**/*'], ['jshint', 'scripts']);
  gulp.watch([path.source + 'fonts/**/*'], ['fonts']);
  gulp.watch([path.source + 'images/**/*'], ['images']);
  gulp.watch(['bower.json', 'assets/manifest.json'], ['build']);
});

// ### Build
// `gulp build` - Run all the build tasks but don't clean up beforehand.
// Generally you should be running `gulp` instead of `gulp build`.
gulp.task('build', function(callback) {
  runSequence('styles',
              'scripts',
              ['fonts', 'images'],
              callback);
});

// ### Wiredep
// `gulp wiredep` - Automatically inject Less and Sass Bower dependencies. See
// https://github.com/taptapship/wiredep
gulp.task('wiredep', function() {
  var wiredep = require('wiredep').stream;
  return gulp.src(project.css)
    .pipe(wiredep())
    .pipe(changed(path.source + 'styles', {
      hasChanged: changed.compareSha1Digest
    }))
    .pipe(gulp.dest(path.source + 'styles'));
});

// ### Gulp
// `gulp` - Run a complete build. To compile for production run `gulp --production`.
gulp.task('default', ['clean'], function() {
  gulp.start('build');
});

// ### UNCSS
// `gulp uncss`
gulp.task('uncss', function() {
  return gulp.src([
      'dist/styles/main-40c21f7c.css'
    ])
    .pipe(uncss({
      html: [
        'http://vagrant.local/jchck/',
        'http://vagrant.local/jchck/hire-justin',
        'http://localhost:3000/jchck/follow-along/'
      ]
    }))
    .pipe(gulp.dest('dist/styles/'));
});<|endoftext|>


<commit_before>var gulp = require('gulp'),
    browserify = require('browserify'),
    transform = require('vinyl-transform'),
    reactify = require('reactify'),
    rename = require('gulp-rename'),
    uglify = require('gulp-uglify');

gulp.task('browserify', function () {
  var browserified = transform(function(filename) {
    var b = browserify({
            entries: [filename],
            debug: true,
            transform: [reactify],
            extensions: [".html",".jsx"]
        });
    return b.bundle();
  });

  return gulp.src(['admin/main.jsx'])
    .pipe(browserified)
    .pipe(uglify())
    .pipe(rename('admin.js'))
    .pipe(gulp.dest('server/build/'));
});

gulp.task('release', function () {
  var browserified = transform(function(filename) {
    var b = browserify({
            entries: [filename],
            debug: true,
            transform: [reactify],
            extensions: [".html",".jsx"]
        });
    return b.bundle();
  });

  return gulp.src(['admin/main.jsx'])
    .pipe(browserified)
    .pipe(uglify())
    .pipe(rename('admin.js'))
    .pipe(gulp.dest('server/build/'));
});

gulp.task('watch', function() {
    gulp.watch(["admin/**"], ["browserify"]);
});

gulp.task('default', ["browserify", "watch"]);

gulp.on('error', function(){
    console.log('error');
});<commit_msg>Updated gulpfile<commit_after>var gulp = require('gulp'),
    browserify = require('browserify'),
    transform = require('vinyl-transform'),
    reactify = require('reactify'),
    rename = require('gulp-rename'),
    uglify = require('gulp-uglify');

gulp.task('browserify', function () {
  var browserified = transform(function(filename) {
    var b = browserify({
            entries: [filename],
            debug: true,
            transform: [reactify],
            extensions: [".html",".jsx"]
        });
    return b.bundle();
  });

  return gulp.src(['client/main.jsx'])
    .pipe(browserified)
    .pipe(uglify())
    .pipe(rename('main.js'))
    .pipe(gulp.dest('server/build/'));
});

gulp.task('release', function () {
  var browserified = transform(function(filename) {
    var b = browserify({
            entries: [filename],
            debug: true,
            transform: [reactify],
            extensions: [".html",".jsx"]
        });
    return b.bundle();
  });

  return gulp.src(['client/main.jsx'])
    .pipe(browserified)
    .pipe(uglify())
    .pipe(rename('main.js'))
    .pipe(gulp.dest('server/build/'));
});

gulp.task('watch', function() {
    gulp.watch(["admin/**"], ["browserify"]);
});

gulp.task('default', ["browserify", "watch"]);

gulp.on('error', function(){
    console.log('error');
});
<|endoftext|>


<commit_before>var gulp = require('gulp');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var changed = require('gulp-changed');
var data = require('gulp-data');
var gm = require('gulp-gm');
var jade = require('gulp-jade');
var jshint = require('gulp-jshint');
var watch = require('gulp-watch');
var rimraf = require('rimraf');
var runSequence = require('run-sequence');

// paths for the development and build directories
var paths = {
	app: "./app",
	build: "./app/build"
};

// Jade task: Pull in image data from the json file and
// compile the Jade file into html, and copy to the build folder
gulp.task('jade', function() {
	var stream = gulp.src(paths.app + '/index.jade')
		.pipe(data(function(file) {
			return require(paths.app + '/data.json');
		}))
		.pipe(jade())
		.pipe(gulp.dest(paths.build))
		.pipe(reload({stream: true})); // reload the browser whenever we want to show changes
	// require() caches the json file, so we need to clear it
	// from the cache after the task finishes, or else when we
	// call require() on the json file again during the
	// watch task to get the new file,
	// we get the original cached file instead
	stream.on('end', function() {
		delete require.cache[require.resolve(paths.app + '/data.json')];
	});
	return stream;
});

// css task: copy stylesheets to the build folder and reload the browser to show changes
gulp.task('css', function() {
	return gulp.src(paths.app + '/style.css')
		.pipe(gulp.dest(paths.build))
		.pipe(reload({stream: true}));
});

// scripts task: run JS scripts through JSHint and copy to build folder, reload browser to show changes
// JSHint ignores files listed in the .jshintignore file
gulp.task('scripts', function() {
	return gulp.src(paths.app + '/*.js')
		.pipe(jshint())
		.pipe(jshint.reporter('default'))
		.pipe(gulp.dest(paths.build))
		.pipe(reload({stream: true}));
});

// GraphicsMagick task: resize images to a set width,
// while the height stays at the original aspect ratio.
// To save time, only process images that have been changed.
var resizedImageWidth = 1366;
gulp.task('gm', function() {
	return gulp.src(paths.app + '/images/*.JPG')
		.pipe(changed(paths.build + '/images'))
		.pipe(gm(function(gmfile) {
			return gmfile.resize(resizedImageWidth);
		}))
		.pipe(gulp.dest(paths.build + '/images'))
		.pipe(reload({stream: true}));
});

// Watch task: whenever a file is changed, run its corresponding task
gulp.task('watch', function() {
	watch(paths.app + '/style.css', function() {
		gulp.start('css');
	});
	watch([paths.app + '/index.jade', paths.app + '/data.json'], function() {
		gulp.start('jade');
	});
	watch(paths.app + '/*.js', function() {
		gulp.start('scripts');
	});
	// if an image in the folder was added or modified, run the gm task
	watch(paths.app + '/images/*.JPG', {events: ['add', 'change']}, function(file) {
		console.log(file.basename + ' added or changed!');
		gulp.start('gm');
	});
	// if an image in the folder was deleted, also delete the image with same filename in the build folder
	watch(paths.app + '/images/*.JPG', {events: 'unlink'}, function(file) {
		console.log(file.basename + ' deleted!');
		rimraf(paths.build + '/images/' + file.basename, function(err) {
			if (err) {
				console.log('rimraf error', err);
			}
		});
		reload({stream: true});
	});

});

// Cleaning task: run if you want to delete the build
gulp.task('deleteBuild', function(callback) {
	rimraf(paths.build, callback);
});

// Connecting task: BrowserSync on paths.build
gulp.task('connect', function() {
    browserSync({
        port: 9000,
        server: {
            baseDir: paths.build
        }
    });
});

// Main tasks

// dev task: build everything
gulp.task('dev', function(callback) {
	return runSequence(['css', 'jade', 'scripts'], 'gm', callback);
});

// default task: build everything, open BrowserSync, and then watch files
gulp.task('default', function(callback) {
	return runSequence('dev', 'connect', 'watch', callback);
});<commit_msg>Add variables for common paths used<commit_after>var gulp = require('gulp');
var browserSync = require('browser-sync');
var reload = browserSync.reload;
var changed = require('gulp-changed');
var data = require('gulp-data');
var gm = require('gulp-gm');
var jade = require('gulp-jade');
var jshint = require('gulp-jshint');
var watch = require('gulp-watch');
var rimraf = require('rimraf');
var runSequence = require('run-sequence');

// paths for the development and build directories
var paths = {
	app: "./app",
	build: "./app/build"
};

// Some common file paths needed

// index.jade is convenient since we need to build to index.html
// because BrowserSync loads the build directory, so it looks for index.html
var jadeFilename = paths.app + '/index.jade';
var cssFilename = paths.app + '/style.css';
var dataFilename = paths.app + '/data.json';
var jsFilesPath = paths.app + '/*.js';
var imgSrcPath = paths.app + '/images/*.JPG';
var imgBuildDir = paths.build + '/images';

// Jade task: Pull in image data from the json file and
// compile the Jade file into html, and copy to the build folder
gulp.task('jade', function() {
	var stream = gulp.src(jadeFilename)
		.pipe(data(function(file) {
			return require(dataFilename);
		}))
		.pipe(jade())
		.pipe(gulp.dest(paths.build))
		.pipe(reload({stream: true})); // reload the browser whenever we want to show changes
	// require() caches the json file, so we need to clear it
	// from the cache after the task finishes, or else when we
	// call require() on the json file again during the
	// watch task to get the new file,
	// we get the original cached file instead
	stream.on('end', function() {
		delete require.cache[require.resolve(dataFilename)];
	});
	return stream;
});

// css task: copy stylesheets to the build folder and reload the browser to show changes
gulp.task('css', function() {
	return gulp.src(cssFilename)
		.pipe(gulp.dest(paths.build))
		.pipe(reload({stream: true}));
});

// scripts task: run JS scripts through JSHint and copy to build folder, reload browser to show changes
// JSHint ignores files listed in the .jshintignore file
gulp.task('scripts', function() {
	return gulp.src(jsFilesPath)
		.pipe(jshint())
		.pipe(jshint.reporter('default'))
		.pipe(gulp.dest(paths.build))
		.pipe(reload({stream: true}));
});

// GraphicsMagick task: resize images to a set width,
// while the height stays at the original aspect ratio.
// To save time, only process images that have been changed.
var resizedImageWidth = 1366;
gulp.task('gm', function() {
	return gulp.src(imgSrcPath)
		.pipe(changed(imgBuildDir))
		.pipe(gm(function(gmfile) {
			return gmfile.resize(resizedImageWidth);
		}))
		.pipe(gulp.dest(imgBuildDir))
		.pipe(reload({stream: true}));
});

// Watch task: whenever a file is changed, run its corresponding task
gulp.task('watch', function() {
	watch(cssFilename, function() {
		gulp.start('css');
	});
	watch([jadeFilename, dataFilename], function() {
		gulp.start('jade');
	});
	watch(jsFilesPath, function() {
		gulp.start('scripts');
	});
	// if an image in the folder was added or modified, run the gm task
	watch(imgSrcPath, {events: ['add', 'change']}, function(file) {
		console.log(file.basename + ' added or changed!');
		gulp.start('gm');
	});
	// if an image in the folder was deleted, also delete the image with same filename in the build folder
	watch(imgSrcPath, {events: 'unlink'}, function(file) {
		console.log(file.basename + ' deleted!');
		rimraf(imgBuildDir + '/' + file.basename, function(err) {
			if (err) {
				console.log('rimraf error', err);
			}
		});
		reload({stream: true});
	});

});

// Cleaning task: run if you want to delete the build
gulp.task('deleteBuild', function(callback) {
	rimraf(paths.build, callback);
});

// Connecting task: BrowserSync on paths.build
gulp.task('connect', function() {
    browserSync({
        port: 9000,
        server: {
            baseDir: paths.build
        }
    });
});

// Main tasks

// dev task: build everything
gulp.task('dev', function(callback) {
	return runSequence(['css', 'jade', 'scripts'], 'gm', callback);
});

// default task: build everything, open BrowserSync, and then watch files
gulp.task('default', function(callback) {
	return runSequence('dev', 'connect', 'watch', callback);
});<|endoftext|>


<commit_before>var gulp = require('gulp');
var $ = require('gulp-load-plugins')({
  replaceString: /^gulp(-|\.)([0-9]+)?/
});
const fs = require('fs');
const del = require('del');
const path = require('path');
const isparta = require('isparta');
const esperanto = require('esperanto');
const browserify = require('browserify');
const runSequence = require('run-sequence');
const source = require('vinyl-source-stream');

// Adjust this file to configure the build
const config = require('./config');

// Remove the built files
gulp.task('clean', function(cb) {
  del([config.destinationFolder], cb);
});

// Remove our temporary files
gulp.task('clean:tmp', function(cb) {
  del(['tmp'], cb);
});

// Send a notification when JSHint fails,
// so that you know your changes didn't build
function ding(file) {
  return file.jshint.success ? false : 'JSHint failed';
};

// Lint our source code
gulp.task('lint:src', function() {
  return gulp.src(['src/**/*.js'])
    .pipe($.plumber())
    .pipe($.jshint())
    .pipe($.jshint.reporter('jshint-stylish'))
    .pipe($.notify(ding))
    .pipe($.jshint.reporter('fail'));
});

// Lint our test code
gulp.task('lint:test', function() {
  return gulp.src(['test/unit/**/*.js'])
    .pipe($.plumber())
    .pipe($.jshint())
    .pipe($.jshint.reporter('jshint-stylish'))
    .pipe($.notify(ding))
    .pipe($.jshint.reporter('fail'));
});

// Build two versions of the library
gulp.task('build', ['lint:src', 'clean'], function(done) {
  esperanto.bundle({
    base: 'src',
    entry: config.entryFileName,
  }).then(function(bundle) {
    res = bundle.toUmd({
      sourceMap: true,
      sourceMapSource: config.entryFileName + '.js',
      sourceMapFile: config.exportFileName + '.js',
      name: config.exportVarName
    });

    // Write the generated sourcemap
    fs.mkdirSync(config.destinationFolder);
    fs.writeFileSync(path.join(config.destinationFolder, config.exportFileName + '.js'), res.map.toString());

    $.file(config.exportFileName + '.js', res.code, { src: true })
      .pipe($.plumber())
      .pipe($.sourcemaps.init({ loadMaps: true }))
      .pipe($.babel({ blacklist: ['useStrict'] }))
      .pipe($.sourcemaps.write('./', {addComment: false}))
      .pipe(gulp.dest(config.destinationFolder))
      .pipe($.filter(['*', '!**/*.js.map']))
      .pipe($.rename(config.exportFileName + '.min.js'))
      .pipe($.uglifyjs({
        outSourceMap: true,
        inSourceMap: config.destinationFolder + '/' + config.exportFileName + '.js.map',
      }))
      .pipe(gulp.dest(config.destinationFolder))
      .on('end', done);
  })
  .catch(done);
});

// Use babel to build the library to CommonJS modules. This
// is fed to Browserify, which builds the version of the lib
// for our browser spec runner.
gulp.task('compile_browser_script', function() {
  return gulp.src(['src/**/*.js'])
    .pipe($.plumber())
    .pipe($.babel({modules: 'common'}))
    .pipe(gulp.dest('tmp'))
    .pipe($.filter([config.entryFileName + '.js']))
    .pipe($.rename('__entry.js'))
    .pipe(gulp.dest('tmp'));
});

// Bundle our app for our unit tests
gulp.task('browserify', ['compile_browser_script'], function() {
  var bundleStream = browserify(['./test/setup/browserify.js']).bundle();
  return bundleStream
    .on('error', function(err){
      console.log(err.message);
      this.emit('end');
    })
    .pipe($.plumber())
    .pipe(source('./tmp/__spec-build.js'))
    .pipe(gulp.dest(''))
    .pipe($.livereload());
});

gulp.task('coverage', function(done) {
  gulp.src(['src/*.js'])
    .pipe($.plumber())
    .pipe($.istanbul({ instrumenter: isparta.Instrumenter }))
    .pipe($.istanbul.hookRequire())
    .on('finish', function() {
      return test()
      .pipe($.istanbul.writeReports())
      .on('end', done);
    });
});

function test() {
  return gulp.src(['test/setup/node.js', 'test/unit/**/*.js'], {read: false})
    .pipe($.plumber())
    .pipe($.mocha({reporter: 'dot', globals: config.mochaGlobals}));
};

// Lint and run our tests
gulp.task('test', ['lint:src', 'lint:test'], function() {
  require('babel/register')({ modules: 'common' });
  return test();
});

// Ensure that linting occurs before browserify runs. This prevents
// the build from breaking due to poorly formatted code.
gulp.task('build_in_sequence', function(callback) {
  runSequence(['lint:src', 'lint:test'], 'browserify', callback);
});

// Set up a livereload environment for our spec runner
gulp.task('test:browser', ['build_in_sequence'], function() {
  $.livereload.listen({port: 35729, host: 'localhost', start: true});
  return gulp.watch(['src/**/*.js', 'test/**/*', '.jshintrc', 'test/.jshintrc', 'config/index.json'], ['build_in_sequence']);
});

// An alias of test
gulp.task('default', ['test']);
<commit_msg>try to catch test error in CI<commit_after>var gulp = require('gulp');
var $ = require('gulp-load-plugins')({
  replaceString: /^gulp(-|\.)([0-9]+)?/
});
const fs = require('fs');
const del = require('del');
const path = require('path');
const isparta = require('isparta');
const esperanto = require('esperanto');
const browserify = require('browserify');
const runSequence = require('run-sequence');
const source = require('vinyl-source-stream');

// Adjust this file to configure the build
const config = require('./config');

var onError = function(err) {
  $.util.beep();
  if (process.env.CI) {
    throw new Error(err);
  };
}

// Remove the built files
gulp.task('clean', function(cb) {
  del([config.destinationFolder], cb);
});

// Remove our temporary files
gulp.task('clean:tmp', function(cb) {
  del(['tmp'], cb);
});

// Send a notification when JSHint fails,
// so that you know your changes didn't build
function ding(file) {
  return file.jshint.success ? false : 'JSHint failed';
};

// Lint our source code
gulp.task('lint:src', function() {
  return gulp.src(['src/**/*.js'])
    .pipe($.plumber())
    .pipe($.jshint())
    .pipe($.jshint.reporter('jshint-stylish'))
    .pipe($.notify(ding))
    .pipe($.jshint.reporter('fail'));
});

// Lint our test code
gulp.task('lint:test', function() {
  return gulp.src(['test/unit/**/*.js'])
    .pipe($.plumber())
    .pipe($.jshint())
    .pipe($.jshint.reporter('jshint-stylish'))
    .pipe($.notify(ding))
    .pipe($.jshint.reporter('fail'));
});

// Build two versions of the library
gulp.task('build', ['lint:src', 'clean'], function(done) {
  esperanto.bundle({
    base: 'src',
    entry: config.entryFileName,
  }).then(function(bundle) {
    res = bundle.toUmd({
      sourceMap: true,
      sourceMapSource: config.entryFileName + '.js',
      sourceMapFile: config.exportFileName + '.js',
      name: config.exportVarName
    });

    // Write the generated sourcemap
    fs.mkdirSync(config.destinationFolder);
    fs.writeFileSync(path.join(config.destinationFolder, config.exportFileName + '.js'), res.map.toString());

    $.file(config.exportFileName + '.js', res.code, { src: true })
      .pipe($.plumber())
      .pipe($.sourcemaps.init({ loadMaps: true }))
      .pipe($.babel({ blacklist: ['useStrict'] }))
      .pipe($.sourcemaps.write('./', {addComment: false}))
      .pipe(gulp.dest(config.destinationFolder))
      .pipe($.filter(['*', '!**/*.js.map']))
      .pipe($.rename(config.exportFileName + '.min.js'))
      .pipe($.uglifyjs({
        outSourceMap: true,
        inSourceMap: config.destinationFolder + '/' + config.exportFileName + '.js.map',
      }))
      .pipe(gulp.dest(config.destinationFolder))
      .on('end', done);
  })
  .catch(done);
});

// Use babel to build the library to CommonJS modules. This
// is fed to Browserify, which builds the version of the lib
// for our browser spec runner.
gulp.task('compile_browser_script', function() {
  return gulp.src(['src/**/*.js'])
    .pipe($.plumber())
    .pipe($.babel({modules: 'common'}))
    .pipe(gulp.dest('tmp'))
    .pipe($.filter([config.entryFileName + '.js']))
    .pipe($.rename('__entry.js'))
    .pipe(gulp.dest('tmp'));
});

// Bundle our app for our unit tests
gulp.task('browserify', ['compile_browser_script'], function() {
  var bundleStream = browserify(['./test/setup/browserify.js']).bundle();
  return bundleStream
    .on('error', function(err){
      console.log(err.message);
      this.emit('end');
    })
    .pipe($.plumber())
    .pipe(source('./tmp/__spec-build.js'))
    .pipe(gulp.dest(''))
    .pipe($.livereload());
});

gulp.task('coverage', function(done) {
  gulp.src(['src/*.js'])
    .pipe($.plumber({errorHandler: onError}))
    .pipe($.istanbul({ instrumenter: isparta.Instrumenter }))
    .pipe($.istanbul.hookRequire())
    .on('finish', function() {
      return test()
      .pipe($.istanbul.writeReports())
      .on('end', done);
    });
});

function test() {
  return gulp.src(['test/setup/node.js', 'test/unit/**/*.js'], {read: false})
    .pipe($.plumber({errorHandler: onError}))
    .pipe($.mocha({reporter: 'dot', globals: config.mochaGlobals}));
};

// Lint and run our tests
gulp.task('test', ['lint:src', 'lint:test'], function() {
  require('babel/register')({ modules: 'common' });
  return test();
});

// Ensure that linting occurs before browserify runs. This prevents
// the build from breaking due to poorly formatted code.
gulp.task('build_in_sequence', function(callback) {
  runSequence(['lint:src', 'lint:test'], 'browserify', callback);
});

// Set up a livereload environment for our spec runner
gulp.task('test:browser', ['build_in_sequence'], function() {
  $.livereload.listen({port: 35729, host: 'localhost', start: true});
  return gulp.watch(['src/**/*.js', 'test/**/*', '.jshintrc', 'test/.jshintrc', 'config/index.json'], ['build_in_sequence']);
});

// An alias of test
gulp.task('default', ['test']);
<|endoftext|>


<commit_before>var gulp = require('gulp'),
    autoprefixer = require('gulp-autoprefixer'),
    minifycss = require('gulp-minifycss'),
    jshint = require('gulp-jshint'),
    uglify = require('gulp-uglify'),
    rename = require('gulp-rename'),
    clean = require('gulp-clean'),
    concat = require('gulp-concat'),
    util = require('gulp-util');

// Options
var options = {
	autoprefixer: {
		map: true,
		from: 'placeholder',
		to: 'style.min.css'
	},
	rename: {
		suffix: '.min'
	}
};

var paths = {
 	scripts: [
	 	'src/*.js',
		'!src/vendor/*.js'
	],
	styles: [
		'src/*.css'
	]
};

gulp.task('scripts', function() {
	return gulp.src(paths.scripts)
        .pipe(jshint('.jshintrc'))
        .pipe(jshint.reporter('jshint-stylish'))
        .pipe(uglify())
		.pipe(rename(options.rename))
        .pipe(gulp.dest('./build'));
});

gulp.task('styles', function() {
    return gulp.src(paths.styles)
		.pipe(autoprefixer(["last 1 version", "> 1%", "ie 8", "ie 7"], options.autoprefixer))
		.pipe(minifycss())
		.pipe(rename(options.rename))
        .pipe(gulp.dest('./css'));
});

gulp.task('watch', ['connect', 'styles', 'scripts'], function() {
    // Watch .scss files
    gulp.watch(paths.sass, ['styles']);

    // Watch .js files
    gulp.watch(paths.scripts, ['scripts']);

    // Watch .html files
    gulp.watch(paths.html, ['html']);
});

gulp.task('html', function() {
    return gulp.src(paths.html)
        .pipe(connect.reload())
});

gulp.task('connect', function() {
    connect.server(options.server);
});

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

<commit_msg>Finishes setting up initial gulpfile<commit_after>var gulp = require('gulp'),
    autoprefixer = require('gulp-autoprefixer'),
    minifycss = require('gulp-minify-css'),
    jshint = require('gulp-jshint'),
    uglify = require('gulp-uglify'),
    rename = require('gulp-rename'),
    clean = require('gulp-clean'),
    concat = require('gulp-concat'),
    util = require('gulp-util');

// Options
var options = {
	autoprefixer: {
		map: true,
		from: 'placeholder',
		to: 'style.min.css'
	},
	rename: {
		suffix: '.min'
	},
	clean: {
		read: false
	}
};

var paths = {
 	scripts: [
	 	'src/*.js',
		'!src/vendor/*.js'
	],
	styles: [
		'src/*.css'
	]
};

gulp.task('scripts', function() {
	return gulp.src(paths.scripts)
        .pipe(jshint('.jshintrc'))
        .pipe(jshint.reporter('jshint-stylish'))
		.pipe(gulp.dest('./build'))
        .pipe(uglify())
		.pipe(rename(options.rename))
        .pipe(gulp.dest('./build'));
});

gulp.task('styles', function() {
    return gulp.src(paths.styles)
		.pipe(autoprefixer(["last 1 version", "> 1%", "ie 8", "ie 7"], options.autoprefixer))
		.pipe(gulp.dest('./build'))
		.pipe(minifycss())
		.pipe(rename(options.rename))
        .pipe(gulp.dest('./build'));
});

gulp.task('clean', function() {
	return gulp.src('./build', options.clean)
		.pipe(clean());
});

gulp.task('default', ['clean'], function() {
    gulp.start('styles');
    gulp.start('scripts');
});

<|endoftext|>