blob: 25e0aed4c38a574edb8bca2f4d9d8a45042c33f1 [file] [log] [blame]
Steven Burrowsa145e102017-06-16 13:37:50 -04001import gulp from 'gulp';
2import concat from 'gulp-concat';
3import strip from 'gulp-strip-comments';
4import uglyfy from 'gulp-uglify';
5import sourceMaps from 'gulp-sourcemaps';
6import BundleResources from '../helpers/bundleResources';
Steven Burrows0f26ac82017-08-07 22:36:36 +01007import { reload } from '../../dev-server';
Steven Burrowsa145e102017-06-16 13:37:50 -04008
9const GUI_BASE = '../../web/gui/src/main/webapp/';
10const 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
26const 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 Burrows96ee21e2017-07-11 19:49:45 +010032 'tp/Chart.js',
Steven Burrowsa145e102017-06-16 13:37:50 -040033 'tp/lodash.min.js',
34];
35
36function bundle(files, exportName) {
Steven Burrows1c2a9682017-07-14 16:52:46 +010037
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 Burrows0f26ac82017-08-07 22:36:36 +010046 .on('end', () => { reload(); })
Steven Burrows1c2a9682017-07-14 16:52:46 +010047 }
48
Steven Burrowsa145e102017-06-16 13:37:50 -040049 return gulp.src(BundleResources(GUI_BASE, files))
50 .pipe(sourceMaps.init())
51 .pipe(strip())
52 .pipe(uglyfy())
Steven Burrowsdc165622017-07-20 14:40:27 +010053 .on('error', (e, file, line) => console.error(e))
Steven Burrowsa145e102017-06-16 13:37:50 -040054 .pipe(concat(exportName))
55 .pipe(sourceMaps.write('source-map'))
56 .pipe(gulp.dest(GUI_BASE + '/dist/'));
57}
58
59const tasks = function () {
Steven Burrows1c2a9682017-07-14 16:52:46 +010060 // gulp.task('bundle-vendor', () => bundle(vendor, 'vendor.js'));
Steven Burrowsa145e102017-06-16 13:37:50 -040061 gulp.task('bundle-js', () => bundle(bundleFiles, 'onos.js'));
Steven Burrows1c2a9682017-07-14 16:52:46 +010062 gulp.task('watch-js', () => {
Steven Burrows4b4d2b42017-08-16 14:11:23 +010063 gulp.watch([GUI_BASE + 'app/**/*.js'], ['bundle-js']);
Steven Burrows1c2a9682017-07-14 16:52:46 +010064 }).on('change', (event) => {
65 console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
66 });
Steven Burrowsa145e102017-06-16 13:37:50 -040067};
68
69export default tasks();