-
Notifications
You must be signed in to change notification settings - Fork 84
/
gulpfile.js
202 lines (177 loc) · 4.37 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// include plug-ins
var gulp = require('gulp');
var $ = require('gulp-load-plugins')({
pattern: ['gulp-*', 'gulp.*', 'watch', 'del'],
});
// settings
var base = './htdocs/';
var build = base + 'build/';
// styles
var styles = base + 'css/';
// images
var images = base + 'img/';
// js
var vendor = base + 'vendor/';
var javascripts = base + 'js/';
var flot = base + 'vendor/flot/';
var extensions = base + 'js/jquery/';
var jsfiles = [
'gulpfile.js',
base + 'js/**/*.js',
'!' + base + 'js/canvas/**/*.js',
'!' + base + 'js/jquery/**/*.js',
'!**/*.min.js'
];
/**
* Defaults
*/
gulp.task('default', ['jshint', 'watch']);
/**
* Watch javascripts
*/
gulp.task('watch', function() {
gulp.src(jsfiles)
.pipe($.watch(jsfiles))
.pipe($.jshint())
.pipe($.jshint.reporter('default'));
});
/**
* Build
*/
gulp.task('build', ['clean', 'jshint', 'scripts', 'sprites']);
gulp.task('clean', function () {
$.del([
build + '**'
]);
});
gulp.task('jshint', function() {
gulp.src(jsfiles)
.pipe($.jshint())
.pipe($.jshint.reporter('default'))
.pipe($.jshint.reporter('fail'));
});
/**
* Scripts
*/
gulp.task('scripts', ['flot', 'jquery-ext', 'vz-scripts']);
gulp.task('vz-scripts', function() {
return gulp.src([
javascripts + 'helper.js', // in order of index.html
javascripts + 'init.js',
javascripts + 'functions.js',
javascripts + 'entities.js',
javascripts + 'wui.js',
javascripts + 'plot.js',
javascripts + 'entity.js',
'!**/options.js', // exclude options
])
.pipe($.concat('scripts.js'))
.pipe(gulp.dest(build)) // for reference only
.pipe($.size({showFiles: true}))
.pipe($.uglify())
.pipe($.rename('scripts.min.js'))
.pipe(gulp.dest(javascripts))
.pipe($.size({showFiles: true}));
});
gulp.task('flot', function() {
return gulp.src([
flot + '**/jquery.flot.js', // flot first
// flot + '**.js', // then flot modules
flot + '**/jquery.flot.crosshair.js',
flot + '**/jquery.flot.selection.js',
flot + '**/jquery.flot.time.js',
flot + '**/jquery.flot.canvas.js',
flot + '**/jquery.flot.axislabels.js',
flot + '**/jquery.flot.xgap.js',
flot + '**/jquery.flot.orderBars.js',
flot + '**/date.js',
flot + '**/canvas2image.js',
flot + '**/base64.js',
'!**/excanvas*.js', // omit canvas helper
'!**/*.min.js', // omit minified files
])
.pipe($.concat('flot.js'))
.pipe(gulp.dest(build)) // for reference only
.pipe($.size({showFiles: true}))
.pipe($.uglify())
.pipe($.rename('flot.min.js'))
.pipe(gulp.dest(flot))
.pipe($.size({showFiles: true}));
});
gulp.task('jquery-ext', function() {
return gulp.src([
extensions + '**.js',
'!**/*.min.js', // omit minified files
])
.pipe($.concat('jquery-extensions.js'))
.pipe(gulp.dest(build)) // for reference only
.pipe($.size({showFiles: true}))
.pipe($.uglify())
.pipe($.rename('jquery-ext.min.js'))
.pipe(gulp.dest(extensions))
.pipe($.size({showFiles: true}));
});
/**
* Sprites
*/
gulp.task('sprites', function () {
// Combine images into sprite
var spriteData = gulp.src([
images + '!(sprites|blank|ui-|style_|empty)*.png',
images + 'types/*!(32).png'
])
.pipe($.spritesmith({
imgName: '../img/sprites.png', // link to images folder
cssName: 'sprites.css',
algorithm: 'top-down',
padding: 2
}));
spriteData.img
.pipe($.imagemin())
.pipe(gulp.dest(images));
spriteData.css
.pipe(gulp.dest(build));
// remove dimensions and save as new css file
gulp.src(build + 'sprites.css')
.pipe($.replace(/ width: 16px;\n height: 16px;\n/g, ''))
.pipe(gulp.dest(styles));
});
/**
* CSS
*/
// not used
gulp.task('css-minimize', function () {
gulp.src(styles + '*.css')
.pipe($.concat('styles.css'))
.pipe(gulp.dest(build))
.pipe($.cssnano({
keepBreaks:true
}))
.pipe($.rename('styles.min.css'))
.pipe(gulp.dest(build));
});
// not used
gulp.task('css-strip', function() {
gulp.src(styles + '*.css')
// gulp.src(build + 'styles.min.css')
.pipe($.uncss({
html: [base + 'index.html']
}))
// .pipe($.rename('styles.min.css'))
.pipe(gulp.dest(build))
.pipe(cssnano({
keepBreaks:true
}))
.pipe(rename('styles.min.css'))
.pipe(gulp.dest(build));
});
// not used
gulp.task('css-strip', function() {
gulp.src(styles + '*.css')
// gulp.src(build + 'styles.min.css')
.pipe(uncss({
html: [base + 'index.html']
}))
// .pipe(rename('styles.min.css'))
.pipe(gulp.dest(build));
});