/**
 *  gulp [Task]
 *
 *  Available Build Task(s)
 *    - clean
 *    - concat
 *    - minify
 *    - minify-css
 *    - build
 */

var gulp = require('gulp');
var help = require('gulp-help');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var minifyCss = require('gulp-minify-css');
var rename = require('gulp-rename');
var clean = require('gulp-clean');

/** gulp tasks */

help(gulp)

gulp.task('clean', 'Cleans the build folder.', [], function () {
    gulp.src('build/**/*', { read: false })
        .pipe(clean({ force: true }));
}, {
    aliases: ['c', 'C']
});

gulp.task("concat", 'Joins all the script files putting them in build folder.', [], function () {
    gulp.src('js/**/*.js')
        .pipe(concat('jqm.editable.listview.js'))
        .pipe(gulp.dest('build/'));
}, {
    aliases: ['j', 'J']
});

gulp.task("minify", 'Minifies all the script files.', [], function () {
   gulp.src('js/**/*.js')
        .pipe(concat('jqm.editable.listview.js'))
        .pipe(rename('jqm.editable.listview.min.js'))
        .pipe(uglify({
            preserveComments: 'some'
        }))
        .pipe(gulp.dest('build/'))
}, {
    aliases: ['m', 'M']
});

gulp.task("minify-css", 'Minifies the CSS stylesheets.', [], function() {
    gulp.src('css/**/*.css')
        .pipe(concat('jqm.editable.listview.min.css'))
        .pipe(minifyCss({
            noAdvanced: false
        }))
        .pipe(gulp.dest('build'))
}, {
    aliases: ['s', 'S']
})

gulp.task("assets", 'Copies all assets (css stylesheets, images etc.) to the build folder.', [], function(){
    gulp.src("css/**/*")
        .pipe(concat("jqm.editable.listview.css"))
        .pipe(gulp.dest('build'))
}, {
    aliases: ['a', 'A']
})

gulp.task("build", '(default task) Cleans, concatenates and minifies all script files into build folder.', [], function () {
    gulp.run('clean')
    gulp.run('concat')
    gulp.run('minify')
    gulp.run('assets')
    gulp.run('minify-css')
}, {
    aliases: ['b', 'B']
});

gulp.task('default', function () {
    gulp.run('build')
});

