-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathgulpfile.babel.js
65 lines (57 loc) · 1.6 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
'use strict';
import path from 'path';
import gulp from 'gulp';
import through from 'through2';
import puppeteer from 'puppeteer';
import connect from 'gulp-connect';
import replace from 'gulp-replace';
const indexFilename = 'index.html';
const resumeFilename = 'resume.pdf';
const manifestFilename = 'manifest.json';
const buildPath = path.join(__dirname, 'build');
const htmlPath = path.join(buildPath, indexFilename);
const manifestPath = path.join(buildPath, manifestFilename);
const port = 8080;
gulp.task('replaceManifest', () =>
gulp
.src(manifestPath)
.pipe(replace(/%(REACT_APP_\w+)%/g, (_, key) => process.env[key]))
.pipe(gulp.dest(buildPath)),
);
gulp.task('captureResume', () =>
gulp
.src(htmlPath)
.pipe(through.obj(async function (file, enc, cb) {
const browser = await puppeteer.launch({
args: ['--font-render-hinting=none'],
});
const page = await browser.newPage();
await page.goto(`http://localhost:${port}/#/resume`, { waitUntil: 'networkidle2' });
const buffer = await page.pdf({ printBackground: true });
await browser.close();
file.contents = buffer;
file.path = file.path.replace(indexFilename, resumeFilename);
cb(null, file);
}))
.pipe(gulp.dest(buildPath)),
);
gulp.task('openServer', done => {
connect.server({
port,
root: buildPath,
});
done();
});
gulp.task('closeServer', done => {
connect.serverClose();
done();
});
gulp.task('buildResume', gulp.series(
'openServer',
'captureResume',
'closeServer',
));
gulp.task('default', gulp.parallel(
'replaceManifest',
'buildResume',
));