Steven Burrows | a145e10 | 2017-06-16 13:37:50 -0400 | [diff] [blame] | 1 | import gulp from 'gulp'; |
| 2 | import concat from 'gulp-concat'; |
| 3 | import strip from 'gulp-strip-comments'; |
| 4 | import uglyfy from 'gulp-uglify'; |
| 5 | import sourceMaps from 'gulp-sourcemaps'; |
| 6 | import BundleResources from '../helpers/bundleResources'; |
| 7 | |
| 8 | |
| 9 | const GUI_BASE = '../../web/gui/src/main/webapp/'; |
| 10 | const bundleFiles = [ |
| 11 | // NOTE: Bundle the important files first |
| 12 | 'app/directives.js', |
| 13 | 'app/fw/util/util.js', |
| 14 | 'app/fw/mast/mast.js', |
| 15 | 'app/fw/nav/nav.js', |
| 16 | 'app/fw/svg/svg.js', |
| 17 | 'app/fw/remote/remote.js', |
| 18 | 'app/fw/widget/widget.js', |
| 19 | 'app/fw/layer/layer.js', |
| 20 | |
| 21 | // NOTE: bundle everything else |
| 22 | 'app/fw/**/*.js', |
| 23 | 'app/view/**/*.js' |
| 24 | ]; |
| 25 | |
| 26 | const vendor = [ |
| 27 | 'tp/angular.js', |
| 28 | 'tp/angular-route.js', |
| 29 | 'tp/angular-cookies.js', |
| 30 | 'tp/d3.js', |
| 31 | 'tp/topojson.v1.min.js', |
Steven Burrows | 96ee21e | 2017-07-11 19:49:45 +0100 | [diff] [blame] | 32 | 'tp/Chart.js', |
Steven Burrows | a145e10 | 2017-06-16 13:37:50 -0400 | [diff] [blame] | 33 | 'tp/lodash.min.js', |
| 34 | ]; |
| 35 | |
| 36 | function bundle(files, exportName) { |
| 37 | return gulp.src(BundleResources(GUI_BASE, files)) |
| 38 | .pipe(sourceMaps.init()) |
| 39 | .pipe(strip()) |
| 40 | .pipe(uglyfy()) |
Steven Burrows | dc16562 | 2017-07-20 14:40:27 +0100 | [diff] [blame] | 41 | .on('error', (e, file, line) => console.error(e)) |
Steven Burrows | a145e10 | 2017-06-16 13:37:50 -0400 | [diff] [blame] | 42 | .pipe(concat(exportName)) |
| 43 | .pipe(sourceMaps.write('source-map')) |
| 44 | .pipe(gulp.dest(GUI_BASE + '/dist/')); |
| 45 | } |
| 46 | |
| 47 | const tasks = function () { |
Simon Hunt | 5c3ed73 | 2017-07-20 19:03:28 +0000 | [diff] [blame] | 48 | gulp.task('bundle-vendor', () => bundle(vendor, 'vendor.js')); |
Steven Burrows | a145e10 | 2017-06-16 13:37:50 -0400 | [diff] [blame] | 49 | gulp.task('bundle-js', () => bundle(bundleFiles, 'onos.js')); |
Steven Burrows | a145e10 | 2017-06-16 13:37:50 -0400 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | export default tasks(); |