Matteo Scandolo | b0238d3 | 2015-11-04 16:03:59 +0100 | [diff] [blame] | 1 | var gulp = require('gulp'); |
| 2 | var uglify = require('gulp-uglify'); |
Matteo Scandolo | 45a5c56 | 2016-04-13 16:20:13 -0700 | [diff] [blame] | 3 | var concat = require('gulp-concat'); |
Matteo Scandolo | b0238d3 | 2015-11-04 16:03:59 +0100 | [diff] [blame] | 4 | var ngAnnotate = require('gulp-ng-annotate'); |
| 5 | var angularFilesort = require('gulp-angular-filesort'); |
Matteo Scandolo | 45a5c56 | 2016-04-13 16:20:13 -0700 | [diff] [blame] | 6 | var gulpDocs = require('gulp-ngdocs'); |
Matteo Scandolo | 717352a | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 7 | var del = require('del'); |
Matteo Scandolo | 1dab3e0 | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 8 | var babel = require('gulp-babel'); |
| 9 | const sourcemaps = require('gulp-sourcemaps'); |
Matteo Scandolo | 5614b90 | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 10 | var browserSync = require('browser-sync').create(); |
Matteo Scandolo | b0238d3 | 2015-11-04 16:03:59 +0100 | [diff] [blame] | 11 | |
| 12 | module.exports = function(options){ |
Matteo Scandolo | 1dab3e0 | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 13 | |
| 14 | // transpile js with sourceMaps |
| 15 | gulp.task('babel', function(){ |
| 16 | return gulp.src(options.xosHelperSource + '**/*.js') |
| 17 | .pipe(babel({ |
| 18 | presets: ['es2015'] |
| 19 | })) |
| 20 | .pipe(gulp.dest(options.xosHelperTmp)); |
| 21 | }); |
| 22 | |
| 23 | gulp.task('babelDev', function(){ |
| 24 | return gulp.src(options.xosHelperSource + '**/*.js') |
| 25 | .pipe(sourcemaps.init()) |
| 26 | .pipe(babel({ |
| 27 | presets: ['es2015'] |
| 28 | })) |
| 29 | .pipe(sourcemaps.write('./maps')) |
| 30 | .pipe(gulp.dest(options.xosHelperTmp)); |
| 31 | }); |
| 32 | |
| 33 | // build |
| 34 | gulp.task('helpers', ['babel'], function(){ |
| 35 | return gulp.src([options.xosHelperTmp + '**/*.js']) |
Matteo Scandolo | b0238d3 | 2015-11-04 16:03:59 +0100 | [diff] [blame] | 36 | .pipe(angularFilesort()) |
| 37 | .pipe(concat('ngXosHelpers.js')) |
| 38 | .pipe(ngAnnotate()) |
| 39 | .pipe(uglify()) |
| 40 | .pipe(gulp.dest(options.ngXosVendor)); |
| 41 | }); |
Matteo Scandolo | 45a5c56 | 2016-04-13 16:20:13 -0700 | [diff] [blame] | 42 | |
Matteo Scandolo | 1dab3e0 | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 43 | // build Dev (no minify, sourcemaps) |
| 44 | gulp.task('helpersDev', ['babelDev'], function(){ |
| 45 | return gulp.src([options.xosHelperTmp + '**/*.js']) |
| 46 | .pipe(angularFilesort()) |
| 47 | .pipe(concat('ngXosHelpers.js')) |
| 48 | .pipe(ngAnnotate()) |
| 49 | .pipe(gulp.dest(options.ngXosVendor)); |
| 50 | }); |
| 51 | |
Matteo Scandolo | 717352a | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 52 | gulp.task('cleanDocs', function(){ |
Matteo Scandolo | 717352a | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 53 | return del([options.docs + '**/*']); |
| 54 | }); |
| 55 | |
Matteo Scandolo | 5614b90 | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 56 | gulp.task('makeDocs', ['cleanDocs'], function(){ |
Matteo Scandolo | 717352a | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 57 | var ngOptions = { |
| 58 | scripts: [ |
| 59 | 'http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js', |
Matteo Scandolo | 5614b90 | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 60 | 'http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-animate.min.js', |
| 61 | `${options.ngXosVendor}ngXosHelpers.js` |
| 62 | ], |
| 63 | styles: [ |
| 64 | 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css', |
Matteo Scandolo | 717352a | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 65 | ], |
Matteo Scandolo | 6a6586e | 2016-04-14 16:52:13 -0700 | [diff] [blame] | 66 | html5Mode: false, |
Matteo Scandolo | 717352a | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 67 | title: 'XOS Helpers documentation', |
| 68 | startPage: '/module', |
| 69 | } |
| 70 | |
| 71 | return gulpDocs.sections({ |
| 72 | module: { |
| 73 | glob: [ |
| 74 | options.xosHelperSource + '*.js', |
Matteo Scandolo | 5614b90 | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 75 | options.xosHelperSource + 'services/*.js', |
| 76 | options.xosHelperSource + 'ui_components/**/*.js' |
Matteo Scandolo | 717352a | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 77 | ], |
| 78 | title: 'Module Documentation', |
| 79 | }, |
| 80 | 'rest-api': { |
| 81 | glob: [ |
| 82 | options.xosHelperSource + 'services/rest/*.js' |
| 83 | ], |
| 84 | api: true, |
| 85 | title: 'API Documentation', |
| 86 | } |
| 87 | }).pipe(gulpDocs.process(ngOptions)).pipe(gulp.dest('./docs')); |
Matteo Scandolo | 45a5c56 | 2016-04-13 16:20:13 -0700 | [diff] [blame] | 88 | }); |
Matteo Scandolo | 1dab3e0 | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 89 | |
Matteo Scandolo | 5614b90 | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 90 | gulp.task('serveDocs', function(){ |
| 91 | browserSync.init({ |
| 92 | server: { |
| 93 | baseDir: './docs', |
| 94 | routes: { |
| 95 | '/xos/core/xoslib/static/js/vendor': options.ngXosVendor |
| 96 | } |
| 97 | } |
| 98 | }); |
| 99 | }); |
| 100 | |
| 101 | gulp.task('docs', ['makeDocs', 'serveDocs'], function(){ |
| 102 | |
| 103 | var files = [ |
| 104 | options.xosHelperSource + '*.js', |
| 105 | options.xosHelperSource + 'services/*.js', |
| 106 | options.xosHelperSource + 'ui_components/**/*.js' |
| 107 | ]; |
| 108 | |
| 109 | gulp.watch(files, ['makeDocs']); |
| 110 | |
| 111 | gulp.watch(files, function(){ |
Matteo Scandolo | 5614b90 | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 112 | browserSync.reload(); |
| 113 | }); |
| 114 | }) |
| 115 | |
Matteo Scandolo | 1dab3e0 | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 116 | gulp.task('dev', function(){ |
| 117 | gulp.watch(options.xosHelperSource + '**/*.js', ['helpersDev']); |
| 118 | }); |
Matteo Scandolo | b0238d3 | 2015-11-04 16:03:59 +0100 | [diff] [blame] | 119 | }; |