-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
130 lines (120 loc) · 3.08 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
/* jshint esversion:8 */
const {
src,
dest,
parallel,
series
} = require('gulp');
const uglify = require('gulp-uglify');
const concat = require('gulp-concat');
const fileInclude = require('gulp-file-include');
const sriHash = require('gulp-sri-hash');
const htmlmin = require('gulp-html-minifier-terser');
const {
version,
appName,
description,
appUrl,
author
} = require('./package.json');
const sass = require('gulp-sass')(require('sass'));
const {
marked
} = require('marked');
const pages = require('./src/json/pages.json');
function licensePrep() {
const licenses = require('./thirdparty-licenses.json');
const array = [];
let counter = 0;
Object.keys(licenses).forEach(key => {
counter++;
const license = licenses[key];
array.push({
name: license.name,
version: license.version,
repo: license.repository,
license: (String(license.licenseFile).endsWith('LICENSE') || String(license.licenseFile).endsWith('LICENSE.md') || String(license.licenseFile).endsWith('LICENSE.txt')) ? license.licenseText : '',
counter
});
});
return array;
}
const licenses = licensePrep();
function sri() {
return src('dist/*.html', { encoding: false })
.pipe(sriHash({
algo: 'sha512',
relative: true
}))
.pipe(dest('dist/'));
}
function bundledJs() {
return src([
'./node_modules/bootstrap/dist/js/bootstrap.bundle.min.js',
'./node_modules/navigo/lib/navigo.min.js',
'./src/js/script.js'
], { encoding: false })
.pipe(concat(`main-${version}.min.js`))
.pipe(uglify())
.pipe(dest('dist/js/'));
}
function bundledCss() {
return src([
'./src/css/style.scss',
'./node_modules/bootstrap-icons/font/bootstrap-icons.scss',
'./node_modules/outdated-browser-rework/dist/style.css'
], { encoding: false })
.pipe(concat(`bundle-${version}.min.css`))
.pipe(sass.sync({
outputStyle: 'compressed'
}).on('error', sass.logError))
.pipe(dest('dist/css/'));
}
function copyImg() {
return src([
'./src/img/**/*'
], { encoding: false })
.pipe(dest('dist/img/'));
}
function copyIcons() {
return src('./node_modules/bootstrap-icons/font/fonts/*', { encoding: false })
.pipe(dest('dist/css/fonts/'));
}
function sitePages() {
return src('./src/html/*.html', { encoding: false })
.pipe(fileInclude({
prefix: '@@',
basepath: '@root',
context: {
version,
licenses,
appName,
description,
pages,
appUrl,
author
},
filters: {
markdown: marked.options({ mangle: false, headerIds: false, headerPrefix: false }).parse
}
}))
.pipe(htmlmin({
collapseWhitespace: true,
removeComments: true,
continueOnParseError: true
}))
.pipe(dest('dist/'));
}
function copyJson() {
return src('./src/json/*.json', { encoding: false })
.pipe(dest('dist/'));
}
function browserCompat() {
return src([
'./node_modules/outdated-browser-rework/dist/outdated-browser-rework.min.js',
'./src/js/browser-compat.js'
], { encoding: false })
.pipe(concat(`browser-compat-${version}.min.js`))
.pipe(dest('dist/js/'));
}
exports.default = parallel(series(parallel(bundledJs, bundledCss, sitePages, copyIcons, copyImg, copyJson, browserCompat), sri));