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 | 90ed064 | 2016-04-25 10:11:56 -0700 | [diff] [blame] | 11 | var rename = require('gulp-rename'); |
| 12 | var sass = require('gulp-sass'); |
Matteo Scandolo | 2b62674 | 2015-11-04 16:03:59 +0100 | [diff] [blame] | 13 | |
| 14 | module.exports = function(options){ |
Matteo Scandolo | b7a86dc | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 15 | |
Matteo Scandolo | 90ed064 | 2016-04-25 10:11:56 -0700 | [diff] [blame] | 16 | gulp.task('style', function(){ |
Matteo Scandolo | b028075 | 2016-04-25 10:31:22 -0700 | [diff] [blame] | 17 | return gulp.src(`${options.xosHelperSource}styles/main.scss`) |
Matteo Scandolo | 90ed064 | 2016-04-25 10:11:56 -0700 | [diff] [blame] | 18 | .pipe(sourcemaps.init()) |
| 19 | .pipe(sass().on('error', sass.logError)) |
| 20 | .pipe(rename('xosNgLib.css')) |
| 21 | .pipe(sourcemaps.write()) |
| 22 | .pipe(gulp.dest(options.ngXosStyles)); |
| 23 | }); |
| 24 | |
Matteo Scandolo | b7a86dc | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 25 | // transpile js with sourceMaps |
| 26 | gulp.task('babel', function(){ |
| 27 | return gulp.src(options.xosHelperSource + '**/*.js') |
| 28 | .pipe(babel({ |
| 29 | presets: ['es2015'] |
| 30 | })) |
| 31 | .pipe(gulp.dest(options.xosHelperTmp)); |
| 32 | }); |
| 33 | |
| 34 | gulp.task('babelDev', function(){ |
| 35 | return gulp.src(options.xosHelperSource + '**/*.js') |
| 36 | .pipe(sourcemaps.init()) |
| 37 | .pipe(babel({ |
| 38 | presets: ['es2015'] |
| 39 | })) |
| 40 | .pipe(sourcemaps.write('./maps')) |
| 41 | .pipe(gulp.dest(options.xosHelperTmp)); |
| 42 | }); |
| 43 | |
| 44 | // build |
Matteo Scandolo | 90ed064 | 2016-04-25 10:11:56 -0700 | [diff] [blame] | 45 | gulp.task('helpers', ['babel', 'style'], function(){ |
Matteo Scandolo | b7a86dc | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 46 | return gulp.src([options.xosHelperTmp + '**/*.js']) |
Matteo Scandolo | 2b62674 | 2015-11-04 16:03:59 +0100 | [diff] [blame] | 47 | .pipe(angularFilesort()) |
| 48 | .pipe(concat('ngXosHelpers.js')) |
| 49 | .pipe(ngAnnotate()) |
| 50 | .pipe(uglify()) |
| 51 | .pipe(gulp.dest(options.ngXosVendor)); |
| 52 | }); |
Matteo Scandolo | 57404dc | 2016-04-13 16:20:13 -0700 | [diff] [blame] | 53 | |
Matteo Scandolo | b7a86dc | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 54 | // build Dev (no minify, sourcemaps) |
| 55 | gulp.task('helpersDev', ['babelDev'], function(){ |
| 56 | return gulp.src([options.xosHelperTmp + '**/*.js']) |
| 57 | .pipe(angularFilesort()) |
| 58 | .pipe(concat('ngXosHelpers.js')) |
| 59 | .pipe(ngAnnotate()) |
| 60 | .pipe(gulp.dest(options.ngXosVendor)); |
| 61 | }); |
| 62 | |
Matteo Scandolo | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 63 | gulp.task('cleanDocs', function(){ |
Matteo Scandolo | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 64 | return del([options.docs + '**/*']); |
| 65 | }); |
| 66 | |
Matteo Scandolo | aa683dd | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 67 | gulp.task('makeDocs', ['cleanDocs'], function(){ |
Matteo Scandolo | 68df51b | 2016-05-03 17:07:01 -0700 | [diff] [blame] | 68 | |
Matteo Scandolo | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 69 | var ngOptions = { |
Matteo Scandolo | 68df51b | 2016-05-03 17:07:01 -0700 | [diff] [blame] | 70 | scripts: [].concat([ |
Matteo Scandolo | 68df51b | 2016-05-03 17:07:01 -0700 | [diff] [blame] | 71 | `./${options.ngXosVendor}ngXosVendor.js`, |
Matteo Scandolo | 88e1846 | 2016-04-25 14:24:18 -0700 | [diff] [blame] | 72 | `./${options.ngXosVendor}ngXosHelpers.js`, |
arpiagariu | 98680a5 | 2016-06-14 14:08:45 -0700 | [diff] [blame] | 73 | '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] | 74 | ]), |
Matteo Scandolo | aa683dd | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 75 | styles: [ |
Matteo Scandolo | 88e1846 | 2016-04-25 14:24:18 -0700 | [diff] [blame] | 76 | `./${options.ngXosStyles}xosNgLib.css`, |
Matteo Scandolo | 199ec00 | 2016-04-22 10:53:49 -0700 | [diff] [blame] | 77 | '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] | 78 | ], |
Matteo Scandolo | a6a9e61 | 2016-04-14 16:52:13 -0700 | [diff] [blame] | 79 | html5Mode: false, |
Matteo Scandolo | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 80 | title: 'XOS Helpers documentation', |
Matteo Scandolo | 0ae5d35 | 2016-07-15 17:04:14 -0700 | [diff] [blame] | 81 | startPage: '/ngXosLib', |
Matteo Scandolo | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | return gulpDocs.sections({ |
Matteo Scandolo | 0ae5d35 | 2016-07-15 17:04:14 -0700 | [diff] [blame] | 85 | ngXosLib: { |
Matteo Scandolo | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 86 | glob: [ |
| 87 | options.xosHelperSource + '*.js', |
Matteo Scandolo | 974c0e4 | 2016-05-25 16:02:16 -0700 | [diff] [blame] | 88 | options.xosHelperSource + 'services/helpers/**/*.js', |
Matteo Scandolo | aa683dd | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 89 | options.xosHelperSource + 'services/*.js', |
| 90 | options.xosHelperSource + 'ui_components/**/*.js' |
Matteo Scandolo | 582cc81 | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 91 | ], |
| 92 | title: 'Module Documentation', |
| 93 | }, |
| 94 | 'rest-api': { |
| 95 | glob: [ |
| 96 | options.xosHelperSource + 'services/rest/*.js' |
| 97 | ], |
| 98 | api: true, |
| 99 | title: 'API Documentation', |
| 100 | } |
| 101 | }).pipe(gulpDocs.process(ngOptions)).pipe(gulp.dest('./docs')); |
Matteo Scandolo | 57404dc | 2016-04-13 16:20:13 -0700 | [diff] [blame] | 102 | }); |
Matteo Scandolo | b7a86dc | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 103 | |
Matteo Scandolo | aa683dd | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 104 | gulp.task('serveDocs', function(){ |
| 105 | browserSync.init({ |
| 106 | server: { |
| 107 | baseDir: './docs', |
| 108 | routes: { |
Matteo Scandolo | 88e1846 | 2016-04-25 14:24:18 -0700 | [diff] [blame] | 109 | '/xos/core/xoslib/static/js/vendor': options.ngXosVendor, |
arpiagariu | 98680a5 | 2016-06-14 14:08:45 -0700 | [diff] [blame] | 110 | '/xos/core/static': options.ngXosStyles, |
Matteo Scandolo | aa683dd | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | }); |
| 114 | }); |
| 115 | |
| 116 | gulp.task('docs', ['makeDocs', 'serveDocs'], function(){ |
| 117 | |
| 118 | var files = [ |
Matteo Scandolo | 0ae5d35 | 2016-07-15 17:04:14 -0700 | [diff] [blame] | 119 | options.xosHelperSource + '**/*.js', |
Matteo Scandolo | aa683dd | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 120 | ]; |
| 121 | |
| 122 | gulp.watch(files, ['makeDocs']); |
| 123 | |
Matteo Scandolo | b7dac50 | 2016-04-28 13:14:08 -0700 | [diff] [blame] | 124 | // uncomment to enable autoreload, now it is broken (reload a wrong page) |
| 125 | // https://github.com/nikhilmodak/gulp-ngdocs/issues/81 |
| 126 | |
| 127 | // gulp.watch(files, function(){ |
| 128 | // browserSync.reload(); |
| 129 | // }); |
Matteo Scandolo | aa683dd | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 130 | }) |
| 131 | |
Matteo Scandolo | b7a86dc | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 132 | gulp.task('dev', function(){ |
Matteo Scandolo | 90ed064 | 2016-04-25 10:11:56 -0700 | [diff] [blame] | 133 | gulp.watch(`${options.xosHelperSource}**/*.scss`, ['style']); |
Matteo Scandolo | b7a86dc | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 134 | gulp.watch(options.xosHelperSource + '**/*.js', ['helpersDev']); |
| 135 | }); |
Matteo Scandolo | 2b62674 | 2015-11-04 16:03:59 +0100 | [diff] [blame] | 136 | }; |