-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
107 lines (98 loc) · 2.51 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
const fs = require('fs');
const fsp = fs.promises;
const path = require('path');
const gulp = require('gulp');
const gulpCleanCss = require('gulp-cleaner-css');
const gulpHtmlMinify = require('gulp-htmlmin');
const {pipeline} = require('readable-stream');
const {
addCspHashes,
compilePages,
buildSitemap,
getYouTubeData,
} = require('./gulp-helpers');
const {
SRC_DIR,
BUILD_DIR,
PROJECT_DIR,
YT_DATA_DIR, ASSET_DIR,
} = require('./gulp-helpers/consts');
const pagesPaths = path.join(SRC_DIR, 'templates', 'pages', '*.hbs');
function removeBuildDir() {
if (!fs.existsSync(BUILD_DIR)) {
return Promise.resolve();
}
return fsp.rm(BUILD_DIR, {recursive: true});
}
function fetchYouTubeData() {
return pipeline(
gulp.src(pagesPaths),
getYouTubeData,
gulp.dest(YT_DATA_DIR),
);
}
function buildPages() {
return pipeline(
gulp.src(pagesPaths),
compilePages,
gulpHtmlMinify({
minifyCSS: true,
minifyJS: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
}),
addCspHashes,
gulpHtmlMinify({
collapseWhitespace: true,
collapseBooleanAttributes: true,
removeAttributeQuotes: true,
removeOptionalTags: true,
sortAttributes: true,
sortClassName: true,
useShortDoctype: true,
}),
gulp.dest(BUILD_DIR),
);
}
async function buildCss() {
return pipeline(
gulp.src(path.join(ASSET_DIR, '**', '*.css')),
gulpCleanCss(),
gulp.dest(path.join(BUILD_DIR, 'assets')),
);
}
async function copyImages() {
return pipeline(
gulp.src([
path.join(ASSET_DIR, '*.png'),
path.join(ASSET_DIR, '*.jpg'),
path.join(YT_DATA_DIR, '*.png'),
path.join(YT_DATA_DIR, '*.jpg'),
]),
gulp.dest(path.join(BUILD_DIR, 'assets')),
);
}
function copyRootFiles() {
return pipeline(
gulp.src(path.join(PROJECT_DIR, 'src', 'root-files', '*')),
gulp.dest(BUILD_DIR),
);
}
const build = gulp.series(
removeBuildDir,
gulp.parallel(
buildCss,
copyImages,
copyRootFiles,
),
buildPages,
buildSitemap,
);
gulp.task('fetch-yt-data', fetchYouTubeData);
gulp.task('build', build);
gulp.task('default', gulp.series(
fetchYouTubeData,
build,
));