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 | aa683dd | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 10 | var browserSync = require('browser-sync').create(); |
Matteo Scandolo | 2b62674 | 2015-11-04 16:03:59 +0100 | [diff] [blame] | 11 | |
| 12 | module.exports = function(options){ |
Matteo Scandolo | b7a86dc | 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 | 2b62674 | 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 | 57404dc | 2016-04-13 16:20:13 -0700 | [diff] [blame] | 42 | |
Matteo Scandolo | b7a86dc | 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 | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 52 | gulp.task('cleanDocs', function(){ |
Matteo Scandolo | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 53 | return del([options.docs + '**/*']); |
| 54 | }); |
| 55 | |
Matteo Scandolo | aa683dd | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 56 | gulp.task('makeDocs', ['cleanDocs'], function(){ |
Matteo Scandolo | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 57 | var ngOptions = { |
| 58 | scripts: [ |
Matteo Scandolo | 199ec00 | 2016-04-22 10:53:49 -0700 | [diff] [blame] | 59 | 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular.js', |
| 60 | 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular-animate.js', |
| 61 | 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular-cookies.min.js', |
| 62 | 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular-resource.js', |
Matteo Scandolo | 840260d | 2016-04-22 09:56:48 -0700 | [diff] [blame] | 63 | 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.11.2/lodash.js', |
Matteo Scandolo | 199ec00 | 2016-04-22 10:53:49 -0700 | [diff] [blame] | 64 | `./${options.ngXosVendor}ngXosHelpers.js` |
Matteo Scandolo | aa683dd | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 65 | ], |
| 66 | styles: [ |
Matteo Scandolo | 199ec00 | 2016-04-22 10:53:49 -0700 | [diff] [blame] | 67 | '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] | 68 | ], |
Matteo Scandolo | a6a9e61 | 2016-04-14 16:52:13 -0700 | [diff] [blame] | 69 | html5Mode: false, |
Matteo Scandolo | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 70 | title: 'XOS Helpers documentation', |
| 71 | startPage: '/module', |
| 72 | } |
| 73 | |
| 74 | return gulpDocs.sections({ |
| 75 | module: { |
| 76 | glob: [ |
| 77 | options.xosHelperSource + '*.js', |
Matteo Scandolo | aa683dd | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 78 | options.xosHelperSource + 'services/*.js', |
| 79 | options.xosHelperSource + 'ui_components/**/*.js' |
Matteo Scandolo | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 80 | ], |
| 81 | title: 'Module Documentation', |
| 82 | }, |
| 83 | 'rest-api': { |
| 84 | glob: [ |
| 85 | options.xosHelperSource + 'services/rest/*.js' |
| 86 | ], |
| 87 | api: true, |
| 88 | title: 'API Documentation', |
| 89 | } |
| 90 | }).pipe(gulpDocs.process(ngOptions)).pipe(gulp.dest('./docs')); |
Matteo Scandolo | 57404dc | 2016-04-13 16:20:13 -0700 | [diff] [blame] | 91 | }); |
Matteo Scandolo | b7a86dc | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 92 | |
Matteo Scandolo | aa683dd | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 93 | gulp.task('serveDocs', function(){ |
| 94 | browserSync.init({ |
| 95 | server: { |
| 96 | baseDir: './docs', |
| 97 | routes: { |
| 98 | '/xos/core/xoslib/static/js/vendor': options.ngXosVendor |
| 99 | } |
| 100 | } |
| 101 | }); |
| 102 | }); |
| 103 | |
| 104 | gulp.task('docs', ['makeDocs', 'serveDocs'], function(){ |
| 105 | |
| 106 | var files = [ |
| 107 | options.xosHelperSource + '*.js', |
| 108 | options.xosHelperSource + 'services/*.js', |
| 109 | options.xosHelperSource + 'ui_components/**/*.js' |
| 110 | ]; |
| 111 | |
| 112 | gulp.watch(files, ['makeDocs']); |
| 113 | |
| 114 | gulp.watch(files, function(){ |
Matteo Scandolo | aa683dd | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 115 | browserSync.reload(); |
| 116 | }); |
| 117 | }) |
| 118 | |
Matteo Scandolo | b7a86dc | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 119 | gulp.task('dev', function(){ |
| 120 | gulp.watch(options.xosHelperSource + '**/*.js', ['helpersDev']); |
| 121 | }); |
Matteo Scandolo | 2b62674 | 2015-11-04 16:03:59 +0100 | [diff] [blame] | 122 | }; |