blob: 40136c809015acc9da2b55e2bdeb647c14261478 [file] [log] [blame]
Matteo Scandolof813b6a2015-11-03 14:32:00 +01001'use strict';
2
3// BUILD
4//
5// The only purpose of this gulpfile is to build a XOS view and copy the correct files into
6// .html => dashboards
7// .js (minified and concat) => static/js
8//
9// The template are parsed and added to js with angular $templateCache
10
11var gulp = require('gulp');
12var ngmin = require('gulp-ngmin');
13var uglify = require('gulp-uglify');
14var templateCache = require('gulp-angular-templatecache');
15var runSequence = require('run-sequence');
16var minifyHtml = require("gulp-minify-html");
17var concat = require("gulp-concat");
18var del = require('del');
19var wiredep = require('wiredep');
20var babel = require('gulp-babel');
21var angularFilesort = require('gulp-angular-filesort');
22
23var TEMPLATE_HEADER = '/*This code is autogenerated from the templates files */ angular.module("<%= module %>"<%= standalone %>).run(["$templateCache", function($templateCache) {';
24
25module.exports = function(options){
26
27 // empty the dist folder
28 gulp.task('clean', function(){
29 return del([options.dist + '**/*']);
30 });
31
32 // compile and minify scripts
33 gulp.task('scripts', function() {
34 return gulp.src([
35 options.scripts + '**/*.js'
36 ])
37 .pipe(babel())
38 .pipe(ngmin())
39 .pipe(angularFilesort())
40 .pipe(concat('xosContentProvider.js'))
41 .pipe(uglify())
42 .pipe(gulp.dest(options.dist));
43 });
44
45 // set templates in cache
46 gulp.task('templates', function(){
47 return gulp.src("./src/templates/*.html")
48 .pipe(templateCache({
49 module: 'xos.contentProviderApp',
50 root: '../../static/templates/contentProvider/',
51 templateHeader: TEMPLATE_HEADER
52 }))
53 .pipe(gulp.dest(options.scripts));
54 });
55
56 // copy js output to Django Folder
57 gulp.task('copyJs', function(){
58 return gulp.src('dist/xosContentProvider.js')
59 .pipe(gulp.dest('../static/js/'))
60 });
61
62 // copy vendor js output to Django Folder
63 gulp.task('copyVendor', function(){
64 return gulp.src('dist/xosNgVendor.js')
65 .pipe(gulp.dest('../static/js/vendor/'));
66 });
67
68 // minify vendor js files
69 gulp.task('wiredep', function(){
70 var bowerDeps = wiredep().js;
71 return gulp.src(bowerDeps)
72 .pipe(concat('xosNgVendor.js'))
73 .pipe(uglify())
74 .pipe(gulp.dest(options.dist));
75 });
76
77 // TODO vendor
78 // - define a list of common components (eg: angular, angular-route, ...)
79 // - find the difference between local components e common components
80 // - minify only the local
81 // - unify wiredep, filter and copyVendor task
82
83 gulp.task('build', function() {
84 runSequence(
85 'clean',
86 'templates',
87 'scripts',
88 'copyJs',
89 'wiredep',
90 'copyVendor'
91 );
92 });
93}