-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
97 lines (84 loc) · 2.41 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
const {writeFileSync} = require('fs');
const gulp = require('gulp');
const sass = require('gulp-sass')(require('sass'));
const del = require('del');
const rev = require('gulp-rev');
const revReplace = require('gulp-rev-css-url');
const tildeImporter = require('node-sass-tilde-importer');
const paths = {
styles: {
src: [
'src/scss/**/*.scss',
'node_modules/swagger-ui-dist/swagger-ui.css'
],
dest: 'static/css',
},
images: {
src: 'src/img/**/*',
dest: 'static/img',
},
fonts: {
src: [
'node_modules/et-line/fonts/**/*',
'node_modules/@fortawesome/fontawesome-free-webfonts/webfonts/**/*'
],
dest: 'static/fonts',
},
scripts: {
src: [
'node_modules/swagger-ui-dist/swagger-ui-bundle.*',
'node_modules/swagger-ui-dist/swagger-ui-standalone-preset.*',
],
dest: 'static/js'
},
watch: {
src: 'src/**/*'
}
};
const buildStyles = () => gulp
.src(paths.styles.src)
.pipe(sass({ outputStyle : 'compressed', importer: tildeImporter }))
.pipe(gulp.dest(paths.styles.dest));
const copyImages = () => gulp
.src(paths.images.src)
.pipe(gulp.dest(paths.images.dest));
const copyFonts = () => gulp
.src(paths.fonts.src)
.pipe(gulp.dest(paths.fonts.dest));
const copyScripts = () => gulp
.src(paths.scripts.src)
.pipe(gulp.dest(paths.scripts.dest));
const clean = () => del([paths.styles.dest, paths.images.dest, paths.scripts.dest]);
const revision = () => gulp
.src([
'static/**/*.*',
`!static/**/*-${'[0-9a-f]'.repeat(10)}.*`,
'!static/__build-time'
])
.pipe(rev())
.pipe(revReplace())
.pipe(gulp.dest('static'))
.pipe(rev.manifest('assets.json'))
.pipe(gulp.dest('data'));
const watch = () => gulp.watch(
paths.watch.src,
{ ignoreInitial: false },
build
).on('error', () => {});
gulp.task('revision', revision);
gulp.task('scss', buildStyles);
gulp.task('images', copyImages);
gulp.task('fonts', copyFonts);
gulp.task('scripts', copyScripts);
gulp.task('clean', clean);
gulp.task('write-build-time', function (cb) {
// wait one sec to give hugo some time to react on changes.
setTimeout(() => {
writeFileSync('./static/__build-time', (new Date).toISOString());
cb();
}, 500);
});
const build = gulp.series('clean', gulp.parallel('scss', 'images', 'fonts', 'scripts'), 'revision', 'write-build-time');
gulp.task('build', build);
gulp.task('default', build);
gulp.task('watch', watch);