-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.babel.js
59 lines (47 loc) · 1.47 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
import fs from 'fs'
import gulp from 'gulp'
import eslint from 'gulp-eslint'
import jasmine from 'gulp-jasmine'
import rename from 'gulp-rename'
import replace from 'gulp-replace'
import merge from 'merge-stream'
gulp.task('test', ['lint', 'jasmine', 'maxSize'])
gulp.task('default', ['test'])
const MAX_BUILD_SIZE = 40960
gulp.task('lint', () => {
return gulp.src(['src/**/*.js', 'examples/src/**/*.js', 'test/**/*.js', 'gulpfile.babel.js', 'gulp/*.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
})
gulp.task('jasmine', () => {
return gulp.src('test/**/*.js')
.pipe(jasmine())
})
gulp.task('maxSize', done => {
fs.stat('dist/plait.min.js', (_, stats) => {
const kb = b => Math.floor(b / 1000)
if (stats.size > MAX_BUILD_SIZE) {
done(`plait.min.js is too big (${kb(stats.size)}K > ${kb(MAX_BUILD_SIZE)}K)!`)
}
done()
})
})
gulp.task('buildExamples', () => {
const streams = merge(copyExamples())
const examples = fs.readdirSync('examples/src').filter(f => fs.statSync(`examples/src/${f}`).isDirectory())
examples.forEach(example => {
streams.add(buildPage(example))
})
return streams
})
function copyExamples () {
return gulp.src(['examples/src/style.css'])
.pipe(gulp.dest('examples/dist'))
}
function buildPage (example) {
return gulp.src('examples/src/example.tmpl.html')
.pipe(replace('{{component}}', example))
.pipe(rename(`${example}.html`))
.pipe(gulp.dest('examples/dist'))
}