-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
49 lines (42 loc) · 1.41 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
const gulp = require('gulp');
const doctoc = require('doctoc/lib/transform');
const del = require('del');
const $ = require('gulp-load-plugins')();
const reactDocsPlugin = require('../');
const { exec } = require('child_process');
// Helper vars
var docsDest = 'docs';
// Tasks
gulp.task('clean', function (cb) {
del.sync(docsDest);
cb();
});
gulp.task('check:docs', function (cb) {
exec('git diff --name-only docs/', function (err, diffFiles) {
if (diffFiles.indexOf('.md') > -1) {
console.log('Automatically generated documentation is not up to \
date with the changes in the codebase. Please run `gulp` and commit the changes.');
process.exit(1);
} else {
console.log('Automatically generated documentation is up to date!');
}
cb();
});
});
gulp.task('react-docs', function () {
var mdTitle = '# React Component Reference';
return gulp.src('./components/**/*.jsx')
.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 = Buffer.from(mdWithToc);
}))
.pipe(gulp.dest(docsDest));
});
gulp.task('default', gulp.series('react-docs'));