gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-merchant-backoffice] branch master updated: mocking 'window' to d


From: gnunet
Subject: [taler-merchant-backoffice] branch master updated: mocking 'window' to development server
Date: Thu, 03 Feb 2022 10:54:24 +0100

This is an automated email from the git hooks/post-receive script.

ms pushed a commit to branch master
in repository merchant-backoffice.

The following commit(s) were added to refs/heads/master by this push:
     new 2e91bf5  mocking 'window' to development server
2e91bf5 is described below

commit 2e91bf53cea553a6db5eb9ef46109388923fe849
Author: ms <ms@taler.net>
AuthorDate: Thu Feb 3 10:54:15 2022 +0100

    mocking 'window' to development server
---
 packages/bank/mocks/json-server/db.json     |  6 +++
 packages/bank/mocks/json-server/routes.json |  4 ++
 packages/bank/mocks/window.js               | 24 +++++++++++
 packages/bank/package.json                  |  4 +-
 packages/bank/preact.mock.js                | 47 ++++++++++++++++++++++
 packages/bank/preact.single-config.js       | 62 +++++++++++++++++++++++++++++
 packages/bank/remove-link-stylesheet.sh     |  8 ++++
 7 files changed, 153 insertions(+), 2 deletions(-)

diff --git a/packages/bank/mocks/json-server/db.json 
b/packages/bank/mocks/json-server/db.json
new file mode 100644
index 0000000..f10a7a7
--- /dev/null
+++ b/packages/bank/mocks/json-server/db.json
@@ -0,0 +1,6 @@
+{
+  "register": {
+    "{\"hey\": \"you\"}": ""
+  },
+  "transactions": {}
+}
\ No newline at end of file
diff --git a/packages/bank/mocks/json-server/routes.json 
b/packages/bank/mocks/json-server/routes.json
new file mode 100644
index 0000000..fe0163b
--- /dev/null
+++ b/packages/bank/mocks/json-server/routes.json
@@ -0,0 +1,4 @@
+{
+  "/access-api/testing/register": "/register",
+  "/access-api/accounts/:accountName/transactions\\?page=:pageNumber": 
"/transactions"
+}
diff --git a/packages/bank/mocks/window.js b/packages/bank/mocks/window.js
new file mode 100644
index 0000000..dc805a6
--- /dev/null
+++ b/packages/bank/mocks/window.js
@@ -0,0 +1,24 @@
+Object.defineProperty(window, 'localStorage', {
+  value: {
+    store: {},
+    getItem: function(key) {
+      return this.store[key];
+    },
+    setItem: function(key, value) {
+      return this.store[key] = value;
+    },
+    clear: function() {
+      this.store = {};
+    }
+  }
+});
+
+Object.defineProperty(window, 'location', {
+  value: {
+    origin: "http://localhost:5000";,
+    search: "",
+    pathname: "/demobanks/default",
+  }
+})
+
+export default window;
diff --git a/packages/bank/package.json b/packages/bank/package.json
index e1155a3..18c6adc 100644
--- a/packages/bank/package.json
+++ b/packages/bank/package.json
@@ -4,8 +4,8 @@
   "version": "0.1.0",
   "license": "MIT",
   "scripts": {
-    "dev": "preact watch --port ${PORT:=8080} --no-sw --no-esm",
-    "build": "preact build --no-sw --no-esm -c preact.single-config.js --dest 
single && sh remove-link-stylesheet.sh",
+    "dev": "preact watch --port ${PORT:=8080} --no-sw --no-esm -c 
preact.mock.js",
+    "build": "preact build --no-sw --no-esm -c preact.single-config.js --dest 
build && sh remove-link-stylesheet.sh",
     "serve": "sirv build --port ${PORT:=8080} --cors --single",
     "lint": "eslint 'src/**/*.{js,jsx,ts,tsx}'",
     "test": "jest ./tests",
diff --git a/packages/bank/preact.mock.js b/packages/bank/preact.mock.js
new file mode 100644
index 0000000..53274d8
--- /dev/null
+++ b/packages/bank/preact.mock.js
@@ -0,0 +1,47 @@
+/*
+ This file is part of GNU Taler
+ (C) 2021 Taler Systems S.A.
+
+ GNU Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+
+/**
+*
+* @author Sebastian Javier Marchano (sebasjm)
+*/
+
+import { DefinePlugin, ProvidePlugin } from 'webpack';
+
+import pack from './package.json';
+import * as cp from 'child_process';
+
+const commitHash = cp.execSync('git rev-parse --short HEAD').toString();
+import path from 'path';
+
+export default {
+  webpack(config, env, helpers) {
+    // Ensure that process.env will not be undefined at runtime.
+    config.node.process = 'mock'
+
+    // Add __VERSION__ to be use in the html.
+    config.plugins.push(
+      new DefinePlugin({
+        'process.env.__VERSION__': JSON.stringify(env.isProd ? pack.version : 
`dev-${commitHash}`) ,
+      }),
+      // 'window' gets mocked to point at a running euFin instance.
+      new ProvidePlugin({window: path.resolve("mocks/window")})
+    );
+
+    let { index } = helpers.getPluginsByName(config, 
'WebpackFixStyleOnlyEntriesPlugin')[0]
+    config.plugins.splice(index, 1)   
+  }
+}
diff --git a/packages/bank/preact.single-config.js 
b/packages/bank/preact.single-config.js
new file mode 100644
index 0000000..61a79bb
--- /dev/null
+++ b/packages/bank/preact.single-config.js
@@ -0,0 +1,62 @@
+/*
+ This file is part of GNU Taler
+ (C) 2021 Taler Systems S.A.
+
+ GNU Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+
+/**
+*
+* @author Sebastian Javier Marchano (sebasjm)
+*/
+
+import defaultConfig from './preact.config'
+
+export default {
+  webpack(config, env, helpers, options) {
+    defaultConfig.webpack(config, env, helpers, options)
+
+    //1. check no file is under /routers or /component/{routers,async} to 
prevent async components
+    // https://github.com/preactjs/preact-cli#route-based-code-splitting
+
+    //2. remove devtools to prevent sourcemaps
+    config.devtool = false
+
+    //3. change assetLoader to load assets inline
+    const loaders = helpers.getLoaders(config)
+    const assetsLoader = loaders.find(lo => 
lo.rule.test.test('something.woff'))
+    if (assetsLoader) {
+      assetsLoader.rule.use = 'base64-inline-loader'
+      assetsLoader.rule.loader = undefined
+    }
+
+    //4. remove critters
+    //critters remove the css bundle from htmlWebpackPlugin.files.css
+    //for now, pushing all the content into the html is enough
+    const crittersWrapper = helpers.getPluginsByName(config, 'Critters')
+    if (crittersWrapper && crittersWrapper.length > 0) {
+      const [{ index }] = crittersWrapper
+      config.plugins.splice(index, 1)
+    }
+
+    //5. remove favicon from src/assets
+
+    //6. remove performance hints since we now that this is going to be big
+    if (config.performance) {
+      config.performance.hints = false
+    }
+
+    //7. template.html should have a favicon and add js/css content
+
+    //last, after building remove the mysterious link to stylesheet with 
remove-link-stylesheet.sh
+  }
+}
diff --git a/packages/bank/remove-link-stylesheet.sh 
b/packages/bank/remove-link-stylesheet.sh
new file mode 100755
index 0000000..d3376b8
--- /dev/null
+++ b/packages/bank/remove-link-stylesheet.sh
@@ -0,0 +1,8 @@
+# This script has been placed in the public domain.
+
+FILE=$(ls build/bundle.*.css)
+BUNDLE=${FILE#build}
+grep -q '<link href="'$BUNDLE'" rel="stylesheet">' build/index.html || { echo 
bundle $BUNDLE not found in index.html; exit 1; }
+echo -n Removing link from index.html ...
+sed 's_<link href="'$BUNDLE'" rel="stylesheet">__' -i build/index.html
+echo done

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]