var gulp = require('gulp');
var concat = require('gulp-concat');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var ngAnnotate = require('gulp-ng-annotate');
var jshint = require('gulp-jshint');
var htmlhint = require('gulp-htmlhint');

var client = ['index.js', 'controllers/**/*.js', 'entity/**/*.js', 'filters/**/*.js', 'directives/**/*.js', 'services/**/*.js', '!zettapi.js', '!zettapi.min.js', '!gulpfile.js', '!**/.svn/*.*', '!**/.svn/**/*.*'];

var all = ['!app.js', '!zettapi.js', '!zettapi.min.js', '!gulpfile.js', '!node_modules/**/*.*', '!bower_components/**/*.*', '!**/.svn/*.*', '!**/.svn/**/*.*'];

gulp.task('default', ['jshint', 'htmlhint', 'concat', 'concat.min']);

gulp.task('jshint', function () {
    return gulp.src(all.concat(['*.js', '**/*.js']))
        .pipe(jshint())
        .pipe(jshint.reporter('jshint-stylish'));
});

gulp.task('htmlhint', function () {
    return gulp.src(all.concat(['*.html', '**/*.html']))
        .pipe(htmlhint("./htmlhintrc"))
        .pipe(htmlhint.reporter("htmlhint-stylish"));
});

gulp.task('concat', function () {
    return gulp.src(client)
        .pipe(sourcemaps.init())
        .pipe(concat('zettapi.js'))
        .pipe(sourcemaps.write())
        .pipe(gulp.dest('.'));
});
gulp.task('concat.min', function () {
    return gulp.src(client)
        .pipe(concat('zettapi.min.js'))
        .pipe(ngAnnotate())
        .pipe(uglify())
        .pipe(gulp.dest('.'));
});