Generating TOSCA recipes for dashboard in generator-xos

Change-Id: I507ffc35e1499c8377d86e0cd6dd952b0d19d404
diff --git a/views/ngXosLib/generator-xos/app/templates/gulp/build.js b/views/ngXosLib/generator-xos/app/templates/gulp/build.js
index 88d88d3..f916212 100644
--- a/views/ngXosLib/generator-xos/app/templates/gulp/build.js
+++ b/views/ngXosLib/generator-xos/app/templates/gulp/build.js
@@ -26,6 +26,8 @@
 var autoprefixer = require('autoprefixer');
 var mqpacker = require('css-mqpacker');
 var csswring = require('csswring');
+var yaml = require('js-yaml');
+var colors = require('colors/safe');
 
 const TEMPLATE_FOOTER = `
 angular.module('xos.<%= name %>')
@@ -155,6 +157,47 @@
     }, 1000);
   });
 
+  gulp.task('tosca', function (cb) {
+
+    // TOSCA to register the dashboard in the system
+    const dashboardJson = {};
+    dashboardJson['<%= fileName %>'] = {
+      type: 'tosca.nodes.DashboardView',
+      properties: {
+        url: 'template:xos<%= fileName %>'
+      }
+    };
+    const dashboardTosca = yaml.dump(dashboardJson).replace(/'/gmi, '');
+
+    // TOSCA to add the dashboard to the user
+    const userDashboardJson = {};
+    userDashboardJson['<%= name %>_dashboard'] = {
+      node: '<%= fileName %>',
+      relationship: 'tosca.relationships.UsesDashboard'
+    };
+    const userJson = {
+      'padmin@vicci.org': {
+        type: 'tosca.nodes.User',
+        properties: {
+          'no-create': true,
+          'no-delete': true
+        },
+        requirements: [userDashboardJson]
+      }
+    };
+    const userTosca = yaml.dump(userJson).replace(/'/gmi, '');
+
+
+    // the output is in a timeout so that it get printed after the gulp logs
+    setTimeout(function () {
+      console.log(colors.cyan('\n\n# You can use this recipe to load the dashboard in the system:'));
+      console.log(colors.yellow(dashboardTosca));
+      console.log(colors.cyan('# And this recipe to activate the dashboard for a user:'));
+      console.log(colors.yellow(userTosca));
+    }, 1000);
+    cb();
+  });
+
   gulp.task('build', function() {
     runSequence(
       'clean',
@@ -167,7 +210,8 @@
       'copyCss',
       'copyImages',
       'copyHtml',
-      'cleanTmp'
+      'cleanTmp',
+      'tosca'
     );
   });
 };
\ No newline at end of file
diff --git a/views/ngXosLib/generator-xos/app/templates/package.json b/views/ngXosLib/generator-xos/app/templates/package.json
index 0705f5d..4ef6a73 100644
--- a/views/ngXosLib/generator-xos/app/templates/package.json
+++ b/views/ngXosLib/generator-xos/app/templates/package.json
@@ -5,6 +5,7 @@
   "scripts": {
     "prestart": "npm install && bower install",
     "start": "gulp serve",
+    "tosca": "gulp tosca",
     "prebuild": "npm install && bower install",
     "build": "gulp",
     "test": "karma start",
@@ -22,6 +23,7 @@
   "devDependencies": {
     "autoprefixer": "^6.3.3",
     "browser-sync": "^2.9.11",
+    "colors": "^1.1.2",
     "css-mqpacker": "^4.0.0",
     "csswring": "^4.2.1",
     "del": "^2.0.2",
@@ -46,6 +48,7 @@
     "http-proxy": "^1.12.0",
     "ink-docstrap": "^0.5.2",
     "jasmine-core": "~2.3.4",
+    "js-yaml": "^3.6.1",
     "karma": "^0.13.14",
     "karma-babel-preprocessor": "~5.2.2",
     "karma-coverage": "^0.5.3",
diff --git a/views/ngXosViews/truckroll/gulp/build.js b/views/ngXosViews/truckroll/gulp/build.js
index 5878b31..d71151b 100644
--- a/views/ngXosViews/truckroll/gulp/build.js
+++ b/views/ngXosViews/truckroll/gulp/build.js
@@ -26,6 +26,8 @@
 var autoprefixer = require('autoprefixer');
 var mqpacker = require('css-mqpacker');
 var csswring = require('csswring');
+var yaml = require('js-yaml');
+var colors = require('colors/safe');
 
 const TEMPLATE_FOOTER = `
 angular.module('xos.truckroll')
@@ -155,6 +157,47 @@
     }, 1000);
   });
 
+  gulp.task('tosca', function (cb) {
+
+    // TOSCA to register the dashboard in the system
+    const dashboardJson = {};
+    dashboardJson['Truckroll'] = {
+      type: 'tosca.nodes.DashboardView',
+      properties: {
+        url: 'template:xosTruckroll'
+      }
+    };
+    const dashboardTosca = yaml.dump(dashboardJson).replace(/'/gmi, '');
+
+    // TOSCA to add the dashboard to the user
+    const userDashboardJson = {};
+    userDashboardJson['truckroll_dashboard'] = {
+      node: 'Truckroll',
+      relationship: 'tosca.relationships.UsesDashboard'
+    };
+    const userJson = {
+      'padmin@vicci.org': {
+        type: 'tosca.nodes.User',
+        properties: {
+          'no-create': true,
+          'no-delete': true
+        },
+        requirements: [userDashboardJson]
+      }
+    };
+    const userTosca = yaml.dump(userJson).replace(/'/gmi, '');
+
+
+    // the output is in a timeout so that it get printed after the gulp logs
+    setTimeout(function () {
+      console.log(colors.cyan('\n\n# You can use this recipe to load the dashboard in the system:'));
+      console.log(colors.yellow(dashboardTosca));
+      console.log(colors.cyan('# And this recipe to activate the dashboard for a user:'));
+      console.log(colors.yellow(userTosca));
+    }, 1000);
+    cb();
+  });
+
   gulp.task('build', function() {
     runSequence(
       'clean',
@@ -167,7 +210,8 @@
       'copyCss',
       'copyImages',
       'copyHtml',
-      'cleanTmp'
+      'cleanTmp',
+      'tosca'
     );
   });
 };
\ No newline at end of file
diff --git a/views/ngXosViews/truckroll/gulp/server.js b/views/ngXosViews/truckroll/gulp/server.js
index 3b1ee04..36fdded 100644
--- a/views/ngXosViews/truckroll/gulp/server.js
+++ b/views/ngXosViews/truckroll/gulp/server.js
@@ -55,7 +55,6 @@
           '/xos/core/static': options.static + '../../static/'
         },
         middleware: function(req, res, next){
-
           if(
             req.url.indexOf('/api/') !== -1
           ){
diff --git a/views/ngXosViews/truckroll/package.json b/views/ngXosViews/truckroll/package.json
index f397ff0..dbfc895 100644
--- a/views/ngXosViews/truckroll/package.json
+++ b/views/ngXosViews/truckroll/package.json
@@ -5,6 +5,7 @@
   "scripts": {
     "prestart": "npm install && bower install",
     "start": "gulp serve",
+    "tosca": "gulp tosca",
     "prebuild": "npm install && bower install",
     "build": "gulp",
     "test": "karma start",
@@ -22,6 +23,7 @@
   "devDependencies": {
     "autoprefixer": "^6.3.3",
     "browser-sync": "^2.9.11",
+    "colors": "^1.1.2",
     "css-mqpacker": "^4.0.0",
     "csswring": "^4.2.1",
     "del": "^2.0.2",
@@ -46,6 +48,7 @@
     "http-proxy": "^1.12.0",
     "ink-docstrap": "^0.5.2",
     "jasmine-core": "~2.3.4",
+    "js-yaml": "^3.6.1",
     "karma": "^0.13.14",
     "karma-babel-preprocessor": "~5.2.2",
     "karma-coverage": "^0.5.3",