-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.babel.js
114 lines (100 loc) · 2.64 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
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
import fs from 'fs'
import path from 'path'
import gulp from 'gulp'
import gulplog from 'gulplog'
import gulpJsonlint from 'gulp-jsonlint'
import gulpRename from 'gulp-rename'
import gulpReplace from 'gulp-replace'
import gulpStandard from 'gulp-standard'
import gulpWatch from 'gulp-watch'
import { publish as ghPagesPublish } from 'gh-pages'
const paths = {
docs: 'docs',
json: [
'*.json',
'data/**/*.json',
'examples/**/*.json',
'fixtures/**/*.json'
],
scripts: ['*.js', 'examples/**/*.js', 'lib/**/*.js', 'test/**/*.js']
}
export const docVersion = () => {
const data = fs.readFileSync(path.resolve('package.json'))
const pkg = JSON.parse(data)
return gulp
.src(['.doc.index.html'])
.pipe(gulpReplace('--version--', pkg.version))
.pipe(gulpRename('index.html'))
.pipe(gulp.dest(`${paths.docs}/${pkg.name}`))
}
export const publishDocs = (done) => {
const publish = (docs, pkg, done) =>
ghPagesPublish(
docs,
{
repo: `[email protected]:${pkg.repository}.git`,
branch: 'gh-pages',
add: true,
clone: '.gh-pages',
depth: 2,
message: `Publish docs for v${pkg.version} [ci skip]`,
user: {
name: pkg.author.name,
email: pkg.author.email
}
},
done
)
fs.readFile(path.resolve('package.json'), (err, data) => {
if (err) {
done(err)
return
}
const pkg = JSON.parse(data)
const docs = path.resolve(paths.docs, pkg.name)
publish(docs, pkg, done)
})
}
export const standard = () =>
gulp
.src(paths.scripts)
.pipe(gulpStandard())
.pipe(
gulpStandard.reporter('default', {
breakOnError: true
})
)
export const jsonlint = () =>
gulp
.src(paths.json)
.pipe(gulpJsonlint())
.pipe(gulpJsonlint.failAfterError())
.pipe(gulpJsonlint.reporter())
export const watchScripts = () =>
gulp
.src(paths.scripts)
.pipe(
gulpWatch(paths.scripts, (vinyl) => {
if (vinyl.event === 'change') {
gulplog.info(`Linted ${vinyl.relative}`)
}
})
)
.pipe(gulpStandard())
.pipe(gulpStandard.reporter('default', {}))
export const watchJson = () =>
gulp
.src(paths.json)
.pipe(
gulpWatch(paths.json, (vinyl) => {
if (vinyl.event === 'change') {
gulplog.info(`Linted ${vinyl.relative}`)
}
})
)
.pipe(gulpJsonlint())
.pipe(gulpJsonlint.reporter())
export const lint = gulp.parallel(jsonlint, standard)
export const watch = gulp.parallel(watchJson, watchScripts)
export const docs = gulp.series(docVersion, publishDocs)
export default gulp.series(lint, watch)