UNPKG

790 BJavaScriptView Raw
1const fs = require('fs');
2const gulp = require('gulp');
3const livereload = require('gulp-livereload');
4const opn = require('opn');
5const swaggerJSDoc = require('swagger-jsdoc');
6
7const swagger = require('./docs/swagger');
8const docsConfig = require('./docs/config');
9
10gulp.task('reload', () => {
11 livereload.reload();
12});
13
14gulp.task('docs:compile', () => {
15 const swaggerSpec = swaggerJSDoc(docsConfig);
16
17 fs.writeFileSync('./docs/api.json', JSON.stringify(swaggerSpec));
18});
19
20gulp.task('docs:watch', () => {
21 livereload.listen();
22
23 gulp.watch(docsConfig.apis, ['docs:compile', 'reload']);
24});
25
26gulp.task('docs:ui', () => {
27 swagger((config) => {
28 opn(`http://localhost:${config.port}?url=/docs/api.json`);
29 });
30});
31
32gulp.task('docs', ['docs:compile', 'docs:watch', 'docs:ui']);
33