var gulp = require('gulp');

// define plug-ins
var flatten = require('gulp-flatten');
var gulpFilter = require('gulp-filter');
var uglify = require('gulp-uglify');
var minifycss = require('gulp-minify-css');
var rename = require('gulp-rename');
var mainBowerFiles = require('main-bower-files');

// Define paths variables
var src_path = 'src';
var dest_path =  'js/libs';

// grab libraries files from bower_components, minify and push in /public
gulp.task('default', function() {

    gulp.src('bower_components/bootstrap/**/bootstrap-theme.min.css')
	.pipe(flatten())
	.pipe(gulp.dest('css'))
    
	var jsFilter = gulpFilter('*.js');
    var cssFilter = gulpFilter('*.css');
    var fontFilter = gulpFilter(['*.eot', '*.woff', '*.svg', '*.ttf']);

	return gulp.src(mainBowerFiles())

	// grab vendor js files from bower_components, minify and push in dest_path
	.pipe(jsFilter)
	//.pipe(gulp.dest(dest_path))
	.pipe(uglify())
	.pipe(rename({
        suffix: ".min"
    }))
	.pipe(gulp.dest(dest_path))
	.pipe(jsFilter.restore())

	// grab vendor css files from bower_components, minify and push in dest_path
	.pipe(cssFilter)
	//.pipe(gulp.dest('css'))
	.pipe(minifycss())
	.pipe(rename({
        suffix: ".min"
    }))
	.pipe(gulp.dest('css'))
	.pipe(cssFilter.restore())
    
	// grab vendor font files from bower_components and push in dest_path
	.pipe(fontFilter)
	.pipe(flatten())
	.pipe(gulp.dest('fonts'))
});
