blob: 119c3f21db0e4e7cf62cb9b59a8c6a7f12ab6b15 [file] [log] [blame]
Steven Burrows1c2a9682017-07-14 16:52:46 +01001import gulp from 'gulp';
2import browserSync from 'browser-sync';
3import fs from 'fs';
4import webserver from 'gulp-webserver';
5import proxy from 'http-proxy-middleware';
6
7let external_apps;
8let bs = null;
9
10const files = ['../../web/gui/src/main/webapp/**/*.js'];
11const defaultViews = fs.readdirSync('../../web/gui/src/main/webapp/app/view/');
12const viewNameMatcher = new RegExp(/\/onos\/ui\/app\/view\/(.+)\/.+\.(?:js|css|html)/);
13
14if (process.env.ONOS_EXTERNAL_APP_DIRS) {
15 let external_apps = process.env.ONOS_EXTERNAL_APP_DIRS.replace(/\s/,'').split(',');
16
17 external_apps = external_apps.reduce(function (dict, app) {
18 const pieces = app.split(':');
19 const appName = pieces[0];
20 const appPath = pieces[1];
21 dict[appName] = appPath;
22 return dict;
23 }, {});
24}
25
26const checkExternalApp = (url) => {
27 if(external_apps){
28 for(let i = 0; i < Object.keys(external_apps).length; i++){
29 const key = Object.keys(external_apps)[i];
30 if (url.indexOf(key) !== -1) {
31 return key;
32 }
33 }
34 }
35 return false;
36};
37
38const serve = () => {
39 bs = browserSync.init({
40 proxy: {
41 target: 'http://localhost:8181',
42 ws: true,
43 middleware: [
44 proxy(['**/*.js', '!/onos/ui/onos.js'], { target: 'http://localhost:8189' }),
45 proxy('**/*.js.map', {
46 target: 'http://localhost:8189',
47 changeOrigin: true,
48 logLevel: 'debug'
49 })
50 ]
51 }
52 });
53};
54
55const tasks = () => {
56 gulp.task('serve', ['bundle-js', 'proxy-server'], serve);
57 gulp.task('proxy-server', function () {
58 gulp.src('../../web/gui/src/main/webapp')
59 .pipe(webserver({
60 port: 8189,
61 path: '/onos/ui/'
62 }));
63 });
64};
65
66export default tasks();
67
68export function reload() {
69 if (bs) {
70 bs.reload();
71 }
72}
73