blob: 135ee9f02af81d6a8b75039631a864afe73fd89b [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' }),
Steven Burrows1270c182017-09-14 10:14:58 +010045 proxy(['**/*.css'], { target: 'http://localhost:8189' }),
Steven Burrows1c2a9682017-07-14 16:52:46 +010046 proxy('**/*.js.map', {
47 target: 'http://localhost:8189',
48 changeOrigin: true,
49 logLevel: 'debug'
50 })
51 ]
52 }
53 });
54};
55
56const tasks = () => {
57 gulp.task('serve', ['bundle-js', 'proxy-server'], serve);
58 gulp.task('proxy-server', function () {
59 gulp.src('../../web/gui/src/main/webapp')
60 .pipe(webserver({
61 port: 8189,
62 path: '/onos/ui/'
63 }));
64 });
65};
66
67export default tasks();
68
69export function reload() {
70 if (bs) {
71 bs.reload();
72 }
73}
74