-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
77 lines (64 loc) · 3.32 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* jshint node:true, jquery:false */
'use strict';
var gulp = require('gulp');
var $$ = require('gulp-load-plugins')({lazy: true});
var del = require('del');
var path = require('path');
var streamqueue = require('streamqueue');
gulp.task('clean', function (cb) {
del(['dist/*'], cb);
});
gulp.task('analyze', function (cb) {
var basePath = path.resolve('./src/app/');
$$.util.log('Analyzing sources in ' + basePath);
gulp.src([basePath + '/**/*.js', '!./bower_components/**/*'])
.pipe($$.jshint())
.pipe($$.jshint.reporter('jshint-stylish', {verbose: true}))
.pipe($$.jshint.reporter('fail'))
.on('end', cb); // returning the stream does not fail the build, therefore we must use the callback style
});
gulp.task('release', ['clean'], function () {
var processedJsFile = 'timerec-app.js'; // Convention: This name has to match the name in the build comment of the index.html
var assets = $$.useref.assets();
var appAndTemplateFilter = $$.filter(['**/*app.js', '**/*templates.js']); // Convention: filter out the *.app.js and the *template.js file
var jsFilter = $$.filter('**/*.js');
var cssFilter = $$.filter('**/*.css');
var htmlFilter = $$.filter('**/*.html');
var basePath = path.resolve('./src');
var templateStream = gulp.src('./src/app/**/*.html')
.pipe($$.debug({title: 'Template Files:'}))
.pipe($$.angularTemplatecache('timerec-templates.js', {
module: 'timerecApp',
base: basePath
}));
gulp.src('./src/bower_components/bootstrap/fonts/*')
.pipe(gulp.dest('./dist/fonts'));
var assetStream = gulp.src(['./src/**/*.html', '!./src/bower_components/**/*'])
.pipe(assets); // Concatenate asset-groups with gulp-useref
return streamqueue({objectMode: true}, assetStream, templateStream) // streamqueue should keep the order -> templates are concatenated at the end
.pipe(appAndTemplateFilter)
.pipe($$.debug({title: 'Asset Files:'}))
.pipe($$.concat(processedJsFile))// Concat the *template.js file to the *app.js file
.pipe($$.debug({title: 'Asset Files:'}))
.pipe($$.ngAnnotate()) // Process app javascript sources to add dependency injection annotations
.pipe(appAndTemplateFilter.restore())
.pipe(jsFilter)
.pipe($$.uglify()) // Minify all javascript sources
.pipe(jsFilter.restore())
.pipe(cssFilter)
.pipe($$.minifyCss({target: path.join(process.cwd(), 'dist/')})) // Minify CSS sources
.pipe(cssFilter.restore())
.pipe($$.rev()) // Rename the concatenated files with a hash-prefix
.pipe(assets.restore())
.pipe($$.useref()) // Replace the original references in the html with the concatenated and processed resources by usemin
.pipe($$.revReplace()) // Replace the usemin generated resources with the reved resources
.pipe(htmlFilter)
.pipe($$.htmlmin({removeComments: true})) // Remove comments from html
.pipe(htmlFilter.restore())
.pipe($$.debug({title: 'Processed output File: '}))
.pipe(gulp.dest('dist/'));
});
gulp.task('default', ['analyze', 'release']);
gulp.task('watch', function () {
gulp.watch(['./app/index.html', './app/scripts/**/*.js'], ['default']);
});