forked from SymbiFlow/symbiflow-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
151 lines (135 loc) · 3.69 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
const gulp = require('gulp'),
sass = require('gulp-sass'),
prefix = require('gulp-autoprefixer'),
babel = require('gulp-babel'),
uglify = require('gulp-uglify'),
hb = require('gulp-handlebars-all'),
imagemin = require('gulp-imagemin'),
newer = require('gulp-newer'),
rename = require('gulp-rename'),
markdown = require('gulp-markdown'),
inject = require('gulp-inject-string'),
browsersync = require('browser-sync').create()
const helpers = require('handlebars-helpers')();
function browserSync(done) {
browsersync.init({
server: {
baseDir: './build/'
},
port: 3000
})
done()
}
function md() {
return gulp.src('./source/md/**/*.md')
.pipe(markdown())
.pipe(inject.prepend(`
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>SymbiFlow - the GCC of FPGAs</title>
<link rel="stylesheet" href="assets/css/main.css">
</head>
<body class="article">
`))
.pipe(inject.append(`
</body>
</html>
`))
.pipe(gulp.dest('./build'))
.pipe(browsersync.stream())
}
function images() {
return gulp
.src('./source/assets/img/**/*')
.pipe(newer('./build/assets/img'))
.pipe(
imagemin([
imagemin.gifsicle({
interlaced: true
}),
imagemin.jpegtran({
progressive: true
}),
imagemin.optipng({
optimizationLevel: 5
}),
imagemin.svgo({
plugins: [{
removeViewBox: false,
collapseGroups: true
}]
})
])
)
.pipe(gulp.dest('./build/assets/img'))
}
function imagesMove() {
return gulp
.src('./source/assets/img/**/*')
.pipe(newer('./build/assets/img'))
.pipe(gulp.dest('./build/assets/img'))
.pipe(browsersync.stream())
}
function scss() {
return gulp
.src('./source/assets/scss/*.scss')
.pipe(sass({
outputStyle: 'compressed'
}))
.pipe(prefix())
.pipe(gulp.dest('./build/assets/css/'))
.pipe(browsersync.stream())
}
function css() {
return gulp
.src('./source/assets/css/*.css')
.pipe(gulp.dest('./build/assets/css/'))
}
function scripts() {
return gulp
.src('./source/assets/js/**/*.js')
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(uglify())
.pipe(gulp.dest('./build/assets/js/'))
.pipe(browsersync.stream());
}
function handlebars() {
delete require.cache[require.resolve('./source/assets/data/data.json')]
return gulp
.src('./source/*.hbs')
.pipe(hb('html', {
context: require('./source/assets/data/data.json')
}))
.pipe(rename(path => path.extname = '.html'))
.pipe(gulp.dest('./build'))
.pipe(browsersync.stream());
}
function watchFiles() {
gulp.watch('./source/assets/fonts/**/*', fonts)
gulp.watch('./source/assets/scss/**/*', scss)
gulp.watch('./source/assets/css/**/*', css)
gulp.watch('./source/assets/js/**/*', scripts)
gulp.watch(['./source/*.hbs', './source/assets/data/data.json'], handlebars)
gulp.watch('./source/assets/img/**/*', images)
gulp.watch('./source/md/**/*.md', md)
}
function fonts() {
return gulp
.src('./source/assets/fonts/**/*')
.pipe(gulp.dest('./build/assets/fonts'))
}
const build = gulp.parallel(scss, css, scripts, images, fonts, handlebars, md, () => {
return gulp
.src('./source/**/*.html')
.pipe(gulp.dest('./build'))
}),
watch = gulp.series(gulp.parallel(scss, css, scripts, imagesMove, fonts, handlebars), gulp.parallel(watchFiles, browserSync))
exports.build = build
exports.watch = watch
exports.markdown = md