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