-
Notifications
You must be signed in to change notification settings - Fork 16
/
gulpfile.js
101 lines (87 loc) · 2.47 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
'use strict'
const gulp = require('gulp')
const pug = require('gulp-pug')
const args = require('yargs').argv
const Parcel = require('parcel-bundler')
const browserify = require('browserify')
const source = require('vinyl-source-stream')
const through = require('through2')
const beautify = require('js-beautify')
const size = require('gulp-size')
function onError(err) {
if (err.annotated) {
console.log(err.annotated)
} else if (err.message) {
console.log(err.message)
} else {
console.log(err)
}
return this.emit('end')
}
function beautifyHtml(opts = {}) {
function modifyFile(file, enc, cb) {
if (file.isNull()) return cb(null, file) // pass along
if (file.isStream()) {
return cb(new Error(`gulp-beautify: Streaming not supported`))
}
var str = file.contents.toString(`utf8`)
file.contents = new Buffer.from(beautify.html(str, opts))
cb(null, file)
}
return through.obj(modifyFile)
}
const libMin = `dist/vh-check.min.js`
const sOpts = { name: `regular`, showFiles: true }
const libSizeMin = () => gulp.src(libMin).pipe(size(sOpts))
const libSizeGzip = () => gulp.src(libMin).pipe(size({ ...sOpts, gzip: true }))
const libSize = gulp.series(libSizeMin, libSizeGzip)
const isGhRelease = args[`gh-release`] === true
const DEMO = `dist-demo`
console.log(`building for ${isGhRelease ? 'GITHUB' : 'local demo'}`)
const html = () => {
return gulp
.src([`src-demo/*.pug`, `!src-demo/_*.pug`])
.pipe(
pug({
locals: {
root: isGhRelease ? `https://hiswe.github.io/vh-check` : ``,
},
})
)
.pipe(beautifyHtml({ indent_size: 2 }))
.pipe(gulp.dest(DEMO))
}
const css = () => {
return gulp.src([`src-demo/*.css`]).pipe(gulp.dest(DEMO))
}
const jsRuler = () => {
return gulp.src([`src-demo/ruler.js`]).pipe(gulp.dest(DEMO))
}
function jsCommonJs() {
return browserify({
cache: {},
packageCache: {},
debug: false,
entries: ['./src-demo/commonjs-example.js'],
})
.bundle()
.on('error', onError)
.pipe(source('commonjs-bundle.js'))
.pipe(gulp.dest(DEMO))
}
function jsEsModule() {
const entryFiles = [
`./src-demo/esmodule-example.js`,
`./src-demo/redefine-vh.js`,
]
const bundler = new Parcel(entryFiles, {
outDir: `./${DEMO}`,
watch: false,
minify: false,
sourceMaps: false,
})
return bundler.bundle()
}
const js = gulp.parallel(jsRuler, jsEsModule, jsCommonJs)
exports.demo = gulp.parallel(html, css, js)
gulp.task(`size`, libSize)