From 075c5c0fef9ca9cf9d5f60588f46efd4ca4a5f73 Mon Sep 17 00:00:00 2001
From: Patrizio Bekerle <patrizio.bekerle@tugraz.at>
Date: Mon, 30 Sep 2019 15:48:09 +0200
Subject: [PATCH] Merge branch 'master' of
 gitlab.tugraz.at:VPU/WebComponents/Notification

---
 packages/notification/assets/index.html       |  2 +-
 packages/notification/karma.conf.js           |  2 +-
 packages/notification/package.json            | 16 +++---
 packages/notification/rollup.config.js        | 55 ++++++++++++++-----
 packages/notification/src/utils.js            |  3 +-
 .../notification/src/vpu-notification-demo.js |  8 +--
 packages/notification/src/vpu-notification.js |  7 ++-
 packages/notification/vendor/common           |  2 +-
 8 files changed, 65 insertions(+), 30 deletions(-)

diff --git a/packages/notification/assets/index.html b/packages/notification/assets/index.html
index 9c6e2568..aba5bddd 100644
--- a/packages/notification/assets/index.html
+++ b/packages/notification/assets/index.html
@@ -2,7 +2,7 @@
 <html>
 <head>
     <meta charset="UTF-8">
-    <script type="module" id="vpu-notification-wc-src" src="bundle.js"></script>
+    <script type="module" id="vpu-notification-src" src="bundle.js"></script>
 </head>
 
 <body>
diff --git a/packages/notification/karma.conf.js b/packages/notification/karma.conf.js
index 901e0780..6a646f5e 100644
--- a/packages/notification/karma.conf.js
+++ b/packages/notification/karma.conf.js
@@ -6,7 +6,7 @@ module.exports = function(config) {
     basePath: 'dist',
     frameworks: ['mocha', 'chai'],
     files: [
-      './bundle.js',
+      {pattern: './*.js', included: true, watched: true, served: true, type: 'module'},
       {pattern: './**/*', included: false, watched: true, served: true},
     ],
     autoWatch: true,
diff --git a/packages/notification/package.json b/packages/notification/package.json
index 26902720..f120a394 100644
--- a/packages/notification/package.json
+++ b/packages/notification/package.json
@@ -11,20 +11,22 @@
     "puppeteer": "^1.15.0",
     "mocha": "^6.2.0",
     "chai": "^4.2.0",
-    "rollup": "^1.11.3",
-    "rollup-plugin-commonjs": "^9.3.4",
-    "rollup-plugin-copy": "^2.0.1",
-    "rollup-plugin-node-resolve": "^4.2.3",
-    "rollup-plugin-postcss": "^2.0.3",
+    "rollup": "^1.20.3",
+    "rollup-plugin-commonjs": "^10.0.2",
+    "rollup-plugin-consts": "^1.0.1",
+    "rollup-plugin-copy": "^3.1.0",
+    "rollup-plugin-delete": "^1.1.0",
+    "rollup-plugin-node-resolve": "^5.2.0",
     "rollup-plugin-serve": "^1.0.1",
-    "rollup-plugin-terser": "^4.0.4",
+    "rollup-plugin-terser": "^5.1.1",
     "rollup-plugin-json": "^4.0.0",
     "rollup-plugin-multi-entry": "^2.1.0",
-    "rollup-plugin-replace": "^2.2.0",
+    "rollup-plugin-url": "^2.2.2",
     "i18next-scanner": "^2.10.2",
     "vpu-common": "file:./vendor/common"
   },
   "dependencies": {
+    "bulma": "^0.7.5",
     "lit-element": "^2.1.0"
   },
   "scripts": {
diff --git a/packages/notification/rollup.config.js b/packages/notification/rollup.config.js
index 92e6250b..7bb210bc 100644
--- a/packages/notification/rollup.config.js
+++ b/packages/notification/rollup.config.js
@@ -1,17 +1,40 @@
 import path from 'path';
 import resolve from 'rollup-plugin-node-resolve';
 import commonjs from 'rollup-plugin-commonjs';
-import postcss from 'rollup-plugin-postcss';
 import copy from 'rollup-plugin-copy';
 import {terser} from "rollup-plugin-terser";
 import json from 'rollup-plugin-json';
-import replace from "rollup-plugin-replace";
 import serve from 'rollup-plugin-serve';
 import multiEntry from 'rollup-plugin-multi-entry';
+import url from "rollup-plugin-url";
+import consts from 'rollup-plugin-consts';
+import del from 'rollup-plugin-delete';
 
+const pkg = require('./package.json');
 const build = (typeof process.env.BUILD !== 'undefined') ? process.env.BUILD : 'local';
 console.log("build: " + build);
 
+let manualChunks = Object.keys(pkg.dependencies).reduce(function (acc, item) { acc[item] = [item]; return acc;}, {});
+manualChunks = Object.keys(pkg.devDependencies).reduce(function (acc, item) { if (item.startsWith('vpu-')) acc[item] = [item]; return acc;}, manualChunks);
+
+function getBuildInfo() {
+    const child_process = require('child_process');
+    const url = require('url');
+
+    let remote = child_process.execSync('git config --get remote.origin.url').toString().trim();
+    let commit = child_process.execSync('git rev-parse --short HEAD').toString().trim();
+
+    let parsed = url.parse(remote);
+    let newPath = parsed.path.slice(0, parsed.path.lastIndexOf('.'))
+    let newUrl = parsed.protocol + '//' + parsed.host + newPath + '/commit/' + commit;
+
+    return {
+        info: commit,
+        url: newUrl,
+        env: build
+    }
+}
+
 export default {
     input: (build != 'test') ? 'src/demo.js' : 'test/**/*.js',
     output: {
@@ -19,7 +42,13 @@ export default {
         format: 'esm'
     },
     plugins: [
+        del({
+            targets: 'dist/*'
+        }),
         multiEntry(),
+        consts({
+            environment: build,
+        }),
         resolve({
           customResolveOptions: {
             // ignore node_modules from vendored packages
@@ -30,21 +59,21 @@ export default {
             include: 'node_modules/**'
         }),
         json(),
-        replace({
-            "process.env.BUILD": '"' + build + '"',
-        }),
-        postcss({
-            inject: false,
-            minimize: false,
-            plugins: []
+        url({
+            limit: 0,
+            include: [
+                "node_modules/bulma/**/*.css",
+                "node_modules/bulma/**/*.sass",
+            ],
+            emitFiles: true,
+            fileName: 'shared/[name].[hash][extname]'
         }),
         (build !== 'local' && build !== 'test') ? terser() : false,
         copy({
             targets: [
-                'assets/index.html',
-                'assets/favicon.ico'
-            ],
-            outputFolder: 'dist'
+                {src: 'assets/index.html', dest: 'dist'},
+                {src: 'assets/favicon.ico', dest: 'dist'},
+            ]
         }),
         (process.env.ROLLUP_WATCH === 'true') ? serve({contentBase: 'dist', host: '127.0.0.1', port: 8002}) : false
     ]
diff --git a/packages/notification/src/utils.js b/packages/notification/src/utils.js
index 92d5ba98..25e76d3e 100644
--- a/packages/notification/src/utils.js
+++ b/packages/notification/src/utils.js
@@ -7,4 +7,5 @@ export const createUUID = () => {
     });
 
     return uuid;
-}
+};
+
diff --git a/packages/notification/src/vpu-notification-demo.js b/packages/notification/src/vpu-notification-demo.js
index 113b63ed..3cb9a731 100644
--- a/packages/notification/src/vpu-notification-demo.js
+++ b/packages/notification/src/vpu-notification-demo.js
@@ -2,7 +2,8 @@ import {i18n} from './i18n';
 import {send as notify} from 'vpu-common/notification';
 import {html, LitElement} from 'lit-element';
 import './vpu-notification';
-import commonUtils from 'vpu-common/utils';
+import * as commonUtils from 'vpu-common/utils';
+import bulmaCSSPath from 'bulma/css/bulma.min.css';
 
 class NotificationDemo extends LitElement {
     constructor() {
@@ -25,10 +26,9 @@ class NotificationDemo extends LitElement {
     }
 
     render() {
+        const bulmaCSS = commonUtils.getAssetURL(bulmaCSSPath);
         return html`
-            <style>
-            </style>
-            <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.5/css/bulma.min.css">
+            <link rel="stylesheet" href="${bulmaCSS}">
 
             <section class="section">
                 <div class="container">
diff --git a/packages/notification/src/vpu-notification.js b/packages/notification/src/vpu-notification.js
index d9533455..7c86b260 100644
--- a/packages/notification/src/vpu-notification.js
+++ b/packages/notification/src/vpu-notification.js
@@ -2,7 +2,8 @@ import {i18n} from './i18n';
 import {createUUID} from './utils'
 import {html} from 'lit-element';
 import VPULitElement from 'vpu-common/vpu-lit-element';
-import commonUtils from 'vpu-common/utils';
+import * as commonUtils from 'vpu-common/utils';
+import bulmaCSSPath from 'bulma/css/bulma.min.css';
 
 /**
  * Notification web component
@@ -74,8 +75,10 @@ class VPUNotification extends VPULitElement {
     }
 
     render() {
+        commonUtils.initAssetBaseURL('vpu-notification-src');
+        const bulmaCSS = commonUtils.getAssetURL(bulmaCSSPath);
         return html`
-            <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.5/css/bulma.min.css">
+            <link rel="stylesheet" href="${bulmaCSS}">
             <style>
                 #notification {position: fixed; top: 0; max-width: 500px; margin: 0.75em auto; left: 0; right: 0; z-index: 1000; padding: 0;}
                 .notification h3 {font-weight: bold; margin-bottom: 3px;}
diff --git a/packages/notification/vendor/common b/packages/notification/vendor/common
index 378256b0..adbdf637 160000
--- a/packages/notification/vendor/common
+++ b/packages/notification/vendor/common
@@ -1 +1 @@
-Subproject commit 378256b0ae92712fd5b8feed3a987cd014617c0b
+Subproject commit adbdf63736ba48eaf93ca06f83ee3652b7f85f12
-- 
GitLab