This repository has been archived by the owner on Sep 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
executable file
·229 lines (191 loc) · 5.04 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
// Requirements
// ------------------------
var gulp = require('gulp'),
// Utils
rename = require('gulp-rename'),
header = require('gulp-header'),
inject = require('gulp-inject'),
concat = require('gulp-concat'),
// Template
minifyHTML = require('gulp-minify-html'),
wiredep = require('wiredep').stream,
svgstore = require('gulp-svgstore'),
// Images
imagemin = require('gulp-imagemin'),
pngquant = require('imagemin-pngquant'),
// Scripts
jshint = require('gulp-jshint'),
stylish = require('jshint-stylish'),
uglify = require('gulp-uglify'),
// Styles
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
sourcemaps = require('gulp-sourcemaps'),
minifyCSS = require('gulp-minify-css'),
// Doc
hologram = require('gulp-hologram'),
// Server
browserSync = require('browser-sync'),
// SEO
sitemap = require('gulp-sitemap'),
// Deployment to Github Pages
ghPages = require('gulp-gh-pages');
// Settings
// ------------------------
var banner = [
'/*!\n' +
' * <%= package.name %>\n' +
' * <%= package.title %>\n' +
' * <%= package.url %>\n' +
' * @author <%= package.author %>\n' +
' * @version <%= package.version %>\n' +
' * Copyright ' + new Date().getFullYear() + '. <%= package.license %> licensed.\n' +
' */',
'\n'
].join('');
var src = './src/',
dist = './app/',
package = require('./package.json'),
reload = browserSync.reload;
// Gulp Tasks
// ------------------------
// COPY
// Copy extra files like .htaccess, robots.txt
gulp.task('copy', function () {
return gulp.src(['./.htaccess', './robots.txt', './CNAME'])
.pipe(gulp.dest(dist));
});
// TEMPLATE
// Bower css and scripts inject + SVG Sprite inject
gulp.task('template', function () {
var svgs = gulp
.src(src + 'assets/icons/*.svg')
.pipe(svgstore({ inlineSvg: true }));
function fileContents (filePath, file) {
return file.contents.toString();
}
return gulp.src(src + '*.html')
.pipe(wiredep({
includeSelf: true
}))
.pipe(inject(svgs, { transform: fileContents }))
.pipe(minifyHTML({
conditionals: true,
spare: true
}))
.pipe(gulp.dest(dist))
.pipe(reload({
stream: true
}));
});
// IMAGES
// Optimization
gulp.task('images', function () {
return gulp.src(src + 'assets/images/*')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{
removeViewBox: false
}],
use: [pngquant()]
}))
.pipe(gulp.dest(dist + 'assets/images/'))
.pipe(reload({
stream: true
}));
});
// SCRIPTS
// JSHint, Uglify
gulp.task('scripts', function () {
return gulp.src([src + 'scripts/*.js'])
.pipe(concat('main.min.js'))
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(uglify())
.pipe(gulp.dest(dist + 'scripts'))
.pipe(reload({
stream: true
}));
});
// Bower components main scripts files
gulp.task('vendors', function() {
var vendorsJS = require('wiredep')().js;
return gulp.src(vendorsJS)
.pipe(concat('vendors.min.js'))
.pipe(uglify())
.pipe(gulp.dest(dist+'scripts'));
});
// STYLES
// LibSass, Minified
gulp.task('styles', function () {
return gulp.src(src + 'styles/{,*/}*.{scss,sass}')
.pipe(sourcemaps.init())
.pipe(wiredep())
.pipe(sass({
errLogToConsole: true
}))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(minifyCSS())
.pipe(rename({
suffix: '.min'
}))
.pipe(header(banner, {
package: package
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest(dist + 'styles'))
.pipe(reload({
stream: true
}));
});
// DOC
// Hologram: http://www.wearecube.ch/maintaining-living-style-guides-with-hologram/
gulp.task('doc', function () {
return gulp.src('hologram_config.yml')
.pipe(hologram())
.pipe(reload({
stream: true
}));
});
// SERVER
// Browser Sync
gulp.task('serve', function () {
return browserSync.init(null, {
server: {
baseDir: dist,
routes: {
"/bower_components": "bower_components"
}
}
});
});
// SEO
// Generate a Sitemap
gulp.task('sitemap', function () {
return gulp.src(dist+'/*.html')
.pipe(sitemap({
siteUrl: 'http://opendevicelabbern.ch/'
}))
.pipe(gulp.dest(dist));
});
// All Task to build the page
gulp.task('build',['copy', 'vendors', 'template', 'images', 'scripts', 'styles', 'doc', 'sitemap']);
// Deploy to Github Pages
gulp.task('deploy',['build'], function() {
return gulp.src(dist + '**/*')
.pipe(ghPages());
});
// Gulp Default Task
// ------------------------
// Having watch within the task ensures that 'sass' has already ran before watching
gulp.task('default', ['build', 'serve'], function () {
gulp.watch(src + '{,*/}*.html', ['template']);
gulp.watch(src + 'assets/icons/*.svg', ['template']);
gulp.watch(src + 'scripts/*.js', ['scripts']);
gulp.watch(src + 'assets/images/*', ['images']);
gulp.watch(src + 'styles/{,*/}*.{scss,sass}', ['styles', 'doc']);
gulp.watch(src + 'styles/styleguide.md', ['doc']);
});