-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
132 lines (116 loc) · 3.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
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
const gulp = require('gulp');
const pug = require('gulp-pug');
const sass = require('gulp-sass');
const imagemin = require('gulp-imagemin');
const cleanCSS = require('gulp-clean-css');
const autoprefixer = require('gulp-autoprefixer');
const browserSync = require('browser-sync').create();
const data = require('gulp-data');
const fs = require('fs');
var argv = require('yargs').argv;
const paths = {
docs: './docs/',
dist: {
all: './dist/',
html: 'dist/*.html'
},
pug: {
pages: 'src/pages/*.pug',
pdf : 'src/pdf/*.pug',
all: 'src/**/*.pug'
},
scss: {
pages: 'src/assets/styles/main-pages.scss',
pdf: 'src/assets/styles/main-pdf.scss',
all: 'src/assets/styles/*.scss'
},
data: 'src/assets/data/data.json',
img: 'src/assets/img/*',
export: 'export/GaborKevinBartaCV.pdf'
}
const pugPrettyOptions = {
doctype: 'html',
pretty: true
}
const pugMinifiedOptions = {
doctype: 'html',
pretty: false
}
const browserSyncOptions = {
server: {
baseDir: paths.dist.all,
},
notify: false
}
function injectJson() {
return JSON.parse(fs.readFileSync(paths.data))
}
var pugSource = (argv.pug == undefined) ? null : argv.pug;
gulp.task('pages-build', function () {
return gulp.src(paths.pug.pages)
.pipe(data(injectJson()))
.pipe(pug(pugMinifiedOptions))
.pipe(gulp.dest(paths.docs));
});
gulp.task('pug', function () {
return gulp.src(paths.pug[pugSource])
.pipe(data(injectJson()))
.pipe(pug(pugPrettyOptions))
.pipe(gulp.dest(paths.dist.all))
.pipe(browserSync.stream());
});
gulp.task('sass', function () {
return gulp.src(paths.scss[pugSource])
.pipe(sass())
.pipe(gulp.dest(paths.dist.all))
.pipe(browserSync.stream());
});
gulp.task('image-min', () =>
gulp.src(paths.img)
.pipe(imagemin())
.pipe(gulp.dest(paths.dist.all))
.pipe(browserSync.stream())
);
gulp.task('image-min-build', () =>
gulp.src(paths.img)
.pipe(imagemin())
.pipe(gulp.dest(paths.docs))
);
gulp.task('move-export-pdf', () =>
gulp.src(paths.export)
.pipe(gulp.dest(paths.docs))
);
gulp.task('sass-build', function () {
return gulp.src(paths.scss.pages)
.pipe(sass())
.pipe(autoprefixer({
overrideBrowserslist: ['last 99 versions'],
cascade: false
}))
.pipe(cleanCSS())
.pipe(gulp.dest(paths.docs))
});
gulp.task('browser-sync', function () {
browserSync.init(browserSyncOptions);
gulp.watch(paths.scss.all, gulp.series('sass'));
gulp.watch(paths.data, gulp.series('pug'));
gulp.watch(paths.pug.all, gulp.series('pug'));
gulp.watch(paths.dist.html).on('change', browserSync.reload);
});
gulp.task('build', gulp.series('pages-build', 'sass-build', 'image-min-build', 'move-export-pdf'));
gulp.task('serve', gulp.series('pug', 'sass', 'image-min', 'browser-sync'));
gulp.task('pdf-puppeteer', async function(){
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto('http://localhost:3000', { waitUntil: 'networkidle2'})
await page.pdf(
{
path: 'export/GaborKevinBartaCV.pdf',
format: 'A4'
}
)
await browser.close()
})()
});