blob: 03c2e407c8b40bf9c4e13afa772e89629fbbfcde [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -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 Scandolo2b626742015-11-04 16:03:59 +010019var gulp = require('gulp');
20var uglify = require('gulp-uglify');
Matteo Scandolo57404dc2016-04-13 16:20:13 -070021var concat = require('gulp-concat');
Matteo Scandolo2b626742015-11-04 16:03:59 +010022var ngAnnotate = require('gulp-ng-annotate');
23var angularFilesort = require('gulp-angular-filesort');
Matteo Scandolo57404dc2016-04-13 16:20:13 -070024var gulpDocs = require('gulp-ngdocs');
Matteo Scandolo582cc812016-04-13 17:23:28 -070025var del = require('del');
Matteo Scandolob7a86dc2016-04-14 11:46:30 -070026var babel = require('gulp-babel');
27const sourcemaps = require('gulp-sourcemaps');
Matteo Scandoloaa683dd2016-04-14 15:34:12 -070028var browserSync = require('browser-sync').create();
Matteo Scandolo90ed0642016-04-25 10:11:56 -070029var rename = require('gulp-rename');
30var sass = require('gulp-sass');
Matteo Scandolo2b626742015-11-04 16:03:59 +010031
32module.exports = function(options){
Matteo Scandolob7a86dc2016-04-14 11:46:30 -070033
Matteo Scandolo90ed0642016-04-25 10:11:56 -070034 gulp.task('style', function(){
Matteo Scandolob0280752016-04-25 10:31:22 -070035 return gulp.src(`${options.xosHelperSource}styles/main.scss`)
Matteo Scandolo90ed0642016-04-25 10:11:56 -070036 .pipe(sourcemaps.init())
37 .pipe(sass().on('error', sass.logError))
38 .pipe(rename('xosNgLib.css'))
39 .pipe(sourcemaps.write())
40 .pipe(gulp.dest(options.ngXosStyles));
41 });
42
Matteo Scandolob7a86dc2016-04-14 11:46:30 -070043 // transpile js with sourceMaps
44 gulp.task('babel', function(){
45 return gulp.src(options.xosHelperSource + '**/*.js')
46 .pipe(babel({
47 presets: ['es2015']
48 }))
49 .pipe(gulp.dest(options.xosHelperTmp));
50 });
51
52 gulp.task('babelDev', function(){
53 return gulp.src(options.xosHelperSource + '**/*.js')
54 .pipe(sourcemaps.init())
55 .pipe(babel({
56 presets: ['es2015']
57 }))
58 .pipe(sourcemaps.write('./maps'))
59 .pipe(gulp.dest(options.xosHelperTmp));
60 });
61
62 // build
Matteo Scandolo90ed0642016-04-25 10:11:56 -070063 gulp.task('helpers', ['babel', 'style'], function(){
Matteo Scandolob7a86dc2016-04-14 11:46:30 -070064 return gulp.src([options.xosHelperTmp + '**/*.js'])
Matteo Scandolo2b626742015-11-04 16:03:59 +010065 .pipe(angularFilesort())
66 .pipe(concat('ngXosHelpers.js'))
67 .pipe(ngAnnotate())
68 .pipe(uglify())
69 .pipe(gulp.dest(options.ngXosVendor));
70 });
Matteo Scandolo57404dc2016-04-13 16:20:13 -070071
Matteo Scandolob7a86dc2016-04-14 11:46:30 -070072 // build Dev (no minify, sourcemaps)
73 gulp.task('helpersDev', ['babelDev'], function(){
74 return gulp.src([options.xosHelperTmp + '**/*.js'])
75 .pipe(angularFilesort())
76 .pipe(concat('ngXosHelpers.js'))
77 .pipe(ngAnnotate())
78 .pipe(gulp.dest(options.ngXosVendor));
79 });
80
Matteo Scandolo582cc812016-04-13 17:23:28 -070081 gulp.task('cleanDocs', function(){
Matteo Scandolo582cc812016-04-13 17:23:28 -070082 return del([options.docs + '**/*']);
83 });
84
Matteo Scandoloaa683dd2016-04-14 15:34:12 -070085 gulp.task('makeDocs', ['cleanDocs'], function(){
Matteo Scandolo68df51b2016-05-03 17:07:01 -070086
Matteo Scandolo582cc812016-04-13 17:23:28 -070087 var ngOptions = {
Matteo Scandolo68df51b2016-05-03 17:07:01 -070088 scripts: [].concat([
Matteo Scandolo68df51b2016-05-03 17:07:01 -070089 `./${options.ngXosVendor}ngXosVendor.js`,
Matteo Scandolo88e18462016-04-25 14:24:18 -070090 `./${options.ngXosVendor}ngXosHelpers.js`,
arpiagariu98680a52016-06-14 14:08:45 -070091 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular-mocks.js',
Matteo Scandolo68df51b2016-05-03 17:07:01 -070092 ]),
Matteo Scandoloaa683dd2016-04-14 15:34:12 -070093 styles: [
Matteo Scandolo88e18462016-04-25 14:24:18 -070094 `./${options.ngXosStyles}xosNgLib.css`,
Matteo Scandolo199ec002016-04-22 10:53:49 -070095 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css',
Matteo Scandolo582cc812016-04-13 17:23:28 -070096 ],
Matteo Scandoloa6a9e612016-04-14 16:52:13 -070097 html5Mode: false,
Matteo Scandolo582cc812016-04-13 17:23:28 -070098 title: 'XOS Helpers documentation',
Matteo Scandolo0ae5d352016-07-15 17:04:14 -070099 startPage: '/ngXosLib',
Matteo Scandolo582cc812016-04-13 17:23:28 -0700100 }
101
102 return gulpDocs.sections({
Matteo Scandolo0ae5d352016-07-15 17:04:14 -0700103 ngXosLib: {
Matteo Scandolo582cc812016-04-13 17:23:28 -0700104 glob: [
105 options.xosHelperSource + '*.js',
Matteo Scandolo974c0e42016-05-25 16:02:16 -0700106 options.xosHelperSource + 'services/helpers/**/*.js',
Matteo Scandoloaa683dd2016-04-14 15:34:12 -0700107 options.xosHelperSource + 'services/*.js',
108 options.xosHelperSource + 'ui_components/**/*.js'
Matteo Scandolo582cc812016-04-13 17:23:28 -0700109 ],
110 title: 'Module Documentation',
111 },
112 'rest-api': {
113 glob: [
114 options.xosHelperSource + 'services/rest/*.js'
115 ],
116 api: true,
117 title: 'API Documentation',
118 }
119 }).pipe(gulpDocs.process(ngOptions)).pipe(gulp.dest('./docs'));
Matteo Scandolo57404dc2016-04-13 16:20:13 -0700120 });
Matteo Scandolob7a86dc2016-04-14 11:46:30 -0700121
Matteo Scandoloaa683dd2016-04-14 15:34:12 -0700122 gulp.task('serveDocs', function(){
123 browserSync.init({
124 server: {
125 baseDir: './docs',
126 routes: {
Matteo Scandolo88e18462016-04-25 14:24:18 -0700127 '/xos/core/xoslib/static/js/vendor': options.ngXosVendor,
arpiagariu98680a52016-06-14 14:08:45 -0700128 '/xos/core/static': options.ngXosStyles,
Matteo Scandoloaa683dd2016-04-14 15:34:12 -0700129 }
130 }
131 });
132 });
133
134 gulp.task('docs', ['makeDocs', 'serveDocs'], function(){
135
136 var files = [
Matteo Scandolo0ae5d352016-07-15 17:04:14 -0700137 options.xosHelperSource + '**/*.js',
Matteo Scandoloaa683dd2016-04-14 15:34:12 -0700138 ];
139
140 gulp.watch(files, ['makeDocs']);
141
Matteo Scandolob7dac502016-04-28 13:14:08 -0700142 // uncomment to enable autoreload, now it is broken (reload a wrong page)
143 // https://github.com/nikhilmodak/gulp-ngdocs/issues/81
144
145 // gulp.watch(files, function(){
146 // browserSync.reload();
147 // });
Matteo Scandoloaa683dd2016-04-14 15:34:12 -0700148 })
149
Matteo Scandolob7a86dc2016-04-14 11:46:30 -0700150 gulp.task('dev', function(){
Matteo Scandolo90ed0642016-04-25 10:11:56 -0700151 gulp.watch(`${options.xosHelperSource}**/*.scss`, ['style']);
Matteo Scandolob7a86dc2016-04-14 11:46:30 -0700152 gulp.watch(options.xosHelperSource + '**/*.js', ['helpersDev']);
153 });
Matteo Scandolo2b626742015-11-04 16:03:59 +0100154};