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', |
Matteo Scandolo | 9a8f53c | 2016-04-22 09:56:48 -0700 | [diff] [blame^] | 61 | 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.11.2/lodash.js', |
Matteo Scandolo | 5614b90 | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 62 | `${options.ngXosVendor}ngXosHelpers.js` |
| 63 | ], |
| 64 | styles: [ |
| 65 | 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css', |
Matteo Scandolo | 717352a | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 66 | ], |
Matteo Scandolo | 6a6586e | 2016-04-14 16:52:13 -0700 | [diff] [blame] | 67 | html5Mode: false, |
Matteo Scandolo | 717352a | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 68 | title: 'XOS Helpers documentation', |
| 69 | startPage: '/module', |
| 70 | } |
| 71 | |
| 72 | return gulpDocs.sections({ |
| 73 | module: { |
| 74 | glob: [ |
| 75 | options.xosHelperSource + '*.js', |
Matteo Scandolo | 5614b90 | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 76 | options.xosHelperSource + 'services/*.js', |
| 77 | options.xosHelperSource + 'ui_components/**/*.js' |
Matteo Scandolo | 717352a | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 78 | ], |
| 79 | title: 'Module Documentation', |
| 80 | }, |
| 81 | 'rest-api': { |
| 82 | glob: [ |
| 83 | options.xosHelperSource + 'services/rest/*.js' |
| 84 | ], |
| 85 | api: true, |
| 86 | title: 'API Documentation', |
| 87 | } |
| 88 | }).pipe(gulpDocs.process(ngOptions)).pipe(gulp.dest('./docs')); |
Matteo Scandolo | 45a5c56 | 2016-04-13 16:20:13 -0700 | [diff] [blame] | 89 | }); |
Matteo Scandolo | 1dab3e0 | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 90 | |
Matteo Scandolo | 5614b90 | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 91 | gulp.task('serveDocs', function(){ |
| 92 | browserSync.init({ |
| 93 | server: { |
| 94 | baseDir: './docs', |
| 95 | routes: { |
| 96 | '/xos/core/xoslib/static/js/vendor': options.ngXosVendor |
| 97 | } |
| 98 | } |
| 99 | }); |
| 100 | }); |
| 101 | |
| 102 | gulp.task('docs', ['makeDocs', 'serveDocs'], function(){ |
| 103 | |
| 104 | var files = [ |
| 105 | options.xosHelperSource + '*.js', |
| 106 | options.xosHelperSource + 'services/*.js', |
| 107 | options.xosHelperSource + 'ui_components/**/*.js' |
| 108 | ]; |
| 109 | |
| 110 | gulp.watch(files, ['makeDocs']); |
| 111 | |
| 112 | gulp.watch(files, function(){ |
Matteo Scandolo | 5614b90 | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 113 | browserSync.reload(); |
| 114 | }); |
| 115 | }) |
| 116 | |
Matteo Scandolo | 1dab3e0 | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 117 | gulp.task('dev', function(){ |
| 118 | gulp.watch(options.xosHelperSource + '**/*.js', ['helpersDev']); |
| 119 | }); |
Matteo Scandolo | b0238d3 | 2015-11-04 16:03:59 +0100 | [diff] [blame] | 120 | }; |