1 var gulp = require('gulp'); |
1 var gulp = require('gulp'); |
2 var gutil = require('gulp-util') |
2 var gutil = require('gulp-util') |
3 var plugins = require("gulp-load-plugins")({lazy:false}); |
3 var plugins = require("gulp-load-plugins")({lazy:false}); |
|
4 var mainBowerFiles = require('main-bower-files'); |
4 var htmlreplace = require('gulp-html-replace'); |
5 var htmlreplace = require('gulp-html-replace'); |
5 //var flatten = require('gulp-flatten'); |
|
6 //var uglify = require('gulp-uglify'); |
|
7 //var clean = require('gulp-clean'); |
|
8 //var rename = require('gulp-rename'); |
|
9 //var filesize = require('gulp-filesize'); |
|
10 //var cssmin = require('gulp-cssmin'); |
|
11 |
6 |
12 gulp.task('clean', function () { |
7 var templateFolder = './../server/ammico'; |
13 return gulp.src('build', {read: false}) |
8 var staticFolder = './../server/ammico/static/ammico'; |
14 .pipe(clean()); |
9 var buildFolder = './build'; |
15 }); |
|
16 |
10 |
17 var scriptsSrc = ['!./app/**/*_test.js','./app/**/*.js']; |
11 var scriptsSrc = ['!./app/**/*_test.js','./app/**/*.js']; |
|
12 |
|
13 gulp.task('templates',function(){ |
|
14 //combine all template files of the app into a js file |
|
15 gulp.src(['!./app/index.html', |
|
16 './app/**/*.html']) |
|
17 .pipe(plugins.angularTemplatecache('templates.js',{standalone:true})) |
|
18 .pipe(gulp.dest(buildFolder+'/js')); |
|
19 }); |
18 |
20 |
19 gulp.task('scripts', function(){ |
21 gulp.task('scripts', function(){ |
20 //combine all js files of the app |
22 //combine all js files of the app |
21 gulp.src(scriptsSrc) |
23 gulp.src(scriptsSrc) |
22 .pipe(plugins.jshint()) |
24 .pipe(plugins.jshint()) |
23 .pipe(plugins.jshint.reporter('default')) |
25 .pipe(plugins.jshint.reporter('default')) |
24 .pipe(plugins.jshint.reporter('fail')) |
26 .pipe(plugins.jshint.reporter('fail')) |
25 .pipe(plugins.concat('app.js')) |
27 .pipe(plugins.concat('app.js')) |
26 .pipe(gulp.dest('./build')) |
28 .pipe(gulp.dest(buildFolder+'/js')) |
27 .pipe(plugins.filesize()) |
|
28 .pipe(plugins.uglify()) |
|
29 .pipe(plugins.rename('app.min.js')) |
|
30 .pipe(gulp.dest('./build')) |
|
31 .pipe(plugins.filesize()) |
29 .pipe(plugins.filesize()) |
32 .on('error', gutil.log); |
30 .on('error', gutil.log); |
33 }); |
31 }); |
34 |
32 |
35 gulp.task('templates',function(){ |
|
36 //combine all template files of the app into a js file |
|
37 gulp.src(['!./app/index.html', |
|
38 './app/**/*.html']) |
|
39 .pipe(plugins.angularTemplatecache('templates.js',{standalone:true})) |
|
40 .pipe(gulp.dest('./build')); |
|
41 }); |
|
42 |
|
43 gulp.task('css', function(){ |
33 gulp.task('css', function(){ |
44 gulp.src('./app/**/*.css') |
34 gulp.src('./app/**/*.css') |
45 // .pipe(plugins.csslint()) |
35 .pipe(plugins.csslint({ 'box-sizing': false })) |
46 // .pipe(plugins.csslint.reporter()) |
36 .pipe(plugins.csslint.reporter()) |
47 .pipe(plugins.concat('app.css')) |
37 .pipe(plugins.concat('app.css')) |
48 .pipe(gulp.dest('./build')) |
38 .pipe(gulp.dest(buildFolder+'/css')) |
49 .pipe(plugins.filesize()) |
|
50 .pipe(plugins.minifyCss({keepBreaks:true})) |
|
51 .pipe(plugins.rename('app.min.css')) |
|
52 .pipe(gulp.dest('./build')) |
|
53 .pipe(plugins.filesize()); |
39 .pipe(plugins.filesize()); |
54 }); |
40 }); |
55 |
41 |
56 var vendorJSsrc = [ |
|
57 '!./bower_components/**/*.min.js', |
|
58 '!./bower_components/bootstrap/**/*', |
|
59 '!./bower_components/jquery/src/**/*', |
|
60 '!./bower_components/jquery-ui/themes/**', |
|
61 '!./bower_components/jquery-ui/ui/**', |
|
62 '!./bower_components/jquery-ui/ui/*.js', |
|
63 '!./bower_components/**/index.js', |
|
64 './bower_components/bootstrap/dist/css/*', |
|
65 './bower_components/jquery/dist/jquery.js', |
|
66 './bower_components/angular/angular.js', |
|
67 './bower_components/angular-route/angular-route.js', |
|
68 './bower_components/angular-resource/angular-resource.js', |
|
69 './bower_components/angular-bootstrap/ui-bootstrap.js', |
|
70 './bower_components/**/*.js' |
|
71 ]; |
|
72 |
|
73 gulp.task('vendorJS', function(){ |
42 gulp.task('vendorJS', function(){ |
74 //concatenate vendor JS files |
43 //concatenate vendor JS files |
75 gulp.src(vendorJSsrc) |
44 return gulp.src(mainBowerFiles('**/*.js', { |
|
45 "overrides":{ |
|
46 "angular": { |
|
47 "dependencies": { |
|
48 "jquery": "~1.8" |
|
49 } |
|
50 } |
|
51 } |
|
52 })) |
76 .pipe(plugins.concat('lib.js')) |
53 .pipe(plugins.concat('lib.js')) |
77 .pipe(gulp.dest('./build')) |
54 .pipe(gulp.dest(buildFolder+'/js')) |
78 .pipe(plugins.filesize()) |
|
79 .pipe(plugins.uglify()) |
|
80 .pipe(plugins.rename('lib.min.js')) |
|
81 .pipe(gulp.dest('./build')) |
|
82 .pipe(plugins.filesize()) |
55 .pipe(plugins.filesize()) |
83 .on('error', gutil.log); |
56 .on('error', gutil.log); |
84 }); |
57 }); |
85 |
58 |
86 gulp.task('vendorCSS', function(){ |
59 gulp.task('vendorCSS', function(){ |
87 //concatenate vendor CSS files |
60 //concatenate vendor CSS files |
88 gulp.src(['!./bower_components/**/*.min.css', |
61 gulp.src(['!./bower_components/**/*.min.css', |
89 './bower_components/**/*.css']) |
62 './bower_components/**/*.css']) |
90 .pipe(plugins.concat('lib.css')) |
63 .pipe(plugins.concat('lib.css')) |
91 .pipe(gulp.dest('./build')) |
64 .pipe(gulp.dest(buildFolder+'/css')) |
92 .pipe(plugins.filesize()) |
|
93 .pipe(plugins.minifyCss({keepBreaks:true})) |
|
94 .pipe(plugins.rename('lib.min.css')) |
|
95 .pipe(gulp.dest('./build')) |
|
96 .pipe(plugins.filesize()); |
65 .pipe(plugins.filesize()); |
97 }); |
66 }); |
98 |
67 |
99 gulp.task('vendorFonts', function(){ |
68 gulp.task('vendorFonts', function(){ |
100 gulp.src(['./bower_components/**/fonts/*']) |
69 gulp.src(['./bower_components/**/fonts/*']) |
101 .pipe(plugins.flatten()) |
70 .pipe(plugins.flatten()) |
102 .pipe(gulp.dest('./build/fonts')); |
71 .pipe(gulp.dest(buildFolder+'/fonts')); |
|
72 }); |
|
73 |
|
74 gulp.task('minimify', function(){ |
|
75 gulp.src(buildFolder+'/js/lib.js') |
|
76 .pipe(plugins.uglify()) |
|
77 .pipe(plugins.rename('lib.min.js')) |
|
78 .pipe(gulp.dest(buildFolder+'/js')) |
|
79 .pipe(plugins.filesize()); |
|
80 gulp.src(buildFolder+'/js/app.js') |
|
81 .pipe(plugins.uglify()) |
|
82 .pipe(plugins.rename('app.min.js')) |
|
83 .pipe(gulp.dest(buildFolder+'/js')) |
|
84 .pipe(plugins.filesize()); |
|
85 gulp.src(buildFolder+'/css/app.css') |
|
86 .pipe(plugins.minifyCss({keepBreaks:true, processImport: false})) |
|
87 .pipe(plugins.rename('app.min.css')) |
|
88 .pipe(gulp.dest(buildFolder+'/css')) |
|
89 .pipe(plugins.filesize()); |
|
90 gulp.src(buildFolder+'/css/lib.css') |
|
91 .pipe(plugins.minifyCss({keepBreaks:true, processImport: false})) |
|
92 .pipe(plugins.rename('lib.min.css')) |
|
93 .pipe(gulp.dest(buildFolder+'/css')) |
|
94 .pipe(plugins.filesize()); |
103 }); |
95 }); |
104 |
96 |
105 gulp.task('copy-index', function() { |
97 gulp.task('copy-index', function() { |
106 gulp.src('./app/index.html') |
98 gulp.src('./app/index.html') |
107 .pipe(gulp.dest('./build')); |
99 .pipe(gulp.dest('./build')); |
108 }); |
100 }); |
109 |
101 |
110 gulp.task('copy-data', function() { |
102 gulp.task('copy-data', function() { |
111 gulp.src('./data/**/*') |
103 gulp.src('./data/**/*') |
112 .pipe(gulp.dest('./build/data')); |
104 .pipe(gulp.dest(buildFolder+'/data')); |
113 }); |
105 }); |
114 |
106 |
115 gulp.task('copy-img', function() { |
107 gulp.task('copy-img', function() { |
116 gulp.src('./img/**/*') |
108 gulp.src('./img/**/*') |
117 .pipe(gulp.dest('./build/img')); |
109 .pipe(gulp.dest(buildFolder+'/img')); |
118 }); |
110 }); |
119 |
111 |
120 gulp.task('copy-server', function() { |
112 gulp.task('copy-server', function() { |
121 gulp.src('./build/img/**/*') |
113 gulp.src(buildFolder+'/img/**/*') |
122 .pipe(gulp.dest('./../server/ammico/static/ammico/img')); |
114 .pipe(gulp.dest(staticFolder+'/img')); |
123 gulp.src('./build/fonts/**/*') |
115 gulp.src(buildFolder+'/fonts/**/*') |
124 .pipe(gulp.dest('./../server/ammico/static/ammico/fonts')); |
116 .pipe(gulp.dest(staticFolder+'/fonts')); |
125 gulp.src('./build/*.js') |
117 gulp.src(buildFolder+'/js/*.js') |
126 .pipe(gulp.dest('./../server/ammico/static/ammico/js')); |
118 .pipe(gulp.dest(staticFolder+'/js')); |
127 gulp.src('./build/*.css') |
119 gulp.src(buildFolder+'/css/*.css') |
128 .pipe(gulp.dest('./../server/ammico/static/ammico/css')); |
120 .pipe(gulp.dest(staticFolder+'/css')); |
129 gulp.src('./app/index.html') |
121 gulp.src(buildFolder+'/index.html') |
130 .pipe(htmlreplace({ |
122 .pipe(htmlreplace({ |
131 django: '{% load static %}', |
123 django: '{% load static %}', |
132 js:{ |
124 js:{ |
133 src: ['lib.js', 'templates.js', 'app.js'], |
125 src: ['lib.js', 'templates.js', 'app.js'], |
134 tpl: '<script src="{% static \'ammico/js/%s\' %}"></script>' |
126 tpl: '<script src="{% static \'ammico/js/%s\' %}"></script>' |
135 }, |
127 }, |
136 css: { |
128 css: { |
137 src: ['lib.css', 'app.css'], |
129 src: ['lib.css', 'app.css'], |
138 tpl: '<link rel="stylesheet" type="text/css" href="{% static \'ammico/css/%s\' %}"/>' |
130 tpl: '<link rel="stylesheet" type="text/css" href="{% static \'ammico/css/%s\' %}"/>' |
139 }, |
131 }, |
140 imgLogo: { |
132 imgLogo: { |
141 src: 'ammico_logo_small.png', |
133 src: 'ammico_logo_small.png', |
142 tpl: '<img src="{% static \'ammico/img/%s\' %}">' |
134 tpl: '<img src="{% static \'ammico/img/%s\' %}">' |
143 }, |
135 }, |
144 imgFooter: { |
136 imgFooter: { |
145 src: 'logo_IRI_footer.png', |
137 src: 'logo_IRI_footer.png', |
146 tpl: '<img src="{% static \'ammico/img/%s\' %}" alt="Logo IRI" />' |
138 tpl: '<img src="{% static \'ammico/img/%s\' %}" alt="Logo IRI" />' |
147 } |
139 } |
148 })) |
140 })) |
149 .pipe(gulp.dest('./../server/ammico/templates')); |
141 .pipe(gulp.dest(templateFolder+'/templates')); |
150 }); |
142 }); |
151 |
143 |
152 gulp.task('watch',function(){ |
144 gulp.task('watch',function(){ |
153 gulp.watch([ |
145 gulp.watch([ |
154 'build/**/*.html', |
146 buildFolder+'/**/*.html', |
155 'build/**/*.js', |
147 buildFolder+'/**/*.js', |
156 'build/**/*.css' |
148 buildFolder+'/**/*.css' |
157 ], function(event) { |
149 ], function(event) { |
158 return gulp.src(event.path) |
150 return gulp.src(event.path) |
159 .pipe(plugins.connect.reload()); |
151 .pipe(plugins.connect.reload()); |
160 }); |
152 }); |
161 gulp.watch(['./app/**/*.js','!./app/**/*test.js'],['scripts']); |
153 gulp.watch(['./app/**/*.js','!./app/**/*test.js'],['scripts']); |
162 gulp.watch(['!./app/index.html','./app/**/*.html'],['templates']); |
154 gulp.watch(['!./app/index.html','./app/**/*.html'],['templates']); |
163 gulp.watch('./app/**/*.css',['css']); |
155 gulp.watch('./app/**/*.css',['css']); |
164 gulp.watch('./app/index.html',['copy-index']); |
156 gulp.watch('./app/index.html',['copy-index']); |
165 gulp.watch('./data/**/*',['copy-data']); |
157 gulp.watch('./data/**/*',['copy-data']); |
166 gulp.watch('./img/**/*',['copy-img']); |
158 gulp.watch('./img/**/*',['copy-img']); |
167 |
|
168 }); |
159 }); |
169 |
160 |
170 gulp.task('connect', plugins.connect.server({ |
|
171 root: ['build'], |
|
172 port: 9000, |
|
173 livereload: true |
|
174 })); |
|
175 |
161 |
176 gulp.task('default',['connect','scripts','templates','css','copy-index','copy-data','copy-img','vendorJS','vendorCSS','vendorFonts','watch']); |
162 gulp.task('connect', function() { |
|
163 plugins.connect.server({ |
|
164 root: buildFolder, |
|
165 port: 9000, |
|
166 livereload: true |
|
167 }); |
|
168 }); |
|
169 |
|
170 gulp.task('default',['connect','scripts','css', 'templates','copy-index','copy-data','copy-img','vendorJS','vendorCSS','vendorFonts','watch']); |
|
171 gulp.task('copy-server',['scripts','css', 'templates','copy-index','copy-data','copy-img','vendorJS','vendorCSS','vendorFonts','minimify','copy-server']); |
|
172 |