forked from swiss/styleguide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
236 lines (210 loc) · 7.33 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/* ==========================================================
* gulpfile.js
* List of Gulp.js task to build and run the project
*
* Author: Yann Gouffon, [email protected]
* Date: 2014-04-29 17:53:14
*
* Copyright 2014 Federal Chancellery of Switzerland
* Licensed under MIT
*
* Last Modified by: Toni Fisler
* Last Modified time: 2014-04-30 14:33:12
========================================================== */
'use strict';
/**
* Import plugins
*/
var gulp = require('gulp'),
$ = require('gulp-load-plugins')(),
browserSync = require('browser-sync'),
reload = browserSync.reload,
runSequence = require('run-sequence'),
argv = require('yargs').argv,
del = require('del');
/**
* Build vendors dependencies
*/
gulp.task('vendors', function() {
// DEPRECATED, to be removed in 3.0.0
gulp.src([
'bower_components/jquery.socialshareprivacy/socialshareprivacy/images/*'
])
.pipe(gulp.dest('build/css/images'));
/**
* CSS VENDORS
*/
gulp.src([
'bower_components/yamm3/yamm/yamm.css',
'bower_components/jquery.socialshareprivacy/socialshareprivacy/socialshareprivacy.css',
'bower_components/bootstrapaccessibilityplugin/plugins/css/bootstrap-accessibility.css',
'bower_components/blueimp-gallery/css/blueimp-gallery.min.css',
'bower_components/blueimp-bootstrap-image-gallery/css/bootstrap-image-gallery.min.css'
])
.pipe($.concat('vendors.css'))
.pipe($.minifyCss())
.pipe(gulp.dest('build/css'));
/**
* JS VENDORS
* (with jQuery and Bootstrap dependencies first)
*/
gulp.src([
'bower_components/jquery/jquery.js',
'bower_components/jquery.tablesorter/js/jquery.tablesorter.js',
'bower_components/chosen_v1.1.0/chosen.jquery.min.js',
'bower_components/typeahead.js/dist/typeahead.bundle.js',
'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/affix.js',
'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/alert.js',
'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/button.js',
'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/carousel.js',
'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/collapse.js',
'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/dropdown.js',
'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/modal.js',
'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/tooltip.js',
'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/popover.js',
'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/scrollspy.js',
'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/tab.js',
'bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/transition.js',
'bower_components/bootstrapaccessibilityplugin/plugins/js/bootstrap-accessibility.js',
'bower_components/jquery.tablesorter/js/jquery.tablesorter.js',
'bower_components/jquery.socialshareprivacy/jquery.socialshareprivacy.min.js',
'bower_components/jquery-drilldown/jquery.drilldown.min.js',
'bower_components/placeholdr/placeholdr.js',
'bower_components/blueimp-gallery/js/jquery.blueimp-gallery.min.js',
'bower_components/blueimp-bootstrap-image-gallery/js/bootstrap-image-gallery.min.js'
])
.pipe($.concat('vendors.min.js'))
.pipe($.uglify())
.pipe(gulp.dest('build/js'));
/**
* FONTS SOURCES
* Important to add the bootstrap fonts to avoid issues with the fonts include path
*/
gulp.src([
'bower_components/bootstrap-sass-official/assets/fonts/bootstrap/*',
'assets/fonts/*'
])
.pipe(gulp.dest('build/fonts'));
});
gulp.task('polyfills', function() {
return gulp.src([
'bower_components/html5shiv/dist/html5shiv.min.js',
'bower_components/html5shiv/dist/html5shiv-printshiv.min.js',
'bower_components/respond/dest/respond.min.js'
])
.pipe($.concat('polyfills.min.js'))
.pipe($.uglify())
.pipe(gulp.dest('build/js'));
});
/**
* Build styles from SCSS files
* With error reporting on compiling (so that there's no crash)
*/
gulp.task('styles', function() {
if (!argv.dev) { console.log('[styles] Outputting minified styles.' ); }
else { console.log('[styles] Processing styles for dev env. No minifying here, for sourcemaps!') }
return gulp.src('assets/sass/admin.scss')
.pipe($.sass({
errLogToConsole: true
}))
.pipe($.if(argv.dev, $.sourcemaps.init()))
.pipe($.autoprefixer({
browsers: ['last 2 versions', 'safari 5', 'ie 8', 'ie 9', 'ff 27', 'opera 12.1']
}))
.pipe($.if(argv.dev, $.sourcemaps.write()))
.pipe($.if(!argv.dev, $.minifyCss()))
.pipe(gulp.dest('build/css'));
});
gulp.task('print', function() {
return gulp.src('assets/sass/print/print.scss')
.pipe($.sass({
errLogToConsole: true
}))
.pipe($.if(argv.dev, $.sourcemaps.init()))
.pipe($.autoprefixer({
browsers: ['last 2 versions', 'safari 5', 'ie 8', 'ie 9', 'ff 27', 'opera 12.1']
}))
.pipe($.if(argv.dev, $.sourcemaps.write()))
.pipe($.if(!argv.dev, $.minifyCss()))
.pipe(gulp.dest('build/css'));
});
/**
* Build JS
* With error reporting on compiling (so that there's no crash)
*/
gulp.task('scripts', function() {
return gulp.src('assets/js/*.js')
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.concat('main.js'))
.pipe(gulp.dest('build/js'))
.pipe($.rename({ suffix: '.min' }))
.pipe($.uglify())
.pipe(gulp.dest('build/js'));
});
/**
* Build Hologram Styleguide
*/
gulp.task('styleguide', function () {
return gulp.src('hologram_config.yml')
.pipe($.hologram({ bundler: true }));
});
gulp.task('build-images', function() {
return gulp.src(['assets/img/**'])
.pipe(gulp.dest('build/img'));
});
gulp.task('build-fonts', function() {
return gulp.src(['assets/fonts/**'])
.pipe(gulp.dest('build/fonts'));
});
/**
* Compile TWIG example pages
*/
gulp.task('twig', function () {
return gulp.src('assets/pages/*.twig')
.pipe($.twig())
.pipe(gulp.dest('styleguide/pages'));
});
/**
* Clean output directories
*/
gulp.task('clean', del.bind(null, ['build', 'styleguide']));
/**
* Serve
*/
gulp.task('serve', ['styles', 'scripts'], function () {
browserSync({
server: {
baseDir: ['styleguide'],
},
open: false
});
gulp.watch(['assets/sass/**/*.scss'], function() {
runSequence('styles', 'print', 'styleguide', reload);
});
gulp.watch(['assets/js/*.js'], function() {
runSequence('scripts', 'styleguide', reload);
});
gulp.watch(['assets/img/**/*.{jpg,png,gif,svg}'], function() {
runSequence('build-images', 'styleguide', reload);
});
gulp.watch(['assets/fonts/**/*.{eot,svg,woff,ttf}'], function() {
runSequence('build-fonts', 'styleguide', reload);
});
gulp.watch(['assets/pages/**/*.twig'], function() {
runSequence('twig', reload);
});
});
/**
* Deploy to GH pages
*/
gulp.task('deploy', function () {
return gulp.src("styleguide/**/*")
.pipe($.ghPages());
});
/**
* Default task
*/
gulp.task('default', ['clean'], function(cb) {
runSequence('vendors', 'polyfills', 'styles', 'print', 'scripts', 'twig', 'build-images', 'build-fonts', 'styleguide', cb);
});