-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
88 lines (70 loc) · 1.87 KB
/
gulpfile.babel.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
import del from 'del'
import fs from 'fs'
import gulp from 'gulp'
import mergeJSON from 'gulp-merge-json'
import mocha from 'gulp-mocha'
import pug from 'gulp-pug'
import gulpSass from 'gulp-sass'
import moment from 'moment'
import dartSass from 'dart-sass'
const sass = gulpSass(dartSass)
// helper functions
function addDate(jsonContent) {
jsonContent.lastUpdatedDate = moment().format('MMMM Do YYYY')
jsonContent.lastUpdatedYear = moment().format('YYYY')
jsonContent.lastUpdatedTimestamp = moment().format()
return jsonContent
}
function getContent() {
let content = fs.readFileSync('./dist/resume.json', { encoding: 'utf8' })
if(!content) {
throw new Error('Could not read resume.json!')
}
content = JSON.parse(content)
if(!content) {
throw new Error('resume.json is not valid JSON!')
}
content = addDate(content)
return content
}
// tasks
export const content = () => {
const stream = gulp.src('src/content/*.json')
.pipe(mergeJSON({
fileName: 'resume.json',
}))
.pipe(gulp.dest('./dist'))
return stream
}
export const html = gulp.series(
content,
() => {
const stream = gulp.src('src/templates/*.pug')
.pipe(pug({
pretty: ' ',
locals: getContent(),
}))
.pipe(gulp.dest('./dist'))
return stream
}
)
export const css = () => {
const stream = gulp.src('src/scss/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./dist'))
return stream
}
export const build = gulp.series(html, css)
export const clean = () => (
del(['dist', '.publish'])
)
export const test = gulp.series(
build,
() => {
const stream = gulp.src('test/specs/*.js', {read: false})
.pipe(mocha({reporter: 'nyan'}))
return stream
}
)
export const watch = () => gulp.watch('src/**/*.*', ['build', 'test'])
export default build