Factor some lines (raw loading pug files)
authorBenjamin Auder <benjamin.auder@somewhere>
Fri, 20 Nov 2020 21:17:47 +0000 (22:17 +0100)
committerBenjamin Auder <benjamin.auder@somewhere>
Fri, 20 Nov 2020 21:17:47 +0000 (22:17 +0100)
client/package-lock.json
client/package.json
client/src/utils/afterRawLoad.js [new file with mode: 0644]
client/src/views/Analyse.vue
client/src/views/Faq.vue
client/src/views/Game.vue
client/src/views/Problems.vue
client/src/views/Rules.vue
client/src/views/Variants.vue

index 954dad6..d50195c 100644 (file)
       }
     },
     "@vue/cli-overlay": {
-      "version": "4.5.8",
-      "resolved": "https://registry.npmjs.org/@vue/cli-overlay/-/cli-overlay-4.5.8.tgz",
-      "integrity": "sha512-M6q4QPKQfErHk54ycxBASgBadgdsK45f6v2NWUTAiFXdTtqv1Z7gR8JAbQhiXbni/m9571bLJnZFv5c8uhAHnw==",
+      "version": "4.5.9",
+      "resolved": "https://registry.npmjs.org/@vue/cli-overlay/-/cli-overlay-4.5.9.tgz",
+      "integrity": "sha512-E2PWv6tCdUz+eEDj2Th2oxiKmzMe02qi0PcxiNaO7oaqggmEOrp1rLgop7DWpiLDBiqUZk2x0vjK/q2Tz8z/eg==",
       "dev": true
     },
     "@vue/cli-plugin-eslint": {
-      "version": "4.5.8",
-      "resolved": "https://registry.npmjs.org/@vue/cli-plugin-eslint/-/cli-plugin-eslint-4.5.8.tgz",
-      "integrity": "sha512-1lg3K2D/harXbN4FvRoA1b0X9947H+G4Ql/43rxJY39OqswfK/d1ck438Fo9M4l1+zhBSUNDmcjn7Q2EH6qWmA==",
+      "version": "4.5.9",
+      "resolved": "https://registry.npmjs.org/@vue/cli-plugin-eslint/-/cli-plugin-eslint-4.5.9.tgz",
+      "integrity": "sha512-wTsWRiRWPW5ik4bgtlh4P4h63Zgjsyvqx2FY0kcj+bSAnQGPJ3bKUOMU9KQP5EyNH6pAXMVGh2LEXK9WwJMf1w==",
       "dev": true,
       "requires": {
-        "@vue/cli-shared-utils": "^4.5.8",
+        "@vue/cli-shared-utils": "^4.5.9",
         "eslint-loader": "^2.2.1",
         "globby": "^9.2.0",
         "inquirer": "^7.1.0",
       }
     },
     "@vue/cli-plugin-router": {
-      "version": "4.5.8",
-      "resolved": "https://registry.npmjs.org/@vue/cli-plugin-router/-/cli-plugin-router-4.5.8.tgz",
-      "integrity": "sha512-tJwVLdX4jj0Ia/1hsBejRbo4gs0hb2z1z5ert+4Ve5RNdpOKUG69OaPQgXPqvuYSQh9MW7bqG0iJmYtVD+KBNw==",
+      "version": "4.5.9",
+      "resolved": "https://registry.npmjs.org/@vue/cli-plugin-router/-/cli-plugin-router-4.5.9.tgz",
+      "integrity": "sha512-eBBfbZpQ1sJrdlx8i7iReFxSnuzwmrv+s2OCT3kjBd6uWRqGnD4VihpS4srC7vZLzDQrDplumSn0a93L9Qf3wQ==",
       "dev": true,
       "requires": {
-        "@vue/cli-shared-utils": "^4.5.8"
+        "@vue/cli-shared-utils": "^4.5.9"
       }
     },
     "@vue/cli-plugin-vuex": {
-      "version": "4.5.8",
-      "resolved": "https://registry.npmjs.org/@vue/cli-plugin-vuex/-/cli-plugin-vuex-4.5.8.tgz",
-      "integrity": "sha512-wU9WPhay1zBxtdd/HLRYhFRLBbG9lw3YTBJep9sTnYwUeXiEgum4O88Q2j6cwBBPPHMgeMrKMPHS85Jf4hMc0g==",
+      "version": "4.5.9",
+      "resolved": "https://registry.npmjs.org/@vue/cli-plugin-vuex/-/cli-plugin-vuex-4.5.9.tgz",
+      "integrity": "sha512-mFNIJhYiJjzCgytkDHX00ROy5Yzl7prkZpUbeDE0biwcLteMf2s3qZVbESOQl6GcviqcfEt2f3tHQQtLNa+OLg==",
       "dev": true
     },
     "@vue/cli-service": {
-      "version": "4.5.8",
-      "resolved": "https://registry.npmjs.org/@vue/cli-service/-/cli-service-4.5.8.tgz",
-      "integrity": "sha512-YcVEJvA5vQOcfRzhCQDfHxRW9WHvKqlQeiuSvNddfV2uQqKD3ifhsNYiZZuFvbev9qgRUmtmxSafpwYzj/LLBw==",
+      "version": "4.5.9",
+      "resolved": "https://registry.npmjs.org/@vue/cli-service/-/cli-service-4.5.9.tgz",
+      "integrity": "sha512-E3XlfM0q+UnnjbC9rwLIWNo2umZCRwnlMJY0KOhY1hFvqisGIYzFmQQ4o01KGyTx2BZNMuQg7Kw+BZ5gyM1Wig==",
       "dev": true,
       "requires": {
         "@intervolga/optimize-cssnano-plugin": "^1.0.5",
         "@types/minimist": "^1.2.0",
         "@types/webpack": "^4.0.0",
         "@types/webpack-dev-server": "^3.11.0",
-        "@vue/cli-overlay": "^4.5.8",
-        "@vue/cli-plugin-router": "^4.5.8",
-        "@vue/cli-plugin-vuex": "^4.5.8",
-        "@vue/cli-shared-utils": "^4.5.8",
+        "@vue/cli-overlay": "^4.5.9",
+        "@vue/cli-plugin-router": "^4.5.9",
+        "@vue/cli-plugin-vuex": "^4.5.9",
+        "@vue/cli-shared-utils": "^4.5.9",
         "@vue/component-compiler-utils": "^3.1.2",
         "@vue/preload-webpack-plugin": "^1.1.0",
         "@vue/web-component-wrapper": "^1.2.0",
       }
     },
     "@vue/cli-shared-utils": {
-      "version": "4.5.8",
-      "resolved": "https://registry.npmjs.org/@vue/cli-shared-utils/-/cli-shared-utils-4.5.8.tgz",
-      "integrity": "sha512-pa6oenhBO/5HeDLRSokiwVN01gROACEDy3ESXWuPmragOREGNmmFKtkPHlqeYavGEX6LFp7f0VK3uMX6UYS5mQ==",
+      "version": "4.5.9",
+      "resolved": "https://registry.npmjs.org/@vue/cli-shared-utils/-/cli-shared-utils-4.5.9.tgz",
+      "integrity": "sha512-anvsrv+rkQC+hgxaT2nQQxnSWSsIzyysZ36LO7qPjXvDRBvcvKLAAviFlUkYbZ+ntbV8puzJ3zw+gUhQw4SEVA==",
       "dev": true,
       "requires": {
         "@hapi/joi": "^15.0.1",
       "dev": true
     },
     "electron-to-chromium": {
-      "version": "1.3.596",
-      "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.596.tgz",
-      "integrity": "sha512-nLO2Wd2yU42eSoNJVQKNf89CcEGqeFZd++QsnN2XIgje1s/19AgctfjLIbPORlvcCO8sYjLwX4iUgDdusOY8Sg==",
+      "version": "1.3.597",
+      "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.597.tgz",
+      "integrity": "sha512-VJI21MucKaqyFw0oe3j9BIg+nDF4MHzUZAmUwZzrxho+s8zPCD13Fds07Rgu+MTtAadO4tYTKFdAUksKYUyIJw==",
       "dev": true
     },
     "elliptic": {
       }
     },
     "node-releases": {
-      "version": "1.1.66",
-      "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.66.tgz",
-      "integrity": "sha512-JHEQ1iWPGK+38VLB2H9ef2otU4l8s3yAMt9Xf934r6+ojCYDMHPMqvCc9TnzfeFSP1QEOeU6YZEd3+De0LTCgg==",
+      "version": "1.1.67",
+      "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.67.tgz",
+      "integrity": "sha512-V5QF9noGFl3EymEwUYzO+3NTDpGfQB4ve6Qfnzf3UNydMhjQRVPR1DZTuvWiLzaFJYw2fmDwAfnRNEVb64hSIg==",
       "dev": true
     },
     "node-sass": {
index 0e606bd..dc40796 100644 (file)
@@ -13,8 +13,8 @@
     "vue-router": "^3.4.9"
   },
   "devDependencies": {
-    "@vue/cli-plugin-eslint": "^4.5.8",
-    "@vue/cli-service": "^4.5.8",
+    "@vue/cli-plugin-eslint": "^4.5.9",
+    "@vue/cli-service": "^4.5.9",
     "ajv": "^6.12.6",
     "apply-loader": "^2.0.0",
     "babel-eslint": "^10.1.0",
diff --git a/client/src/utils/afterRawLoad.js b/client/src/utils/afterRawLoad.js
new file mode 100644 (file)
index 0000000..58bdb56
--- /dev/null
@@ -0,0 +1,10 @@
+export default function afterRawLoad(text) {
+  return (
+    text
+    // Next two lines fix a weird issue after last update (2019-11)
+    .replace(/\\n/g, " ")
+    .replace(/\\"/g, '"')
+    .replace('export default "', "")
+    .replace(/";$/, "")
+  );
+}
index 175cc15..eb36422 100644 (file)
@@ -29,6 +29,7 @@ import BaseGame from "@/components/BaseGame.vue";
 import { processModalClick } from "@/utils/modalClick";
 import { replaceByDiag } from "@/utils/printDiagram";
 import { store } from "@/store";
+import afterRawLoad from "@/utils/afterRawLoad";
 export default {
   name: "my-analyse",
   // TODO: game import ==> require some adjustments, like
@@ -100,17 +101,12 @@ export default {
       })
       .catch((err) => { this.alertAndQuit("Mispelled variant name", true); });
       this.rulesContent =
-        require(
-          "raw-loader!@/translations/rules/" +
-          this.gameRef.vname + "/" +
-          this.st.lang + ".pug"
+        afterRawLoad(
+          require(
+            "raw-loader!@/translations/rules/" +
+            this.gameRef.vname + "/" + this.st.lang + ".pug"
           ).default
-        .replace('export default "', "")
-        .replace(/";$/, "")
-        // Next two lines fix a weird issue after last update (2019-11)
-        .replace(/\\n/g, " ")
-        .replace(/\\"/g, '"')
-        .replace(/(fen:)([^:]*):/g, replaceByDiag);
+        ).replace(/(fen:)([^:]*):/g, replaceByDiag);
     },
     loadGame: function(orientation) {
       this.game.vname = this.gameRef.vname;
index 7164717..05b1e25 100644 (file)
@@ -7,6 +7,7 @@ main
 
 <script>
 import { store } from "@/store";
+import afterRawLoad from "@/utils/afterRawLoad";
 export default {
   name: "my-faq",
   data: function() {
@@ -14,14 +15,12 @@ export default {
   },
   computed: {
     content: function() {
-      // (AJAX) Request to get FAQ content (plain text, HTML)
       return (
-        require("raw-loader!@/translations/faq/" + this.st.lang + ".pug")
-        // Next two lines fix a weird issue after last update (2019-11)
-        .replace(/\\n/g, " ")
-        .replace(/\\"/g, '"')
-        .replace('module.exports = "', "")
-        .replace(/"$/, "")
+        afterRawLoad(
+          require(
+            "raw-loader!@/translations/faq/" + this.st.lang + ".pug"
+          ).default
+        )
       );
     }
   },
index 9094309..d66716c 100644 (file)
@@ -196,6 +196,7 @@ import { getDiagram, replaceByDiag } from "@/utils/printDiagram";
 import { processModalClick } from "@/utils/modalClick";
 import { playMove, getFilteredMove } from "@/utils/playUndo";
 import { ArrayFun } from "@/utils/array";
+import afterRawLoad from "@/utils/afterRawLoad";
 import params from "@/parameters";
 export default {
   name: "my-game",
@@ -1266,19 +1267,13 @@ export default {
         window.V = vModule[game.vname + "Rules"];
         this.loadGame(game, callback);
       });
-      // (AJAX) Request to get rules content (plain text, HTML)
       this.rulesContent =
-        require(
-          "raw-loader!@/translations/rules/" +
-          game.vname + "/" +
-          this.st.lang + ".pug"
-        )
-        // Next two lines fix a weird issue after last update (2019-11)
-        .replace(/\\n/g, " ")
-        .replace(/\\"/g, '"')
-        .replace('module.exports = "', "")
-        .replace(/"$/, "")
-        .replace(/(fen:)([^:]*):/g, replaceByDiag);
+        afterRawLoad(
+          require(
+            "raw-loader!@/translations/rules/" +
+            game.vname + "/" + this.st.lang + ".pug"
+          ).default
+        ).replace(/(fen:)([^:]*):/g, replaceByDiag);
     },
     // 3 cases for loading a game:
     //  - from indexedDB (running or completed live game I play)
index adc0ad3..a55126f 100644 (file)
@@ -131,6 +131,7 @@ import params from "@/parameters";
 import { getDiagram, replaceByDiag } from "@/utils/printDiagram";
 import { processModalClick } from "@/utils/modalClick";
 import { ArrayFun } from "@/utils/array";
+import afterRawLoad from "@/utils/afterRawLoad";
 import BaseGame from "@/components/BaseGame.vue";
 export default {
   name: "my-problems",
@@ -313,19 +314,13 @@ export default {
         this.loadedVar = vid;
         cb();
       });
-      // (AJAX) Request to get rules content (plain text, HTML)
       this.rulesContent =
-        require(
-          "raw-loader!@/translations/rules/" +
-          variant.name + "/" +
-          this.st.lang + ".pug"
-        )
-        // Next two lines fix a weird issue after last update (2019-11)
-        .replace(/\\n/g, " ")
-        .replace(/\\"/g, '"')
-        .replace('module.exports = "', "")
-        .replace(/"$/, "")
-        .replace(/(fen:)([^:]*):/g, replaceByDiag);
+        afterRawLoad(
+          require(
+            "raw-loader!@/translations/rules/" + variant.name + "/" +
+            this.st.lang + ".pug"
+          ).default
+        ).replace(/(fen:)([^:]*):/g, replaceByDiag);
     },
     trySetDiagram: function(prob) {
       // Problem edit: FEN could be wrong or incomplete,
index 2871f3f..2edd8a8 100644 (file)
@@ -44,6 +44,7 @@ import ComputerGame from "@/components/ComputerGame.vue";
 import { store } from "@/store";
 import { replaceByDiag } from "@/utils/printDiagram";
 import { CompgameStorage } from "@/utils/compgameStorage";
+import afterRawLoad from "@/utils/afterRawLoad";
 export default {
   name: "my-rules",
   components: {
@@ -77,19 +78,13 @@ export default {
     },
     content: function() {
       if (!this.gameInfo.vname) return ""; //variant not set yet
-      // (AJAX) Request to get rules content (plain text, HTML)
       return (
-        require(
-          "raw-loader!@/translations/rules/" +
-          this.gameInfo.vname + "/" +
-          this.st.lang + ".pug"
+        afterRawLoad(
+          require(
+            "raw-loader!@/translations/rules/" +
+            this.gameInfo.vname + "/" + this.st.lang + ".pug"
           ).default
-        .replace('export default "', "")
-        .replace(/";$/, "")
-        // Next two lines fix a weird issue after last update (2019-11)
-        .replace(/\\n/g, " ")
-        .replace(/\\"/g, '"')
-        .replace(/(fen:)([^:]*):/g, replaceByDiag)
+        ).replace(/(fen:)([^:]*):/g, replaceByDiag)
       );
     }
   },
index f0a98ed..da6478b 100644 (file)
@@ -9,6 +9,7 @@ main
 
 <script>
 import { store } from "@/store";
+import afterRawLoad from "@/utils/afterRawLoad";
 export default {
   name: "my-variants",
   data: function() {
@@ -18,16 +19,12 @@ export default {
   },
   computed: {
     content: function() {
-      // (AJAX) Request to get rules content (plain text, HTML)
       return (
-        require(
-          "raw-loader!@/translations/variants/" + this.st.lang + ".pug"
+        afterRawLoad(
+          require(
+            "raw-loader!@/translations/variants/" + this.st.lang + ".pug"
           ).default
-        .replace('export default "', "")
-        .replace(/";$/, "")
-        // Next two lines fix a weird issue after last update (2019-11)
-        .replace(/\\n/g, " ")
-        .replace(/\\"/g, '"')
+        )
       );
     }
   },