client/gulpfile.js
changeset 80 dd414da0f0bb
parent 79 bd2f2c3f205c
child 81 a6bbf198bd24
equal deleted inserted replaced
79:bd2f2c3f205c 80:dd414da0f0bb
     1 var gulp = require('gulp');
       
     2 var del = require('del');
       
     3 var gutil = require('gulp-util')
       
     4 var plugins = require("gulp-load-plugins")({lazy:false});
       
     5 
       
     6 var templateFolder = '../annot-server/webapp/templates/';
       
     7 var templateFileDest = '../annot-server/webapp/templates/annotationclient.html';
       
     8 var staticFolder = '../annot-server/static';
       
     9 
       
    10 var clientBaseName = 'app';
       
    11 var vendorBaseName = 'lib';
       
    12 
       
    13 gulp.task('clean', function (cb) {
       
    14     del([
       
    15         templateFileDest,
       
    16         staticFolder + "/css/app*",
       
    17         staticFolder + "/js/app*",
       
    18         staticFolder + "/data/categories.json",
       
    19     ],{'force':true}, cb);
       
    20 });
       
    21 
       
    22 var scriptsSrc = ['!./app/**/*_test.js','./app/**/*.js'];
       
    23 
       
    24 gulp.task('scripts', function(){
       
    25     //combine all js files of the app
       
    26     gulp.src(scriptsSrc)
       
    27         .pipe(plugins.jshint())
       
    28         .pipe(plugins.jshint.reporter('default'))
       
    29         .pipe(plugins.jshint.reporter('fail'))
       
    30         .pipe(plugins.concat(clientBaseName+'.js'))
       
    31         .pipe(gulp.dest(staticFolder+'/js'))
       
    32         .pipe(plugins.filesize())
       
    33         .pipe(plugins.uglify())
       
    34         .pipe(plugins.rename(clientBaseName+'.min.js'))
       
    35         .pipe(gulp.dest(staticFolder+'/js'))
       
    36         .pipe(plugins.filesize())
       
    37         .on('error', gutil.log);
       
    38 });
       
    39 
       
    40 
       
    41 gulp.task('css', function(){
       
    42     gulp.src('./app/**/*.css')
       
    43         .pipe(plugins.csslint({ 'box-sizing': false }))
       
    44         .pipe(plugins.csslint.reporter())
       
    45         .pipe(plugins.concat(clientBaseName+'.css'))
       
    46         .pipe(gulp.dest(staticFolder+'/css'))
       
    47         .pipe(plugins.filesize())
       
    48         .pipe(plugins.minifyCss({keepBreaks:true}))
       
    49         .pipe(plugins.rename(clientBaseName+'.min.css'))
       
    50         .pipe(gulp.dest(staticFolder+'/css'))
       
    51         .pipe(plugins.filesize());
       
    52 });
       
    53 
       
    54 var vendorJSsrc = [
       
    55   '!./bower_components/**/*.min.js',
       
    56   '!./bower_components/bootstrap/Gruntfile.js',
       
    57   '!./bower_components/bootstrap/grunt/*',
       
    58   '!./bower_components/bootstrap/js/*',
       
    59   '!./bower_components/jquery/src/**/*',
       
    60   '!./bower_components/angular-bootstrap/ui-bootstrap.js',
       
    61   './bower_components/jquery/dist/jquery.js',
       
    62   './bower_components/angular/angular.js',
       
    63   './bower_components/**/*.js'
       
    64 ];
       
    65 
       
    66 gulp.task('vendorJS', function(){
       
    67     //concatenate vendor JS files
       
    68     gulp.src(vendorJSsrc)
       
    69         .pipe(plugins.concat('lib.js'))
       
    70         .pipe(gulp.dest(staticFolder+'/js'))
       
    71         .pipe(plugins.filesize())
       
    72         .pipe(plugins.uglify())
       
    73         .pipe(plugins.rename('lib.min.js'))
       
    74         .pipe(gulp.dest(staticFolder+'/js'))
       
    75         .pipe(plugins.filesize())
       
    76         .on('error', gutil.log);
       
    77 });
       
    78 
       
    79 gulp.task('vendorCSS', function(){
       
    80     //concatenate vendor CSS files
       
    81     gulp.src(['!./bower_components/**/*.min.css',
       
    82         './bower_components/**/*.css'])
       
    83         .pipe(plugins.concat(vendorBaseName+'.css'))
       
    84         .pipe(gulp.dest(staticFolder+'/css'))
       
    85         .pipe(plugins.filesize())
       
    86         .pipe(plugins.minifyCss({keepBreaks:true}))
       
    87         .pipe(plugins.rename(vendorBaseName+'.min.css'))
       
    88         .pipe(gulp.dest(staticFolder+'/css'))
       
    89         .pipe(plugins.filesize());
       
    90 });
       
    91 
       
    92 gulp.task('vendorFonts', function(){
       
    93     gulp.src(['./bower_components/**/fonts/*'])
       
    94         .pipe(plugins.flatten())
       
    95         .pipe(gulp.dest(staticFolder+'/css/fonts'));
       
    96 });
       
    97 
       
    98 gulp.task('copy-index', function() {
       
    99     gulp.src('./app/annotationclient.html')
       
   100         .pipe(gulp.dest(templateFolder));
       
   101 });
       
   102 
       
   103 gulp.task('copy-data', function() {
       
   104     gulp.src('./data/**/*')
       
   105         .pipe(gulp.dest(staticFolder+'/data'));
       
   106 });
       
   107 
       
   108 gulp.task('copy-img', function() {
       
   109     gulp.src('./img/**/*')
       
   110         .pipe(gulp.dest(staticFolder+'/img'));
       
   111 });
       
   112 
       
   113 gulp.task('watch',function(){
       
   114     gulp.watch([
       
   115         templateFolder+'/**/*.html',
       
   116         staticFolder+'/**/*.js',
       
   117         staticFolder+'/**/*.css'
       
   118     ], function(event) {
       
   119         return gulp.src(event.path)
       
   120             .pipe(plugins.webserver.reload());
       
   121     });
       
   122     gulp.watch(['./app/**/*.js','!./app/**/*test.js'],['scripts']);
       
   123     gulp.watch('./app/**/*.css',['css']);
       
   124     gulp.watch('./app/annotationclient.html',['copy-index']);
       
   125     gulp.watch('./data/**/*',['copy-data']);
       
   126     gulp.watch('./img/**/*',['copy-img']);
       
   127 
       
   128 });
       
   129 
       
   130 gulp.task('connect', function() {
       
   131     gulp.src('build').pipe(
       
   132         plugins.webserver({
       
   133             port: 9000,
       
   134             livereload: true
       
   135         })
       
   136     );
       
   137 });
       
   138 
       
   139 gulp.task('default',['scripts','css','copy-index','copy-data','copy-img','vendorJS','vendorCSS','vendorFonts']);