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'; |
Steven Burrows | 0f26ac8 | 2017-08-07 22:36:36 +0100 | [diff] [blame] | 7 | import { reload } from '../../dev-server'; |
Steven Burrows | a145e10 | 2017-06-16 13:37:50 -0400 | [diff] [blame] | 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) { |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 37 | |
| 38 | // TODO: Use util.noop once npm issues have been resolved |
| 39 | if (process.argv.indexOf('--development') > -1) { |
| 40 | return gulp.src(BundleResources(GUI_BASE, files)) |
| 41 | .pipe(sourceMaps.init()) |
| 42 | .on('error', (e, file, line) => console.error(e)) |
| 43 | .pipe(concat(exportName)) |
| 44 | .pipe(sourceMaps.write('source-map')) |
| 45 | .pipe(gulp.dest(GUI_BASE + '/dist/')) |
Steven Burrows | 0f26ac8 | 2017-08-07 22:36:36 +0100 | [diff] [blame] | 46 | .on('end', () => { reload(); }) |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 47 | } |
| 48 | |
Steven Burrows | a145e10 | 2017-06-16 13:37:50 -0400 | [diff] [blame] | 49 | return gulp.src(BundleResources(GUI_BASE, files)) |
| 50 | .pipe(sourceMaps.init()) |
| 51 | .pipe(strip()) |
| 52 | .pipe(uglyfy()) |
Steven Burrows | dc16562 | 2017-07-20 14:40:27 +0100 | [diff] [blame] | 53 | .on('error', (e, file, line) => console.error(e)) |
Steven Burrows | a145e10 | 2017-06-16 13:37:50 -0400 | [diff] [blame] | 54 | .pipe(concat(exportName)) |
| 55 | .pipe(sourceMaps.write('source-map')) |
| 56 | .pipe(gulp.dest(GUI_BASE + '/dist/')); |
| 57 | } |
| 58 | |
| 59 | const tasks = function () { |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 60 | // gulp.task('bundle-vendor', () => bundle(vendor, 'vendor.js')); |
Steven Burrows | a145e10 | 2017-06-16 13:37:50 -0400 | [diff] [blame] | 61 | gulp.task('bundle-js', () => bundle(bundleFiles, 'onos.js')); |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 62 | gulp.task('watch-js', () => { |
Steven Burrows | 4b4d2b4 | 2017-08-16 14:11:23 +0100 | [diff] [blame] | 63 | gulp.watch([GUI_BASE + 'app/**/*.js'], ['bundle-js']); |
Steven Burrows | 1c2a968 | 2017-07-14 16:52:46 +0100 | [diff] [blame] | 64 | }).on('change', (event) => { |
| 65 | console.log('File ' + event.path + ' was ' + event.type + ', running tasks...'); |
| 66 | }); |
Steven Burrows | a145e10 | 2017-06-16 13:37:50 -0400 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | export default tasks(); |