Matteo Scandolo | a5d03d5 | 2016-07-21 11:35:46 -0700 | [diff] [blame] | 1 | /*eslint-env node */ |
| 2 | |
| 3 | const gulp = require('gulp'); |
| 4 | const gulpDocs = require('gulp-ngdocs'); |
| 5 | const del = require('del'); |
| 6 | const browserSync = require('browser-sync').create(); |
| 7 | |
| 8 | module.exports = function(options){ |
| 9 | |
| 10 | gulp.task('cleanDocs', function(){ |
| 11 | return del([options.docs + '**/*']); |
| 12 | }); |
| 13 | |
| 14 | gulp.task('makeDocs', ['cleanDocs'], function(){ |
| 15 | |
| 16 | const ngOptions = { |
| 17 | scripts: [].concat([ |
| 18 | `./${options.ngXosVendor}ngXosVendor.min.js`, |
| 19 | `./${options.ngXosVendor}ngXosHelpers.min.js`, |
| 20 | 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular-mocks.js', |
| 21 | ]), |
| 22 | styles: [ |
| 23 | `./${options.ngXosStyles}xosNgLib.css`, |
| 24 | 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css', |
| 25 | ], |
| 26 | html5Mode: false, |
| 27 | title: 'XOS Helpers documentation', |
| 28 | startPage: '/ngXosLib', |
| 29 | } |
| 30 | |
| 31 | return gulpDocs.sections({ |
| 32 | ngXosLib: { |
| 33 | glob: [ |
| 34 | options.xosHelperSource + '*.js', |
| 35 | options.xosHelperSource + 'services/helpers/**/*.js', |
| 36 | options.xosHelperSource + 'services/*.js', |
| 37 | options.xosHelperSource + 'ui_components/**/*.js' |
| 38 | ], |
| 39 | title: 'Module Documentation', |
| 40 | }, |
| 41 | 'rest-api': { |
| 42 | glob: [ |
| 43 | options.xosHelperSource + 'services/rest/*.js' |
| 44 | ], |
| 45 | api: true, |
| 46 | title: 'API Documentation', |
| 47 | } |
| 48 | }).pipe(gulpDocs.process(ngOptions)).pipe(gulp.dest('./docs')); |
| 49 | }); |
| 50 | |
| 51 | gulp.task('serveDocs', function(){ |
| 52 | browserSync.init({ |
| 53 | server: { |
| 54 | baseDir: './docs', |
| 55 | } |
| 56 | }); |
| 57 | }); |
| 58 | |
| 59 | gulp.task('docs', ['makeDocs', 'serveDocs'], function(){ |
| 60 | |
| 61 | const files = [ |
| 62 | options.xosHelperSource + '**/*.js', |
| 63 | ]; |
| 64 | |
| 65 | gulp.watch(files, ['makeDocs']); |
| 66 | |
| 67 | // uncomment to enable autoreload, now it is broken (reload a wrong page) |
| 68 | // https://github.com/nikhilmodak/gulp-ngdocs/issues/81 |
| 69 | |
| 70 | // gulp.watch(files, function(){ |
| 71 | // browserSync.reload(); |
| 72 | // }); |
| 73 | }); |
| 74 | }; |