var gulp = require('gulp');

var autoprefixer = require('gulp-autoprefixer');
var banner = require('gulp-banner');
var clean = require('gulp-clean-css');
var concat = require('gulp-concat');
var jshint = require('gulp-jshint');
var rename = require('gulp-rename');
var stylus = require('gulp-stylus');
var uglify = require('gulp-uglify');
var pkg = require('./package.json');

var fullBanner = '/*\n' +
	' * <%= pkg.name %> <%= pkg.version %>\n' +
	' * <%= pkg.description %>\n' +
	' * <%= pkg.homepage %>\n' +
	' *\n' +
	' * By <%= pkg.author %>\n' +
	' * Released under the <%= pkg.license %> license.\n' +
	'*/\n';

var miniBanner = '/*' +
	' <%= pkg.name %> <%= pkg.version %>' +
	' | <%= pkg.author %> |' +
	' http://0x0049.link/tabbed |' +
	' <%= pkg.license %> license' +
	' */\n';

gulp.task('jshint', function () {
	return gulp.src('src/tabbed.js')
		.pipe(jshint())
		.pipe(jshint.reporter('default'));
});

gulp.task('build:scripts', ['jshint'], function () {
	return gulp.src('src/tabbed.js')
		.pipe(banner(fullBanner, {
			pkg: pkg
		}))
		.pipe(gulp.dest('dist'))
		.pipe(rename('tabbed.min.js'))
		.pipe(uglify())
		.pipe(banner(miniBanner, {
			pkg: pkg
		}))
		.pipe(gulp.dest('dist'));
});

gulp.task('build:styles', function () {
	return gulp.src('src/tabbed.styl')
		.pipe(stylus({
			'include css': true
		}))
		.pipe(autoprefixer({
			browsers: ['last 2 version', 'ie 8', 'ie 9'],
			cascade: false,
			remove: false
		}))
		.pipe(gulp.dest('dist'))
		.pipe(rename('tabbed.min.css'))
		.pipe(clean({
			compatibility: 'ie8'
		}))
		.pipe(gulp.dest('dist'));
});

gulp.task('default', ['build:scripts', 'build:styles']);
