blob: 2292775b6c860f771e68a3f727959d963746d4d0 [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 Burrows1c2a9682017-07-14 16:52:46 +01007import { reload } from '../../dev-server';
Steven Burrowsa145e102017-06-16 13:37:50 -04008
9
10const GUI_BASE = '../../web/gui/src/main/webapp/';
11const bundleFiles = [
12 // NOTE: Bundle the important files first
13 'app/directives.js',
14 'app/fw/util/util.js',
15 'app/fw/mast/mast.js',
16 'app/fw/nav/nav.js',
17 'app/fw/svg/svg.js',
18 'app/fw/remote/remote.js',
19 'app/fw/widget/widget.js',
20 'app/fw/layer/layer.js',
21
22 // NOTE: bundle everything else
23 'app/fw/**/*.js',
24 'app/view/**/*.js'
25];
26
27const vendor = [
28 'tp/angular.js',
29 'tp/angular-route.js',
30 'tp/angular-cookies.js',
31 'tp/d3.js',
32 'tp/topojson.v1.min.js',
Steven Burrows96ee21e2017-07-11 19:49:45 +010033 'tp/Chart.js',
Steven Burrowsa145e102017-06-16 13:37:50 -040034 'tp/lodash.min.js',
35];
36
37function bundle(files, exportName) {
Steven Burrows1c2a9682017-07-14 16:52:46 +010038
39 // TODO: Use util.noop once npm issues have been resolved
40 if (process.argv.indexOf('--development') > -1) {
41 return gulp.src(BundleResources(GUI_BASE, files))
42 .pipe(sourceMaps.init())
43 .on('error', (e, file, line) => console.error(e))
44 .pipe(concat(exportName))
45 .pipe(sourceMaps.write('source-map'))
46 .pipe(gulp.dest(GUI_BASE + '/dist/'))
47 .on('end', () => { reload(); })
48 }
49
Steven Burrowsa145e102017-06-16 13:37:50 -040050 return gulp.src(BundleResources(GUI_BASE, files))
51 .pipe(sourceMaps.init())
52 .pipe(strip())
53 .pipe(uglyfy())
Steven Burrowsdc165622017-07-20 14:40:27 +010054 .on('error', (e, file, line) => console.error(e))
Steven Burrowsa145e102017-06-16 13:37:50 -040055 .pipe(concat(exportName))
56 .pipe(sourceMaps.write('source-map'))
57 .pipe(gulp.dest(GUI_BASE + '/dist/'));
58}
59
60const tasks = function () {
Steven Burrows1c2a9682017-07-14 16:52:46 +010061 // gulp.task('bundle-vendor', () => bundle(vendor, 'vendor.js'));
Steven Burrowsa145e102017-06-16 13:37:50 -040062 gulp.task('bundle-js', () => bundle(bundleFiles, 'onos.js'));
Steven Burrows1c2a9682017-07-14 16:52:46 +010063 gulp.task('watch-js', () => {
64 gulp.watch([GUI_BASE + '**/*.js', `!${GUI_BASE}/dist/**/*`], ['bundle-js']);
65 }).on('change', (event) => {
66 console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
67 });
Steven Burrowsa145e102017-06-16 13:37:50 -040068};
69
70export default tasks();