-
Notifications
You must be signed in to change notification settings - Fork 26
/
gulpfile.js
151 lines (136 loc) · 4.61 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var inject = require('gulp-inject');
var useref = require('gulp-useref');
var filter = require('gulp-filter');
var ngAnnotate = require('gulp-ng-annotate');
var htmlify = require('gulp-angular-htmlify');
var minifyCss = require('gulp-minify-css');
var minifyHtml = require('gulp-minify-html');
var templateCache = require('gulp-angular-templatecache');
var angularFilesort = require('gulp-angular-filesort');
var del = require('del');
var size = require('gulp-filesize');
var rev = require('gulp-rev');
var git = require('gulp-git');
var bump = require('gulp-bump');
var tag_version = require('gulp-tag-version');
gulp.task('default',['build', 'templates'], function(){
});
// Remove the dist directory
gulp.task('clean', function(cb) {
del(['dist'], cb);
});
// Put all templates in a templateCache
gulp.task('templates', function(){
return gulp.src('src/templates/**/*.html')
.pipe(htmlify({
customPrefixes: ['my-']
}))
.pipe(minifyHtml())
.pipe(templateCache({
root: 'src/templates/',
module: 'cardboard'
}))
.pipe(rev())
.pipe(size())
.pipe(gulp.dest('dist'));
});
// Inject App files (no bower_components) in index.html for development
gulp.task('inject', function(){
gulp.src('index.html')
.pipe(inject(gulp.src('src/**/*.css',{read: false})))
.pipe(inject(
gulp.src('src/**/*.js')
.pipe(angularFilesort())
))
.pipe(gulp.dest('./'));
});
// Build a production-ready dist folder
gulp.task('build',['templates'], function(){
// copy the manifest to dist/
gulp.src('manifest.json')
.pipe(gulp.dest('dist'));
// copy resources/ to dist/
gulp.src('resources/**')
.pipe(gulp.dest('dist/resources'));
// copy materialize fonts to dist/
gulp.src('bower_components/materialize/dist/font/**')
.pipe(gulp.dest('dist/font'));
var assets = useref.assets();
// var bowerUnMinJs = filter(['bower_components/**/*.js','!bower_components/**/*.min.js','!google-analytics-bundle.js']);
// var appJs = filter(['src/**/*.js']);
// var unMinCss = filter(['*.css','!*.min.css']);
return gulp.src('index.html')
// inject css in index.html
.pipe(inject(gulp.src('src/**/*.css',{read: false})))
// inject cached templates in index.html
.pipe(inject(
gulp.src('templates-*.js',{
read: false,
cwd: 'dist/'
}),
{
name: 'templates',
addRootSlash: false
}
))
// inject app files in index.html
.pipe(inject(
gulp.src('src/**/*.js')
.pipe(angularFilesort())
))
// get build blocks assets
.pipe(assets)
// // exclude the already minified JS files
// .pipe(bowerUnMinJs)
// .pipe(size())
// // minify
// .pipe(uglify())
// .pipe(bowerUnMinJs.restore())
// // exclude the already minified CSS files
// .pipe(unMinCss)
// .pipe(size())
// // minify
// .pipe(minifyCss())
// .pipe(unMinCss.restore())
// // restore filtered stream
.pipe(assets.restore())
// concat build blocks
.pipe(useref())
// .pipe(htmlify({
// customPrefixes: ['my-']
// }))
.pipe(size())
.pipe(gulp.dest('dist/'));
});
/**
* Bumping version number and tagging the repository with it.
* Please read http://semver.org/
*
* You can use the commands
*
* gulp patch # makes v0.1.0 → v0.1.1
* gulp feature # makes v0.1.1 → v0.2.0
* gulp release # makes v0.2.1 → v1.0.0
*
* To bump the version numbers accordingly after you did a patch,
* introduced a feature or made a backwards-incompatible release.
*/
function inc(importance) {
// get all the files to bump version in
return gulp.src(['./manifest.json','./package.json', './bower.json'])
// bump the version number in those files
.pipe(bump({type: importance}))
// save it back to filesystem
.pipe(gulp.dest('./'))
// commit the changed version number
.pipe(git.commit('bumps package version'))
// read only one file to get the version number
.pipe(filter('manifest.json'))
// **tag it in the repository**
.pipe(tag_version());
}
gulp.task('patch', function() { return inc('patch'); })
gulp.task('feature', function() { return inc('minor'); })
gulp.task('release', function() { return inc('major'); })