Matteo Scandolo | 2b62674 | 2015-11-04 16:03:59 +0100 | [diff] [blame] | 1 | var gulp = require('gulp'); |
| 2 | var uglify = require('gulp-uglify'); |
Matteo Scandolo | 57404dc | 2016-04-13 16:20:13 -0700 | [diff] [blame] | 3 | var concat = require('gulp-concat'); |
Matteo Scandolo | 2b62674 | 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 | 57404dc | 2016-04-13 16:20:13 -0700 | [diff] [blame] | 6 | var gulpDocs = require('gulp-ngdocs'); |
Matteo Scandolo | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 7 | var del = require('del'); |
Matteo Scandolo | b7a86dc | 2016-04-14 11:46:30 -0700 | [diff] [blame^] | 8 | var babel = require('gulp-babel'); |
| 9 | const sourcemaps = require('gulp-sourcemaps'); |
Matteo Scandolo | 2b62674 | 2015-11-04 16:03:59 +0100 | [diff] [blame] | 10 | |
| 11 | module.exports = function(options){ |
Matteo Scandolo | b7a86dc | 2016-04-14 11:46:30 -0700 | [diff] [blame^] | 12 | |
| 13 | // transpile js with sourceMaps |
| 14 | gulp.task('babel', function(){ |
| 15 | return gulp.src(options.xosHelperSource + '**/*.js') |
| 16 | .pipe(babel({ |
| 17 | presets: ['es2015'] |
| 18 | })) |
| 19 | .pipe(gulp.dest(options.xosHelperTmp)); |
| 20 | }); |
| 21 | |
| 22 | gulp.task('babelDev', function(){ |
| 23 | return gulp.src(options.xosHelperSource + '**/*.js') |
| 24 | .pipe(sourcemaps.init()) |
| 25 | .pipe(babel({ |
| 26 | presets: ['es2015'] |
| 27 | })) |
| 28 | .pipe(sourcemaps.write('./maps')) |
| 29 | .pipe(gulp.dest(options.xosHelperTmp)); |
| 30 | }); |
| 31 | |
| 32 | // build |
| 33 | gulp.task('helpers', ['babel'], function(){ |
| 34 | return gulp.src([options.xosHelperTmp + '**/*.js']) |
Matteo Scandolo | 2b62674 | 2015-11-04 16:03:59 +0100 | [diff] [blame] | 35 | .pipe(angularFilesort()) |
| 36 | .pipe(concat('ngXosHelpers.js')) |
| 37 | .pipe(ngAnnotate()) |
| 38 | .pipe(uglify()) |
| 39 | .pipe(gulp.dest(options.ngXosVendor)); |
| 40 | }); |
Matteo Scandolo | 57404dc | 2016-04-13 16:20:13 -0700 | [diff] [blame] | 41 | |
Matteo Scandolo | b7a86dc | 2016-04-14 11:46:30 -0700 | [diff] [blame^] | 42 | // build Dev (no minify, sourcemaps) |
| 43 | gulp.task('helpersDev', ['babelDev'], function(){ |
| 44 | return gulp.src([options.xosHelperTmp + '**/*.js']) |
| 45 | .pipe(angularFilesort()) |
| 46 | .pipe(concat('ngXosHelpers.js')) |
| 47 | .pipe(ngAnnotate()) |
| 48 | .pipe(gulp.dest(options.ngXosVendor)); |
| 49 | }); |
| 50 | |
Matteo Scandolo | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 51 | gulp.task('cleanDocs', function(){ |
| 52 | console.log(options); |
| 53 | return del([options.docs + '**/*']); |
| 54 | }); |
| 55 | |
| 56 | gulp.task('docs', ['cleanDocs'], function(){ |
| 57 | var ngOptions = { |
| 58 | scripts: [ |
| 59 | 'http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js', |
| 60 | 'http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-animate.min.js' |
| 61 | ], |
| 62 | html5Mode: true, |
| 63 | title: 'XOS Helpers documentation', |
| 64 | startPage: '/module', |
| 65 | } |
| 66 | |
| 67 | return gulpDocs.sections({ |
| 68 | module: { |
| 69 | glob: [ |
| 70 | options.xosHelperSource + '*.js', |
| 71 | options.xosHelperSource + 'services/*.js' |
| 72 | ], |
| 73 | title: 'Module Documentation', |
| 74 | }, |
| 75 | 'rest-api': { |
| 76 | glob: [ |
| 77 | options.xosHelperSource + 'services/rest/*.js' |
| 78 | ], |
| 79 | api: true, |
| 80 | title: 'API Documentation', |
| 81 | } |
| 82 | }).pipe(gulpDocs.process(ngOptions)).pipe(gulp.dest('./docs')); |
Matteo Scandolo | 57404dc | 2016-04-13 16:20:13 -0700 | [diff] [blame] | 83 | }); |
Matteo Scandolo | b7a86dc | 2016-04-14 11:46:30 -0700 | [diff] [blame^] | 84 | |
| 85 | gulp.task('dev', function(){ |
| 86 | gulp.watch(options.xosHelperSource + '**/*.js', ['helpersDev']); |
| 87 | }); |
Matteo Scandolo | 2b62674 | 2015-11-04 16:03:59 +0100 | [diff] [blame] | 88 | }; |