-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
127 lines (108 loc) · 3.36 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
var gulp = require('gulp');
var autoprefixer = require('gulp-autoprefixer');
var concat = require('gulp-concat');
var ejs = require('gulp-ejs');
var minifyCSS = require('gulp-minify-css');
var minifyHTML = require('gulp-minify-html');
var sass = require('gulp-sass');
var scsslint = require('gulp-scss-lint');
var uglify = require('gulp-uglify');
// var validator = require('gulp-html');
var watch = require('gulp-watch');
var plumber = require('gulp-plumber');
var notify = require('gulp-notify');
var clean = require('gulp-clean');
var plumberRequest = {
errorHandler: notify.onError('Error: <%= error.message %>')
};
var ejsOptions = {
EJS_ROOT: __dirname + "/src/ejs/",
creators: require( "./src/json/creators.json" ),
portfolios: require("./src/json/portfolios.json"),
tags: require("./src/json/tags.json"),
products: require("./src/json/products.json")
};
// gulp.task('validator', function () {
// return gulp.src('dest/**/*.html')
// .pipe(validator());
// });
gulp.task('sass', function (done) {
return gulp.src('src/sass/**/*.scss')
.pipe(plumber(plumberRequest))
.pipe(scsslint({
'config': '.scsslint.yml',
}))
.pipe(sass())
.pipe(autoprefixer({
browsers: ['last 2 versions']
}))
.pipe(minifyCSS())
.pipe(gulp.dest('dest/css'));
done();
});
gulp.task('cname', function (done) {
gulp.src('src/CNAME')
.pipe(gulp.dest('dest/'));
done();
});
gulp.task('vendor', function (done) {
gulp.src('node_modules/sanitize.css/dist/*')
.pipe(gulp.dest('dest/css'));
gulp.src('node_modules/jquery/dist/*')
.pipe(gulp.dest('dest/js/vendor'));
gulp.src('node_modules/masonry-layout/dist/*')
.pipe(gulp.dest('dest/js/vendor'));
gulp.src('node_modules/jquery-lazyload/*.js')
.pipe(gulp.dest('dest/js/vendor'));
done();
});
gulp.task('js', function (done) {
return gulp.src('src/js/**/*.js')
.pipe(plumber(plumberRequest))
.pipe(concat('main.js'))
.pipe(uglify())
.pipe(gulp.dest('dest/js/'));
done();
});
gulp.task('ejs', function (done) {
return gulp.src(['src/ejs/**/*.ejs', '!src/ejs/**/_*.ejs'])
.pipe(plumber(plumberRequest))
.pipe(ejs(ejsOptions))
.pipe(minifyHTML())
.pipe(gulp.dest('dest/'));
done();
});
gulp.task('img', function (done) {
return gulp.src('src/img/**/*')
.pipe(gulp.dest('dest/img/'));
done();
});
gulp.task('clean',function(done){
return gulp.src([
'dest',
'src/img/portfolios',
'src/img/creator',
'src/img/interviews',
'src/img/thumbnails',
]).pipe(clean());
console.log('Clean completed');
done();
});
gulp.task('build', gulp.series('cname','vendor', 'sass', 'ejs', 'img','js', function (done) {
// gulp.task('build', ['cname','vendor', 'sass', 'ejs', 'img','js', 'validator'], function () {
console.log('done');
done();
}));
gulp.task('watch', function(){
var changeHandler = function(event){
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
}
var taskSass = gulp.watch('src/sass/**/*.scss', gulp.task('sass'));
taskSass.on( 'change', changeHandler );
var taskEjs = gulp.watch('src/ejs/**/*.ejs', gulp.task('ejs'));
taskEjs.on( 'change', changeHandler );
var taskImg = gulp.watch('src/img/**/*', gulp.task('img'));
taskImg.on( 'change', changeHandler );
var taskJs = gulp.watch('src/js/**/*', gulp.task('js'));
taskJs.on( 'change', changeHandler );
});