-
Notifications
You must be signed in to change notification settings - Fork 13
/
gulpfile.js
130 lines (115 loc) · 3.14 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
var gulp = require('gulp');
var path = require('path');
var del = require('del');
var rename = require("gulp-rename");
var runSequence = require('run-sequence');
var webserver = require('gulp-webserver');
var livereload = require('gulp-livereload');
var ghPages = require('gulp-gh-pages');
var sass = require('gulp-sass');
var scsslint = require('gulp-scss-lint');
var autoprefixer = require('gulp-autoprefixer');
var haml = require('gulp-haml');
var prettify = require('gulp-html-prettify');
var inject = require('gulp-inject');
var svgstore = require('gulp-svgstore');
var svgmin = require('gulp-svgmin');
var cheerio = require('gulp-cheerio');
gulp.task('clean', function() {
return del("build");
});
gulp.task('haml', function () {
return gulp.src('*.haml')
.pipe(haml())
.pipe(gulp.dest('build'));
});
gulp.task('prettify', function(callback) {
return gulp.src('build/*.html')
.pipe(prettify({indent_char: ' ', indent_size: 2}))
.pipe(gulp.dest('build'));
});
gulp.task('inlineSvg', function () {
var svgs = gulp.src('svg/*.svg')
.pipe(svgmin(function (file) {
var prefix = path.basename(file.relative, path.extname(file.relative));
return {
plugins: [{
cleanupIDs: {
prefix: prefix + '-',
minify: true
}
}]
}
}))
.pipe(cheerio({
run: function ($) {
$('[fill]').removeAttr('fill');
$('title').remove();
},
parserOptions: { xmlMode: true }
}))
.pipe(svgstore({ inlineSvg: true }));
function fileContents (filePath, file) {
return file.contents.toString();
}
return gulp
.src('build/index.html')
.pipe(inject(svgs, { transform: fileContents }))
.pipe(gulp.dest('build'));
});
gulp.task('sass', function () {
gulp.src('scss/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gulp.dest('build'))
.pipe(livereload());
});
gulp.task('js', function () {
gulp.src(['js/**/*.js','js/**/*.mem'])
.pipe(gulp.dest('build/js'))
.pipe(livereload());
});
gulp.task('copy', function () {
gulp.src('scss/_searchbox.scss')
.pipe(rename('searchbox.scss'))
.pipe(gulp.dest('build/scss'));
gulp.src('scss/themes/*.scss')
.pipe(gulp.dest('build/scss/themes'));
gulp.src('favicon.ico')
.pipe(gulp.dest('build'));
});
gulp.task('watch', function() {
livereload.listen();
gulp.watch('scss/**/*.scss', ['sass','copy','scss-lint']);
gulp.watch('*.haml', ['build']);
gulp.watch('js/**/*.js', ['js']);
});
gulp.task('webserver', function() {
gulp.src('build')
.pipe(webserver({
host: '0.0.0.0',
port: 1337,
livereload: true,
directoryListing: false,
open: true
}));
});
gulp.task('build',['clean'], function(callback) {
runSequence('haml', 'inlineSvg', 'prettify', 'js', 'sass','copy', callback);
});
gulp.task('dev', function(callback) {
runSequence('build', 'watch','webserver', callback);
});
gulp.task('deploy', function() {
return gulp.src('build/**/*')
.pipe(ghPages());
});
gulp.task('scss-lint', function() {
return gulp.src('scss/*.scss')
.pipe(scsslint({
'config': '.scss-lint.yml'
}));
});