-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
100 lines (92 loc) · 2.86 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
const { watch, series, src, dest, task } = require('gulp')
const args = require('yargs').argv
const browserSync = require('browser-sync').create()
const xslt = require('gulp-xslt')
const rename = require('gulp-rename')
const sass = require('gulp-sass')
const gulpInject = require('gulp-inject')
const autoprefixer = require('gulp-autoprefixer')
const html2pdf = require('gulp-html2pdf'); // Requires wkhtmltopdf 0.12.5 (with patched qt)
const fileName = args.bsfile
function scss () {
return src('src/scss/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer())
.pipe(dest('build/'))
}
function inject () {
return src('src/base.xsl')
.pipe(gulpInject(src(['build/style.css']), {
starttag: '<!-- inject:{{path}} -->',
relative: true,
transform: (filePath, file) => {
return file.contents.toString('utf8')
}
}))
.pipe(gulpInject(src(['src/campaign.xsl']), {
starttag: '<!-- inject:{{path}} -->',
relative: true,
transform: (filePath, file) => {
return file.contents.toString('utf8')
}
}))
.pipe(gulpInject(src(['src/roster.xsl']), {
starttag: '<!-- inject:{{path}} -->',
relative: true,
transform: (filePath, file) => {
return file.contents.toString('utf8')
}
}))
.pipe(gulpInject(src(['src/card.xsl']), {
starttag: '<!-- inject:{{path}} -->',
relative: true,
transform: (filePath, file) => {
return file.contents.toString('utf8')
}
}))
.pipe(dest('build/'))
}
function transform () {
return src('data/*.ros')
.pipe(xslt('build/base.xsl', {}))
.pipe(dest('build/'))
}
function htmlRename () {
return src('build/*.ros')
.pipe(rename((path) => {
path.dirname += '/build'
path.extname = '.html'
}))
.pipe(dest('./'))
}
function copyResult () {
return src('build/base.xsl')
.pipe(rename('stylesheet.xsl'))
.pipe(dest('dist'))
}
function pdf () {
const options = {
printMediaType: true,
disableSmartShrinking: true
}
return src('build/*.html')
.pipe(html2pdf(options))
.pipe(dest('demo'))
}
exports.default = () => {
browserSync.init({
server: {
baseDir: './build',
index: `${fileName}.html`
},
reloadDelay: 2000
})
watch(['src/scss/*.scss', 'src/*.xsl'], series(scss, inject, transform, htmlRename, copyResult))
watch('build/*.html').on('change', browserSync.reload)
}
exports.scss = scss
exports.inject = inject
exports.transform = transform
exports.rename = htmlRename
exports.pdf = pdf
exports.build = series(scss, inject, transform, htmlRename, copyResult)