blob: e5e7bf74b5d5a53a225561f1e3ef6525ce88d929 [file] [log] [blame]
Matteo Scandolo686547a2017-08-08 13:05:25 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
Matteo Scandoloa5d03d52016-07-21 11:35:46 -070019/*eslint-env node */
20
21const gulp = require('gulp');
22const gulpDocs = require('gulp-ngdocs');
23const del = require('del');
24const browserSync = require('browser-sync').create();
25
26module.exports = function(options){
27
28 gulp.task('cleanDocs', function(){
29 return del([options.docs + '**/*']);
30 });
31
32 gulp.task('makeDocs', ['cleanDocs'], function(){
33
34 const ngOptions = {
35 scripts: [].concat([
36 `./${options.ngXosVendor}ngXosVendor.min.js`,
37 `./${options.ngXosVendor}ngXosHelpers.min.js`,
Matteo Scandolo1516f882016-08-08 16:51:55 -070038 '../bower_components/angular-mocks/angular-mocks.js'
Matteo Scandoloa5d03d52016-07-21 11:35:46 -070039 ]),
40 styles: [
41 `./${options.ngXosStyles}xosNgLib.css`,
42 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css',
43 ],
44 html5Mode: false,
45 title: 'XOS Helpers documentation',
46 startPage: '/ngXosLib',
47 }
48
49 return gulpDocs.sections({
50 ngXosLib: {
51 glob: [
52 options.xosHelperSource + '*.js',
53 options.xosHelperSource + 'services/helpers/**/*.js',
54 options.xosHelperSource + 'services/*.js',
55 options.xosHelperSource + 'ui_components/**/*.js'
56 ],
57 title: 'Module Documentation',
58 },
59 'rest-api': {
60 glob: [
61 options.xosHelperSource + 'services/rest/*.js'
62 ],
63 api: true,
64 title: 'API Documentation',
65 }
66 }).pipe(gulpDocs.process(ngOptions)).pipe(gulp.dest('./docs'));
67 });
68
69 gulp.task('serveDocs', function(){
70 browserSync.init({
71 server: {
72 baseDir: './docs',
Matteo Scandolo1516f882016-08-08 16:51:55 -070073 routes: {
74 '/bower_components': 'bower_components'
75 }
Matteo Scandoloa5d03d52016-07-21 11:35:46 -070076 }
77 });
78 });
79
80 gulp.task('docs', ['makeDocs', 'serveDocs'], function(){
81
82 const files = [
83 options.xosHelperSource + '**/*.js',
84 ];
85
86 gulp.watch(files, ['makeDocs']);
87
88 // uncomment to enable autoreload, now it is broken (reload a wrong page)
89 // https://github.com/nikhilmodak/gulp-ngdocs/issues/81
90
91 // gulp.watch(files, function(){
92 // browserSync.reload();
93 // });
94 });
95};