-
Notifications
You must be signed in to change notification settings - Fork 13
/
gulpfile.js
119 lines (106 loc) · 2.68 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
const fs = require('fs');
const gulp = require('gulp');
const postcss = require('gulp-postcss');
const handlebars = require('gulp-compile-handlebars');
const rename = require('gulp-rename');
const webserver = require('gulp-webserver');
const del = require('del');
// Get file and directory names for build
const {
VIEWS_DIR,
PARTIALS_DIR,
STYLES_DIR,
OUTPUT_DIR,
TEMPLATE_FILENAME,
HTML_FILENAME,
CSS_FILENAME,
RESUME_PATH,
FALLBACK_RESUME_PATH,
helpers
} = require('./build-config');
/**
* Build the CSS file for the resume using TailwindCSS through PostCSS
*/
function css() {
return gulp
.src(`${STYLES_DIR}/${CSS_FILENAME}`)
.pipe(postcss())
.pipe(gulp.dest(OUTPUT_DIR));
}
/**
* Build the CSS file for checking in repository and saving as
*/
function cssExport() {
return gulp
.src(`${STYLES_DIR}/${CSS_FILENAME}`)
.pipe(postcss())
.pipe(gulp.dest(__dirname));
}
/**
* Build the HTML from the resume file (either resume.json provided or a
* default) and from the templates in views folder
*/
function html() {
const jsonResume = fs.existsSync(RESUME_PATH)
? fs.readFileSync(RESUME_PATH, 'utf-8')
: fs.readFileSync(FALLBACK_RESUME_PATH, 'utf-8');
const resume = JSON.parse(jsonResume);
const options = {
ignorePartials: false,
partials: {},
batch: [PARTIALS_DIR],
helpers: helpers
};
return gulp
.src(`${VIEWS_DIR}/${TEMPLATE_FILENAME}`)
.pipe(handlebars({ resume, stylesheet: `/${CSS_FILENAME}` }, options))
.pipe(rename(HTML_FILENAME))
.pipe(gulp.dest(OUTPUT_DIR));
}
/**
* Run HTML and CSS tasks
*/
const build = gulp.series(css, html);
/**
* Clean output directory
*/
function clean() {
return del(`${OUTPUT_DIR}/*`);
}
/**
* Watch for changes in templates, css and resume for interactive development
*/
function watch() {
const TEMPLATES_GLOB = `${VIEWS_DIR}/**/*.hbs`;
const STYLES_GLOB = `${STYLES_DIR}/*.css`;
/**
* HTML task watches for changes in templates and in resume file
*/
gulp.watch([TEMPLATES_GLOB, RESUME_PATH, FALLBACK_RESUME_PATH], html);
/**
* CSS task needs to watch both styles and templates for tailwind to find
* used class names
*/
gulp.watch([TEMPLATES_GLOB, STYLES_GLOB], css);
}
/**
* Serve the output directory containing HTML and CSS for interactive
* development
*/
function server() {
return gulp.src(OUTPUT_DIR).pipe(
webserver({
port: 6660,
open: true
})
);
}
/**
* Run the whole build process and keep watching for changes and serving
* the output folder for a convenient development experience
*/
const dev = gulp.series(clean, build, gulp.parallel(server, watch));
module.exports = {
cssExport,
default: dev
};