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 | e53ee38 | 2016-04-25 10:11:56 -0700 | [diff] [blame] | 11 | var rename = require('gulp-rename'); |
| 12 | var sass = require('gulp-sass'); |
Matteo Scandolo | b0238d3 | 2015-11-04 16:03:59 +0100 | [diff] [blame] | 13 | |
| 14 | module.exports = function(options){ |
Matteo Scandolo | 1dab3e0 | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 15 | |
Matteo Scandolo | e53ee38 | 2016-04-25 10:11:56 -0700 | [diff] [blame] | 16 | gulp.task('style', function(){ |
Matteo Scandolo | c88bb9f | 2016-04-25 10:31:22 -0700 | [diff] [blame] | 17 | return gulp.src(`${options.xosHelperSource}styles/main.scss`) |
Matteo Scandolo | e53ee38 | 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 | 1dab3e0 | 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 | e53ee38 | 2016-04-25 10:11:56 -0700 | [diff] [blame] | 45 | gulp.task('helpers', ['babel', 'style'], function(){ |
Matteo Scandolo | 1dab3e0 | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 46 | return gulp.src([options.xosHelperTmp + '**/*.js']) |
Matteo Scandolo | b0238d3 | 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 | 45a5c56 | 2016-04-13 16:20:13 -0700 | [diff] [blame] | 53 | |
Matteo Scandolo | 1dab3e0 | 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 | 717352a | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 63 | gulp.task('cleanDocs', function(){ |
Matteo Scandolo | 717352a | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 64 | return del([options.docs + '**/*']); |
| 65 | }); |
| 66 | |
Matteo Scandolo | 5614b90 | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 67 | gulp.task('makeDocs', ['cleanDocs'], function(){ |
Matteo Scandolo | 717352a | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 68 | var ngOptions = { |
| 69 | scripts: [ |
Matteo Scandolo | 9bb3a95 | 2016-04-25 14:24:18 -0700 | [diff] [blame] | 70 | 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular.min.js', |
| 71 | 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular-animate.min.js', |
Matteo Scandolo | d702aff | 2016-04-22 10:53:49 -0700 | [diff] [blame] | 72 | 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular-cookies.min.js', |
| 73 | 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular-resource.js', |
Matteo Scandolo | ed92a29 | 2016-04-28 13:14:08 -0700 | [diff] [blame] | 74 | 'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular-mocks.js', |
Matteo Scandolo | 9a8f53c | 2016-04-22 09:56:48 -0700 | [diff] [blame] | 75 | 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.11.2/lodash.js', |
Matteo Scandolo | 9bb3a95 | 2016-04-25 14:24:18 -0700 | [diff] [blame] | 76 | `./${options.ngXosVendor}ngXosHelpers.js`, |
Matteo Scandolo | 5614b90 | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 77 | ], |
| 78 | styles: [ |
Matteo Scandolo | 9bb3a95 | 2016-04-25 14:24:18 -0700 | [diff] [blame] | 79 | `./${options.ngXosStyles}xosNgLib.css`, |
Matteo Scandolo | d702aff | 2016-04-22 10:53:49 -0700 | [diff] [blame] | 80 | 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css', |
Matteo Scandolo | 717352a | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 81 | ], |
Matteo Scandolo | 6a6586e | 2016-04-14 16:52:13 -0700 | [diff] [blame] | 82 | html5Mode: false, |
Matteo Scandolo | 717352a | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 83 | title: 'XOS Helpers documentation', |
| 84 | startPage: '/module', |
| 85 | } |
| 86 | |
| 87 | return gulpDocs.sections({ |
| 88 | module: { |
| 89 | glob: [ |
| 90 | options.xosHelperSource + '*.js', |
Matteo Scandolo | 5614b90 | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 91 | options.xosHelperSource + 'services/*.js', |
| 92 | options.xosHelperSource + 'ui_components/**/*.js' |
Matteo Scandolo | 717352a | 2016-04-13 17:23:28 -0700 | [diff] [blame] | 93 | ], |
| 94 | title: 'Module Documentation', |
| 95 | }, |
| 96 | 'rest-api': { |
| 97 | glob: [ |
| 98 | options.xosHelperSource + 'services/rest/*.js' |
| 99 | ], |
| 100 | api: true, |
| 101 | title: 'API Documentation', |
| 102 | } |
| 103 | }).pipe(gulpDocs.process(ngOptions)).pipe(gulp.dest('./docs')); |
Matteo Scandolo | 45a5c56 | 2016-04-13 16:20:13 -0700 | [diff] [blame] | 104 | }); |
Matteo Scandolo | 1dab3e0 | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 105 | |
Matteo Scandolo | 5614b90 | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 106 | gulp.task('serveDocs', function(){ |
| 107 | browserSync.init({ |
| 108 | server: { |
| 109 | baseDir: './docs', |
| 110 | routes: { |
Matteo Scandolo | 9bb3a95 | 2016-04-25 14:24:18 -0700 | [diff] [blame] | 111 | '/xos/core/xoslib/static/js/vendor': options.ngXosVendor, |
| 112 | '/xos/core/static': options.ngXosStyles |
Matteo Scandolo | 5614b90 | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | }); |
| 116 | }); |
| 117 | |
| 118 | gulp.task('docs', ['makeDocs', 'serveDocs'], function(){ |
| 119 | |
| 120 | var files = [ |
| 121 | options.xosHelperSource + '*.js', |
| 122 | options.xosHelperSource + 'services/*.js', |
| 123 | options.xosHelperSource + 'ui_components/**/*.js' |
| 124 | ]; |
| 125 | |
| 126 | gulp.watch(files, ['makeDocs']); |
| 127 | |
Matteo Scandolo | ed92a29 | 2016-04-28 13:14:08 -0700 | [diff] [blame] | 128 | // uncomment to enable autoreload, now it is broken (reload a wrong page) |
| 129 | // https://github.com/nikhilmodak/gulp-ngdocs/issues/81 |
| 130 | |
| 131 | // gulp.watch(files, function(){ |
| 132 | // browserSync.reload(); |
| 133 | // }); |
Matteo Scandolo | 5614b90 | 2016-04-14 15:34:12 -0700 | [diff] [blame] | 134 | }) |
| 135 | |
Matteo Scandolo | 1dab3e0 | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 136 | gulp.task('dev', function(){ |
Matteo Scandolo | e53ee38 | 2016-04-25 10:11:56 -0700 | [diff] [blame] | 137 | gulp.watch(`${options.xosHelperSource}**/*.scss`, ['style']); |
Matteo Scandolo | 1dab3e0 | 2016-04-14 11:46:30 -0700 | [diff] [blame] | 138 | gulp.watch(options.xosHelperSource + '**/*.js', ['helpersDev']); |
| 139 | }); |
Matteo Scandolo | b0238d3 | 2015-11-04 16:03:59 +0100 | [diff] [blame] | 140 | }; |