forked from mate-academy/layout_miami
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
120 lines (101 loc) · 3.07 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
'use strict';
const gulp = require('gulp');
const autoprefixer = require('gulp-autoprefixer');
const clean = require('gulp-clean');
const browserSync = require('browser-sync');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const colors = require('colors');
const gulpReplacePath = require('gulp-replace-path');
const gulpStylelint = require('gulp-stylelint');
const gulpHtmllint = require('gulp-htmllint');
const gulpEslint = require('gulp-eslint');
const distDirectory = 'dist';
const htmlBlob = 'src/*.html';
const imagesBlob = 'src/images/**';
const fontsBlob = 'src/fonts/**';
const stylesBlob = 'src/styles/**';
const jsBlob = 'src/scripts/**';
const { series, parallel } = gulp;
gulp.task('cleanDist', function() {
return gulp.src(distDirectory, { read: false, allowEmpty: true })
.pipe(clean());
});
gulp.task('processHtml', function() {
return gulp.src(htmlBlob)
.pipe(gulpHtmllint({
config: './node_modules/@mate-academy/htmllint-config/.htmllintrc',
}, function(filepath, issues) {
issues.forEach(function(issue) {
const { line, column, code, msg } = issue;
console.log(
` ❌ ${colors.red('htmllint error')}
📁 file: ${filepath}
🖊️ [line: ${line}, column: ${column}]: (${code}) - ${msg}`);
});
}))
.pipe(gulp.dest(distDirectory));
});
gulp.task('processImages', function() {
return gulp.src(imagesBlob)
.pipe(gulp.dest(`${distDirectory}/images/`));
});
gulp.task('processFonts', function() {
return gulp.src(fontsBlob)
.pipe(gulp.dest(`${distDirectory}/fonts/`));
});
gulp.task('lintCss', function() {
return gulp
.src(stylesBlob)
.pipe(gulpStylelint({
failAfterError: false,
reporters: [
{ formatter: 'string', console: true },
],
debug: true,
}));
});
gulp.task('processStyles', series('lintCss', function() {
return gulp.src(stylesBlob)
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(gulpReplacePath(/(?:\.\.\/){2,}images/g, '../images'))
.pipe(autoprefixer())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(`${distDirectory}/styles`))
.pipe(browserSync.reload({ stream: true }));
}));
gulp.task('processJs', function() {
return gulp.src(jsBlob)
.pipe(gulpEslint())
.pipe(gulpEslint.format())
.pipe(gulp.dest(`${distDirectory}/scripts/`));
});
gulp.task('build', series(
'cleanDist',
parallel(
'processStyles',
'processHtml',
'processImages',
'processFonts',
'processJs',
)
));
gulp.task('serve', function() {
browserSync.init({
server: {
baseDir: distDirectory,
},
port: 8080,
});
gulp.watch(htmlBlob, series('processHtml'))
.on('change', browserSync.reload);
gulp.watch(imagesBlob, series('processImages'))
.on('change', browserSync.reload);
gulp.watch(fontsBlob, series('processFonts'))
.on('change', browserSync.reload);
gulp.watch(stylesBlob, series('processStyles'));
gulp.watch(jsBlob, series('processJs'))
.on('change', browserSync.reload);
});
gulp.task('default', series('build', 'serve'));