-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
274 lines (244 loc) · 8.3 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*
* gulp.js
* Copyright (C) 2015 ronan <[email protected]>
*
* Distributed under terms of the MIT license.
*/
'use strict';
var gulp = require('gulp'),
concat = require('gulp-concat'),
less = require('gulp-less'),
csscomb = require('gulp-csscomb'),
minifyCss = require("gulp-minify-css"),
uncss = require('gulp-uncss'),
path = require('path'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
cache = require('gulp-cache'),
ssg = require('gulp-ssg'),
rename = require('gulp-rename'),
data = require('gulp-data'),
matter = require('gray-matter'),
markdown = require('gulp-markdown'),
minifyHTML = require("gulp-minify-html"),
changed = require("gulp-changed"),
wrap = require('gulp-wrap'),
includer = require('gulp-lb-include'),
del = require('del'),
sitemap = require('gulp-sitemap'),
debug = require('gulp-debug'),
notify = require('gulp-notify'),
open = require('gulp-open')
;
var watch = true,
src = './src',
assets = './assets',
website = './',
metadata = {
site_name: 'OpenWines',
site_url: 'http://openwines.eu',
description: 'Open-Data, for vineyards, winegrowers and wines',
locale: 'en_GB',
locale_alternate: 'fr_FR',
publication: new Date(),
modification: new Date(),
thumbnail: 'http://openwines.eu/assets/images/ow-logotype-256x256.png',
thumbnail_height: 256,
thumbnail_width: 256
};
var paths = {
contents: src + '/contents/**/*.{md, markdown}',
stylesheets: src + '/css/*.css',
template: src + '/templates/',
templateFile: 'template.html',
source: {
partials: src + '/partials',
less: src + '/less',
lessFile: 'main.less',
css: src + '/css',
scripts: src + '/js/scripts/*.js',
vendor: src + '/js/vendor/*.js',
plugins: src + '/js/plugins/*.js',
bootscript: src + '/js/vendor/bootstrap/',
images: src + '/images/**/*',
fonts: src + '/fonts/*',
},
destination: {
cssFile: 'main.css',
//vendorFile: 'vendor.js',
css: assets + '/css',
js: assets + '/js',
images: assets + '/images',
fonts: assets + '/fonts',
min: {
cssFile: 'main.min.css',
jsFile: 'main.min.js',
//vendorFile: 'vendor.min.js'
}
},
html: [
website + '*.html',
website + 'posts/*.html'
]
};
// Purge before rebuild
gulp.task('clean', function(cb) {
return del([
assets,
website + '*.html',
website + 'posts/*.html'
], cb);
});
// Move Files
gulp.task('move', function(){
gulp.src(paths.source.fonts)
.pipe(gulp.dest(paths.destination.fonts))
});
// Include - not used yet
gulp.task('include', function () {
gulp.src(paths.partials + '/template.html')
.pipe(includer())
.pipe(gulp.dest(paths.template + paths.templateFile));
});
// Compile Less
gulp.task('less', function () {
gulp.src(paths.source.less + '/' + paths.source.lessFile)
.pipe(less({
paths: [ path.join(__dirname, 'less', 'includes') ]
}))
.pipe(csscomb())
.pipe(minifyCss())
.pipe(rename(paths.destination.min.cssFile))
.pipe(gulp.dest(paths.destination.css));
});
// // Uncss
// gulp.task('ultimcss', ['less'], function () {
// gulp.src(paths.source.css + '/' + paths.destination.cssFile)
// .pipe(uncss({
// html: [website + 'index.html'] // *.html files all use a common layout template
// }))
// .pipe(minifyCss())
// .pipe(rename(paths.destination.min.cssFile))
// .pipe(gulp.dest(paths.destination.css));
// });
// Minify Scripts
gulp.task('scripts', function() {
gulp.src(paths.source.scripts)
.pipe(uglify())
.pipe(rename(paths.destination.min.jsFile))
.pipe(gulp.dest(paths.destination.js));
});
// Minify New Images
gulp.task('imagemin', function() {
gulp.src(paths.source.images)
.pipe(cache(imagemin({
optimizationLevel: 5,
progressive: true,
interlaced: true
})))
.pipe(gulp.dest(paths.destination.images));
});
// Minify Vendor
gulp.task('vendor', function() {
gulp.src(paths.source.vendor)
.pipe(uglify())
//.pipe(concat(paths.destination.vendorFile))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest(paths.destination.js));
});
// Concatenate & Minify Plugins
gulp.task('plugins', function() {
gulp.src(paths.source.plugins)
.pipe(concat('plugins.js'))
.pipe(rename('plugins.min.js'))
.pipe(uglify())
.pipe(gulp.dest(paths.destination.js));
});
// Concatenate & Minify Bootstrap js
gulp.task('bootstrap', function () {
gulp.src([
paths.source.bootscript + 'transition.js',
paths.source.bootscript + 'alert.js',
paths.source.bootscript + 'button.js',
paths.source.bootscript + 'carousel.js',
paths.source.bootscript + 'collapse.js',
paths.source.bootscript + 'dropdown.js',
paths.source.bootscript + 'modal.js',
paths.source.bootscript + 'tooltip.js',
paths.source.bootscript + 'popover.js',
paths.source.bootscript + 'scrollspy.js',
paths.source.bootscript + 'tab.js',
paths.source.bootscript + 'affix.js'
])
.pipe(concat('bootstrap.js'))
.pipe(rename('bootstrap.min.js'))
.pipe(uglify())
.pipe(gulp.dest(paths.destination.js));
});
/**
* - Extracts front-matter from each markdown file, assigns it to file object
* - Converts markdown to HTML
* - Passes each file through a template (using hogan flavour of mustache) adding some extra site variables
* - Outputs to a public directory
*
* In the template a simple global navigation is generated of the root files siblings.
* inspiration: https://github.com/paulwib/gulp-ssg/blob/master/examples/markdown-website/gulpfile.js
*/
gulp.task('contents', ['watch', 'less',/*'ultimcss',*/ 'include', 'move', 'scripts', 'imagemin', 'vendor', 'plugins', 'bootstrap'], function () {
return gulp.src(paths.contents)
// Extract YAML front-matter using gulp-data
.pipe(data(function(file) {
var m = matter(String(file.contents));
file.contents = new Buffer(m.content);
return m.data;
}))
// markdown -> HTML
.pipe(markdown())
// Rename to .html
.pipe(rename({ extname: '.html' }))
// Run through gulp-ssg
.pipe(ssg())
// Wrap file in template
.pipe(wrap(
{ src: 'src/templates/template.html' },
{ siteTitle: metadata.site_name, metadata: metadata},
{ engine: 'hogan' }
))
.pipe(minifyHTML())
// Output to build directory
.pipe(gulp.dest(website));
});
// Sitemap
gulp.task('build', ['contents'], function () {
gulp.src(paths.html, { base: './' })
.pipe(sitemap({
siteUrl: 'http://openwines.eu'
}))
.pipe(gulp.dest(website))
.pipe(notify("build achieved."));
});
// Watch for changes in files
gulp.task('watch', function() {
if(watch) {
gulp.watch(paths.source.less + '/**/*.less', ['less']);
gulp.watch(paths.partials + '/**/*.html', ['include']);
gulp.watch(paths.contents, ['build']);
gulp.watch(paths.source.scripts, ['scripts']);
gulp.watch(paths.source.vendor, ['vendor']);
gulp.watch(paths.source.plugins, ['plugins']);
gulp.watch(paths.source.bootscript, ['bootstrap']);
gulp.watch(paths.source.images, ['imagemin']);
}
});
gulp.task('check', function(){
gulp.src(website + 'index.html')
.pipe(open());
});
gulp.task('default', ['clean'], function () {
watch = true;
gulp.start('build');
});
gulp.task('justbuild', ['clean'], function () {
watch = false;
gulp.start('build');
});