blob: f0dddf7f00dcc608381da740aae620c949cc92fd [file] [log] [blame]
Steven Burrows46c5f102017-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
7console.log(proxy)
8
9let external_apps;
10
11const files = ['../../web/gui/src/main/webapp/**/*.js'];
12const defaultViews = fs.readdirSync('../../web/gui/src/main/webapp/app/view/');
13const viewNameMatcher = new RegExp(/\/onos\/ui\/app\/view\/(.+)\/.+\.(?:js|css|html)/);
14
15if (process.env.ONOS_EXTERNAL_APP_DIRS) {
16 let external_apps = process.env.ONOS_EXTERNAL_APP_DIRS.replace(/\s/,'').split(',');
17
18 external_apps = external_apps.reduce(function (dict, app) {
19 const pieces = app.split(':');
20 const appName = pieces[0];
21 const appPath = pieces[1];
22 dict[appName] = appPath;
23 return dict;
24 }, {});
25}
26
27const checkExternalApp = (url) => {
28 if(external_apps){
29 for(let i = 0; i < Object.keys(external_apps).length; i++){
30 const key = Object.keys(external_apps)[i];
31 if (url.indexOf(key) !== -1) {
32 return key;
33 }
34 }
35 }
36 return false;
37};
38
39const serve = () => {
40 browserSync.init({
41 proxy: {
42 target: 'http://localhost:8181',
43 ws: true,
44 middleware: [
45 proxy(['**/*.js', '!/onos/ui/onos.js'], { target: 'http://localhost:8189' }),
46 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
69