var gulp = require('gulp')
autoprefixer = require('gulp-autoprefixer')
concat = require('gulp-concat')
merge2 = require('merge2')
replace = require('gulp-replace')
sass = require('gulp-sass');

var config = {
    autoPrefixer: {
        browsers: [
            "Android 2.3",
            "Android >= 4",
            "Chrome >= 20",
            "Firefox >= 24",
            "Explorer >= 8",
            "iOS >= 6",
            "Opera >= 12",
            "Safari >= 6"
        ]
    }
};

var paths = {
    bootstrap: './node_modules/bootstrap-sass',
    fontAwesome: './node_modules/font-awesome',
    linearicon: './vendor/linearicons',
    public: './public',
    sass: './src'
};

gulp.task('css', function () {
    // var scssStream = gulp.src(paths.sass + '/*.scss')
    //     .pipe(sass({
    //         includePaths: [paths.bootstrap + '/assets/stylesheets'],
    //     }));
    // var cssStream = gulp.src(paths.linearicon + '/style.css');
    // return merge2(scssStream, cssStream)
    //     .pipe(autoprefixer(config.autoPrefixer))
    //     .pipe(concat('bootstrap.css'))
    //     .pipe(replace('../fonts/bootstrap/', '../fonts/'))
    //     .pipe(replace('fonts/Linearicons-Free', '../fonts/Linearicons-Free'))
    //     .pipe(gulp.dest(paths.public + '/css'));

    return gulp.src(paths.sass + '/*.scss')
        .pipe(sass({
            includePaths: [paths.bootstrap + '/assets/stylesheets'],
        }))
        .pipe(autoprefixer(config.autoPrefixer))
        .pipe(concat('bootstrap.css'))
        .pipe(replace('../fonts/bootstrap/', '../fonts/'))
        .pipe(replace('fonts/linearicons', '../fonts/linearicons'))
        .pipe(gulp.dest(paths.public + '/css'));

});

gulp.task('fonts', function () {
    return gulp.src([
        paths.bootstrap + '/assets/fonts/bootstrap/*',
        paths.fontAwesome + '/fonts/*',
        paths.linearicon + '/fonts/*.*'
    ]).pipe(gulp.dest(paths.public + '/fonts'));
});

gulp.task('watch', function () {
    return gulp
        .watch(paths.sass + '/app.scss', ['css'])
        .on('change', function (event) {
            console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
        });
});

gulp.task('default', ['css', 'fonts', 'watch']);
