-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
179 lines (157 loc) · 4.8 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
'use strict';
var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync').create();
var cache = require('gulp-cached');
var fs = require('fs');
var gulp = require('gulp');
var handlebars = require('gulp-compile-handlebars');
var imagemin = require('gulp-imagemin');
var inlinesource = require('gulp-inline-source');
var jscs = require('gulp-jscs');
var jshint = require('gulp-jshint');
var layouts = require('handlebars-layouts');
var minifyCss = require('gulp-minify-css');
var minifyHTML = require('gulp-minify-html');
var plumber = require('gulp-plumber');
var reload = browserSync.reload;
var rename = require('gulp-rename');
var replace = require('gulp-replace');
var sass = require('gulp-sass');
var scsslint = require('gulp-scss-lint');
var shell = require('gulp-shell');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var yaml = require('js-yaml');
handlebars.Handlebars.registerHelper('if_even', function (conditional, options) {
if ((conditional % 2) === 0) {
return options.fn(this);
} else {
return options.inverse(this);
}
});
handlebars.Handlebars.registerHelper(layouts(handlebars.Handlebars));
gulp.task('sass:lint', function () {
gulp.src('./src/sass/*.scss')
.pipe(plumber())
.pipe(scsslint({
config: 'scss-lint.yml',
}));
});
gulp.task('sass:build', function () {
gulp.src('./src/sass/**/style.scss')
.pipe(rename({ suffix: '.min' }))
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'compressed',
}))
.pipe(autoprefixer())
.pipe(sourcemaps.write())
.pipe(gulp.dest('./dist/css/'));
});
gulp.task('sass:optimized', function () {
gulp.src('./src/sass/**/style.scss')
.pipe(rename({ suffix: '.min' }))
.pipe(plumber())
.pipe(sass({
outputStyle: 'compressed',
}))
.pipe(autoprefixer())
.pipe(minifyCss({
compatibility: 'ie8',
}))
.pipe(gulp.dest('dist/css/'));
});
gulp.task('sass', ['sass:lint', 'sass:build']);
gulp.task('js:build', function () {
gulp.src('src/js/**/*.js')
.pipe(plumber())
.pipe(uglify())
.pipe(gulp.dest('dist/js'));
});
gulp.task('js:lint', function () {
gulp.src(['./src/js/**/*.js', '!./src/js/lib/**/*.js', 'Gulpfile.js'])
.pipe(plumber())
.pipe(jscs())
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('js', ['js:lint', 'js:build']);
gulp.task('images', function () {
gulp.src('src/img/**/*')
.pipe(plumber())
.pipe(imagemin({
progressive: true,
}))
.pipe(gulp.dest('./dist/img'));
});
gulp.task('images:optimized', function () {
gulp.src('src/img/**/*')
.pipe(plumber())
.pipe(imagemin({
progressive: true,
multipass: true,
}))
.pipe(gulp.dest('./dist/img'));
});
gulp.task('fonts', function () {
gulp.src('src/font/*')
.pipe(plumber())
.pipe(gulp.dest('./dist/font'));
});
gulp.task('templates', function () {
var templateData = yaml.safeLoad(fs.readFileSync('data.yml', 'utf-8'));
var options = {
ignorePartials: true, //ignores the unknown footer2 partial in the handlebars template, defaults to false
batch: ['./src/partials/'],
helpers: {
capitals: function (str) {
return str.toUpperCase();
},
},
};
return gulp.src('./src/templates/**/*.hbs')
.pipe(plumber())
.pipe(handlebars(templateData, options))
.pipe(rename(function (path) {
path.extname = '.html';
}))
.pipe(gulp.dest('dist'));
});
gulp.task('templates:optimized', ['templates'], function () {
gulp.src('./dist/**/*.html')
.pipe(inlinesource())
.pipe(replace(/\.\.\//g, ''))
.pipe(minifyHTML({
conditionals: true,
spare:true,
}))
.pipe(gulp.dest('./dist/'));
});
gulp.task('watch', function () {
gulp.watch(['./src/templates/**/*.hbs', './src/partials/**/*.hbs'], ['templates'], reload);
gulp.watch('./src/sass/**/*.scss', ['sass'], reload);
gulp.watch('./src/img/**/*', ['images'], reload);
gulp.watch(['./src/js/**/*.js', 'Gulpfile.js'], ['js'], reload);
});
gulp.task('build', ['sass', 'images', 'fonts', 'js', 'templates']);
gulp.task('build:optimized', ['sass:optimized', 'images:optimized', 'fonts', 'js', 'templates:optimized']);
gulp.task('deploy', ['build:optimized'], function () {
gulp.src('')
.pipe(shell('scp -r dist/* root@eunicode:../var/www/html'))
.on('finish', function () {
process.stdout.write('Deployed to http://eunicod.es/');
});
});
// use default task to launch Browsersync and watch JS files
gulp.task('serve', ['build'], function () {
// Serve files from the root of this project
browserSync.init(['./dist/**/*'], {
server: {
baseDir: './dist',
},
});
// add browserSync.reload to the tasks array to make
// all browsers reload after tasks are complete.
gulp.start(['watch']);
});