-
Notifications
You must be signed in to change notification settings - Fork 403
/
gulpfile.js
49 lines (42 loc) · 1.52 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
'use strict';
// Required modules
var gulp = require('gulp'),
path = require('path'),
_ = require('lodash'),
doctoc = require('doctoc/lib/transform'),
del = require('del'),
$ = require('gulp-load-plugins')(),
log = require('fancy-log'),
reactDocsPlugin = require('gulp-react-docs'),
child_process = require('child_process');
// Helper vars
var docsDest = 'docs';
// Tasks
gulp.task('react-docs', function() {
var mdTitle = '# React Component Reference';
return gulp.src('./src/**/*.js')
.pipe(reactDocsPlugin({
path: docsDest
}))
.pipe($.concat('README.md'))
.pipe($.tap(function(file) {
// Generate table of contents for components.md
var mdWithToc = doctoc(file.contents.toString(), null, 2, mdTitle).data;
file.contents = new Buffer(mdWithToc);
}))
.pipe(gulp.dest(docsDest));
});
gulp.task('default', gulp.series('react-docs'));
gulp.task('clean', function(cb) { del(docsDest, cb) });
gulp.task('check:docs', gulp.series('react-docs', function(cb) {
child_process.exec('git diff --name-only docs/', function(err, diffFiles) {
if (diffFiles.indexOf('.md') > -1) {
log('Automatically generated documentation is not up to \
date with the changes in the codebase. Please run `gulp` and commit the changes.');
cb(new Error('Docs not up to date!'));
} else {
log('Automatically generated documentation is up to date!');
}
cb();
});
}));