Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 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 Scandolo | 2b62674 | 2015-11-04 16:03:59 +0100 | [diff] [blame] | 19 | var gulp = require('gulp'); |
| 20 | var uglify = require('gulp-uglify'); |
Matteo Scandolo | 57404dc | 2016-04-13 16:20:13 -0700 | [diff] [blame] | 21 | var concat = require('gulp-concat'); |
Matteo Scandolo | 2b62674 | 2015-11-04 16:03:59 +0100 | [diff] [blame] | 22 | var ngAnnotate = require('gulp-ng-annotate'); |
| 23 | var angularFilesort = require('gulp-angular-filesort'); |
Matteo Scandolo | 57404dc | 2016-04-13 16:20:13 -0700 | [diff] [blame] | 24 | var gulpDocs = require('gulp-ngdocs'); |
Matteo Scandolo | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 25 | var del = require('del'); |
Matteo Scandolo | b7a86dc | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 26 | var babel = require('gulp-babel'); |
| 27 | const sourcemaps = require('gulp-sourcemaps'); |
Matteo Scandolo | aa683dd | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 28 | var browserSync = require('browser-sync').create(); |
Matteo Scandolo | 90ed064 | 2016-04-25 10:11:56 -0700 | [diff] [blame] | 29 | var rename = require('gulp-rename'); |
| 30 | var sass = require('gulp-sass'); |
Matteo Scandolo | 2b62674 | 2015-11-04 16:03:59 +0100 | [diff] [blame] | 31 | |
| 32 | module.exports = function(options){ |
Matteo Scandolo | b7a86dc | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 33 | |
Matteo Scandolo | 90ed064 | 2016-04-25 10:11:56 -0700 | [diff] [blame] | 34 | gulp.task('style', function(){ |
Matteo Scandolo | b028075 | 2016-04-25 10:31:22 -0700 | [diff] [blame] | 35 | return gulp.src(`${options.xosHelperSource}styles/main.scss`) |
Matteo Scandolo | 90ed064 | 2016-04-25 10:11:56 -0700 | [diff] [blame] | 36 | .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 Scandolo | b7a86dc | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 43 | // 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 Scandolo | 90ed064 | 2016-04-25 10:11:56 -0700 | [diff] [blame] | 63 | gulp.task('helpers', ['babel', 'style'], function(){ |
Matteo Scandolo | b7a86dc | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 64 | return gulp.src([options.xosHelperTmp + '**/*.js']) |
Matteo Scandolo | 2b62674 | 2015-11-04 16:03:59 +0100 | [diff] [blame] | 65 | .pipe(angularFilesort()) |
| 66 | .pipe(concat('ngXosHelpers.js')) |
| 67 | .pipe(ngAnnotate()) |
| 68 | .pipe(uglify()) |
| 69 | .pipe(gulp.dest(options.ngXosVendor)); |
| 70 | }); |
Matteo Scandolo | 57404dc | 2016-04-13 16:20:13 -0700 | [diff] [blame] | 71 | |
Matteo Scandolo | b7a86dc | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 72 | // 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 Scandolo | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 81 | gulp.task('cleanDocs', function(){ |
Matteo Scandolo | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 82 | return del([options.docs + '**/*']); |
| 83 | }); |
| 84 | |
Matteo Scandolo | aa683dd | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 85 | gulp.task('makeDocs', ['cleanDocs'], function(){ |
Matteo Scandolo | 68df51b | 2016-05-03 17:07:01 -0700 | [diff] [blame] | 86 | |
Matteo Scandolo | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 87 | var ngOptions = { |
Matteo Scandolo | 68df51b | 2016-05-03 17:07:01 -0700 | [diff] [blame] | 88 | scripts: [].concat([ |
Matteo Scandolo | 68df51b | 2016-05-03 17:07:01 -0700 | [diff] [blame] | 89 | `./${options.ngXosVendor}ngXosVendor.js`, |
Matteo Scandolo | 88e1846 | 2016-04-25 14:24:18 -0700 | [diff] [blame] | 90 | `./${options.ngXosVendor}ngXosHelpers.js`, |
arpiagariu | 98680a5 | 2016-06-14 14:08:45 -0700 | [diff] [blame] | 91 | 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular-mocks.js', |
Matteo Scandolo | 68df51b | 2016-05-03 17:07:01 -0700 | [diff] [blame] | 92 | ]), |
Matteo Scandolo | aa683dd | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 93 | styles: [ |
Matteo Scandolo | 88e1846 | 2016-04-25 14:24:18 -0700 | [diff] [blame] | 94 | `./${options.ngXosStyles}xosNgLib.css`, |
Matteo Scandolo | 199ec00 | 2016-04-22 10:53:49 -0700 | [diff] [blame] | 95 | 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css', |
Matteo Scandolo | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 96 | ], |
Matteo Scandolo | a6a9e61 | 2016-04-14 16:52:13 -0700 | [diff] [blame] | 97 | html5Mode: false, |
Matteo Scandolo | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 98 | title: 'XOS Helpers documentation', |
Matteo Scandolo | 0ae5d35 | 2016-07-15 17:04:14 -0700 | [diff] [blame] | 99 | startPage: '/ngXosLib', |
Matteo Scandolo | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | return gulpDocs.sections({ |
Matteo Scandolo | 0ae5d35 | 2016-07-15 17:04:14 -0700 | [diff] [blame] | 103 | ngXosLib: { |
Matteo Scandolo | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 104 | glob: [ |
| 105 | options.xosHelperSource + '*.js', |
Matteo Scandolo | 974c0e4 | 2016-05-25 16:02:16 -0700 | [diff] [blame] | 106 | options.xosHelperSource + 'services/helpers/**/*.js', |
Matteo Scandolo | aa683dd | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 107 | options.xosHelperSource + 'services/*.js', |
| 108 | options.xosHelperSource + 'ui_components/**/*.js' |
Matteo Scandolo | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 109 | ], |
| 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 Scandolo | 57404dc | 2016-04-13 16:20:13 -0700 | [diff] [blame] | 120 | }); |
Matteo Scandolo | b7a86dc | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 121 | |
Matteo Scandolo | aa683dd | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 122 | gulp.task('serveDocs', function(){ |
| 123 | browserSync.init({ |
| 124 | server: { |
| 125 | baseDir: './docs', |
| 126 | routes: { |
Matteo Scandolo | 88e1846 | 2016-04-25 14:24:18 -0700 | [diff] [blame] | 127 | '/xos/core/xoslib/static/js/vendor': options.ngXosVendor, |
arpiagariu | 98680a5 | 2016-06-14 14:08:45 -0700 | [diff] [blame] | 128 | '/xos/core/static': options.ngXosStyles, |
Matteo Scandolo | aa683dd | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | }); |
| 132 | }); |
| 133 | |
| 134 | gulp.task('docs', ['makeDocs', 'serveDocs'], function(){ |
| 135 | |
| 136 | var files = [ |
Matteo Scandolo | 0ae5d35 | 2016-07-15 17:04:14 -0700 | [diff] [blame] | 137 | options.xosHelperSource + '**/*.js', |
Matteo Scandolo | aa683dd | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 138 | ]; |
| 139 | |
| 140 | gulp.watch(files, ['makeDocs']); |
| 141 | |
Matteo Scandolo | b7dac50 | 2016-04-28 13:14:08 -0700 | [diff] [blame] | 142 | // 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 Scandolo | aa683dd | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 148 | }) |
| 149 | |
Matteo Scandolo | b7a86dc | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 150 | gulp.task('dev', function(){ |
Matteo Scandolo | 90ed064 | 2016-04-25 10:11:56 -0700 | [diff] [blame] | 151 | gulp.watch(`${options.xosHelperSource}**/*.scss`, ['style']); |
Matteo Scandolo | b7a86dc | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 152 | gulp.watch(options.xosHelperSource + '**/*.js', ['helpersDev']); |
| 153 | }); |
Matteo Scandolo | 2b62674 | 2015-11-04 16:03:59 +0100 | [diff] [blame] | 154 | }; |