From 5d872c18d515a6f545ba7d54ae34b9055675e04c Mon Sep 17 00:00:00 2001
From: Christophe L <christophe.misc+helmholtz@protonmail.ch>
Date: Mon, 19 Feb 2024 13:47:36 +0100
Subject: [PATCH] build(Dockerfile): add client build steps to generate client

---
 frontend/Dockerfile                           |  4 +-
 frontend/components/TemplateForm.tsx          | 10 +++-
 frontend/lib/client/.gitignore                |  6 ++
 frontend/lib/client/.npmignore                |  1 -
 frontend/lib/client/.openapi-generator-ignore | 23 --------
 frontend/lib/client/.openapi-generator/FILES  | 33 -----------
 .../lib/client/.openapi-generator/VERSION     |  1 -
 frontend/lib/client/README.md                 | 45 ---------------
 frontend/lib/client/git_push.sh               | 57 -------------------
 frontend/lib/client/package.json              |  6 +-
 frontend/package.json                         | 14 ++---
 frontend/yarn.lock                            | 57 +++++++++++--------
 12 files changed, 59 insertions(+), 198 deletions(-)
 delete mode 100644 frontend/lib/client/.npmignore
 delete mode 100644 frontend/lib/client/.openapi-generator-ignore
 delete mode 100644 frontend/lib/client/.openapi-generator/FILES
 delete mode 100644 frontend/lib/client/.openapi-generator/VERSION
 delete mode 100644 frontend/lib/client/README.md
 delete mode 100644 frontend/lib/client/git_push.sh

diff --git a/frontend/Dockerfile b/frontend/Dockerfile
index 6878f0b..c9a67df 100644
--- a/frontend/Dockerfile
+++ b/frontend/Dockerfile
@@ -24,7 +24,9 @@ COPY pages pages
 COPY components components
 COPY lib lib
 
-#COPY --from=git-version /app/utils/generatedGitInfo.json utils/generatedGitInfo.json
+WORKDIR /app/lib/client
+RUN npm run build
+WORKDIR /app
 
 FROM base as prod-build
 # relative
diff --git a/frontend/components/TemplateForm.tsx b/frontend/components/TemplateForm.tsx
index 164ee96..f687832 100644
--- a/frontend/components/TemplateForm.tsx
+++ b/frontend/components/TemplateForm.tsx
@@ -69,7 +69,11 @@ const TemplateForm: FC<TemplateFormProps> = ({ template }) => {
                 .map((f) => f.name);
             // all fields that are empty
             return Array.from(form.entries())
-                .filter(([key, value]) => keysToCheck.includes(key) && value.length === 0)
+                .filter(
+                    ([key, value]) =>
+                        keysToCheck.includes(key) &&
+                        (typeof value !== 'string' || value.length === 0)
+                )
                 .map(([key]) => key);
         },
         [fields.isSuccess, fields.data]
@@ -94,8 +98,10 @@ const TemplateForm: FC<TemplateFormProps> = ({ template }) => {
             }
         }
 
+        const entries = Array.from(form.entries()).filter(
+            ([, value]) => typeof value === 'string' && value.length > 0
+        );
         // TODO: get rid of type assertion, asserting because we have no files
-        const entries = Array.from(form.entries()).filter((entry) => entry[1].length > 0);
         const json = Object.fromEntries(entries) as Record<string, string>;
         generate.mutate(json);
     };
diff --git a/frontend/lib/client/.gitignore b/frontend/lib/client/.gitignore
index 149b576..f0629e4 100644
--- a/frontend/lib/client/.gitignore
+++ b/frontend/lib/client/.gitignore
@@ -2,3 +2,9 @@ wwwroot/*.js
 node_modules
 typings
 dist
+
+./README.md
+./git_push.sh
+./.openapi-generator-ignore
+./.npmignore
+./.openapi-generator
\ No newline at end of file
diff --git a/frontend/lib/client/.npmignore b/frontend/lib/client/.npmignore
deleted file mode 100644
index 999d88d..0000000
--- a/frontend/lib/client/.npmignore
+++ /dev/null
@@ -1 +0,0 @@
-# empty npmignore to ensure all required files (e.g., in the dist folder) are published by npm
\ No newline at end of file
diff --git a/frontend/lib/client/.openapi-generator-ignore b/frontend/lib/client/.openapi-generator-ignore
deleted file mode 100644
index 7484ee5..0000000
--- a/frontend/lib/client/.openapi-generator-ignore
+++ /dev/null
@@ -1,23 +0,0 @@
-# OpenAPI Generator Ignore
-# Generated by openapi-generator https://github.com/openapitools/openapi-generator
-
-# Use this file to prevent files from being overwritten by the generator.
-# The patterns follow closely to .gitignore or .dockerignore.
-
-# As an example, the C# client generator defines ApiClient.cs.
-# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
-#ApiClient.cs
-
-# You can match any string of characters against a directory, file or extension with a single asterisk (*):
-#foo/*/qux
-# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
-
-# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
-#foo/**/qux
-# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
-
-# You can also negate patterns with an exclamation (!).
-# For example, you can ignore all files in a docs folder with the file extension .md:
-#docs/*.md
-# Then explicitly reverse the ignore rule for a single file:
-#!docs/README.md
diff --git a/frontend/lib/client/.openapi-generator/FILES b/frontend/lib/client/.openapi-generator/FILES
deleted file mode 100644
index 3a6884e..0000000
--- a/frontend/lib/client/.openapi-generator/FILES
+++ /dev/null
@@ -1,33 +0,0 @@
-.gitignore
-.npmignore
-README.md
-api.ts
-apis/database-api.ts
-apis/project-api.ts
-apis/templates-api.ts
-base.ts
-common.ts
-configuration.ts
-git_push.sh
-index.ts
-models/cutter-field.ts
-models/cutter-option.ts
-models/default.ts
-models/error-details.ts
-models/field-type.ts
-models/forbidden.ts
-models/index.ts
-models/not-found.ts
-models/not-implemented.ts
-models/server-error.ts
-models/status401.ts
-models/status403.ts
-models/status404.ts
-models/status422.ts
-models/status500.ts
-models/status501.ts
-models/template.ts
-models/unauthorized.ts
-models/unprocessable.ts
-package.json
-tsconfig.json
diff --git a/frontend/lib/client/.openapi-generator/VERSION b/frontend/lib/client/.openapi-generator/VERSION
deleted file mode 100644
index 4122521..0000000
--- a/frontend/lib/client/.openapi-generator/VERSION
+++ /dev/null
@@ -1 +0,0 @@
-7.0.0
\ No newline at end of file
diff --git a/frontend/lib/client/README.md b/frontend/lib/client/README.md
deleted file mode 100644
index 65f49f5..0000000
--- a/frontend/lib/client/README.md
+++ /dev/null
@@ -1,45 +0,0 @@
-## cookiecutter-web-client@0.1.0
-
-This generator creates TypeScript/JavaScript client that utilizes [axios](https://github.com/axios/axios). The generated Node module can be used in the following environments:
-
-Environment
-* Node.js
-* Webpack
-* Browserify
-
-Language level
-* ES5 - you must have a Promises/A+ library installed
-* ES6
-
-Module system
-* CommonJS
-* ES6 module system
-
-It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html))
-
-### Building
-
-To build and compile the typescript sources to javascript use:
-```
-npm install
-npm run build
-```
-
-### Publishing
-
-First build the package then run ```npm publish```
-
-### Consuming
-
-navigate to the folder of your consuming project and run one of the following commands.
-
-_published:_
-
-```
-npm install cookiecutter-web-client@0.1.0 --save
-```
-
-_unPublished (not recommended):_
-
-```
-npm install PATH_TO_GENERATED_PACKAGE --save
diff --git a/frontend/lib/client/git_push.sh b/frontend/lib/client/git_push.sh
deleted file mode 100644
index f53a75d..0000000
--- a/frontend/lib/client/git_push.sh
+++ /dev/null
@@ -1,57 +0,0 @@
-#!/bin/sh
-# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
-#
-# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com"
-
-git_user_id=$1
-git_repo_id=$2
-release_note=$3
-git_host=$4
-
-if [ "$git_host" = "" ]; then
-    git_host="github.com"
-    echo "[INFO] No command line input provided. Set \$git_host to $git_host"
-fi
-
-if [ "$git_user_id" = "" ]; then
-    git_user_id="GIT_USER_ID"
-    echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
-fi
-
-if [ "$git_repo_id" = "" ]; then
-    git_repo_id="GIT_REPO_ID"
-    echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
-fi
-
-if [ "$release_note" = "" ]; then
-    release_note="Minor update"
-    echo "[INFO] No command line input provided. Set \$release_note to $release_note"
-fi
-
-# Initialize the local directory as a Git repository
-git init
-
-# Adds the files in the local repository and stages them for commit.
-git add .
-
-# Commits the tracked changes and prepares them to be pushed to a remote repository.
-git commit -m "$release_note"
-
-# Sets the new remote
-git_remote=$(git remote)
-if [ "$git_remote" = "" ]; then # git remote not defined
-
-    if [ "$GIT_TOKEN" = "" ]; then
-        echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
-        git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git
-    else
-        git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git
-    fi
-
-fi
-
-git pull origin master
-
-# Pushes (Forces) the changes in the local repository up to the remote repository
-echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
-git push origin master 2>&1 | grep -v 'To https'
diff --git a/frontend/lib/client/package.json b/frontend/lib/client/package.json
index f796f4d..000f1de 100644
--- a/frontend/lib/client/package.json
+++ b/frontend/lib/client/package.json
@@ -17,11 +17,11 @@
     "prepare": "npm run build"
   },
   "dependencies": {
-    "axios": "^1.4.0"
+    "axios": "^1.6.5"
   },
   "devDependencies": {
-    "@types/node": "^18.16.17",
-    "typescript": "^5.1.6"
+    "@types/node": "^18.19.8",
+    "typescript": "^5.3.3"
   },
   "module": "./dist/index.js",
   "sideEffects": false,
diff --git a/frontend/package.json b/frontend/package.json
index c4d719d..9307ba6 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -16,10 +16,7 @@
     "@tailwindcss/forms": "^0.5.6",
     "@tanstack/react-query": "^4.35.3",
     "@tanstack/react-query-devtools": "^4.35.3",
-    "@types/node": "18.11.9",
-    "@types/react": "18.0.25",
-    "@types/react-dom": "18.0.9",
-    "axios": "^1.5.0",
+    "axios": "^1.6.5",
     "clsx": "^1.2.1",
     "eslint": "8.27.0",
     "eslint-config-next": "^13.5.5",
@@ -31,11 +28,13 @@
     "react": "18.2.0",
     "react-dom": "18.2.0",
     "react-oidc-context": "^2.2.0",
-    "sass": "^1.62.1",
-    "typescript": "4.9.3"
+    "sass": "^1.62.1"
   },
   "devDependencies": {
     "@types/lodash": "^4.14.199",
+    "@types/node": "^18.19.8",
+    "@types/react": "^18.2.48",
+    "@types/react-dom": "^18.2.18",
     "@typescript-eslint/eslint-plugin": "^6.8.0",
     "@typescript-eslint/parser": "^6.8.0",
     "autoprefixer": "^10.4.15",
@@ -44,7 +43,8 @@
     "eslint-plugin-tailwindcss": "^3.13.0",
     "postcss": "^8.4.29",
     "prettier": "^2.8.1",
-    "tailwindcss": "^3.3.3"
+    "tailwindcss": "^3.3.3",
+    "typescript": "^5.3.3"
   },
   "packageManager": "yarn@1.22.19"
 }
diff --git a/frontend/yarn.lock b/frontend/yarn.lock
index e110103..57e790c 100644
--- a/frontend/yarn.lock
+++ b/frontend/yarn.lock
@@ -303,27 +303,29 @@
   resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.199.tgz#c3edb5650149d847a277a8961a7ad360c474e9bf"
   integrity sha512-Vrjz5N5Ia4SEzWWgIVwnHNEnb1UE1XMkvY5DGXrAeOGE9imk0hgTHh5GyDjLDJi9OTCn9oo9dXH1uToK1VRfrg==
 
-"@types/node@18.11.9":
-  version "18.11.9"
-  resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.9.tgz#02d013de7058cea16d36168ef2fc653464cfbad4"
-  integrity sha512-CRpX21/kGdzjOpFsZSkcrXMGIBWMGNIHXXBVFSH+ggkftxg+XYP20TESbh+zFvFj3EQOl5byk0HTRn1IL6hbqg==
+"@types/node@^18.19.8":
+  version "18.19.8"
+  resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.8.tgz#c1e42b165e5a526caf1f010747e0522cb2c9c36a"
+  integrity sha512-g1pZtPhsvGVTwmeVoexWZLTQaOvXwoSq//pTL0DHeNzUDrFnir4fgETdhjhIxjVnN+hKOuh98+E1eMLnUXstFg==
+  dependencies:
+    undici-types "~5.26.4"
 
 "@types/prop-types@*":
   version "15.7.5"
   resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.5.tgz#5f19d2b85a98e9558036f6a3cacc8819420f05cf"
   integrity sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==
 
-"@types/react-dom@18.0.9":
-  version "18.0.9"
-  resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.0.9.tgz#ffee5e4bfc2a2f8774b15496474f8e7fe8d0b504"
-  integrity sha512-qnVvHxASt/H7i+XG1U1xMiY5t+IHcPGUK7TDMDzom08xa7e86eCeKOiLZezwCKVxJn6NEiiy2ekgX8aQssjIKg==
+"@types/react-dom@^18.2.18":
+  version "18.2.18"
+  resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.2.18.tgz#16946e6cd43971256d874bc3d0a72074bb8571dd"
+  integrity sha512-TJxDm6OfAX2KJWJdMEVTwWke5Sc/E/RlnPGvGfS0W7+6ocy2xhDVQVh/KvC2Uf7kACs+gDytdusDSdWfWkaNzw==
   dependencies:
     "@types/react" "*"
 
-"@types/react@*", "@types/react@18.0.25":
-  version "18.0.25"
-  resolved "https://registry.yarnpkg.com/@types/react/-/react-18.0.25.tgz#8b1dcd7e56fe7315535a4af25435e0bb55c8ae44"
-  integrity sha512-xD6c0KDT4m7n9uD4ZHi02lzskaiqcBxf4zi+tXZY98a04wvc0hi/TcCPC2FOESZi51Nd7tlUeOJY8RofL799/g==
+"@types/react@*", "@types/react@^18.2.48":
+  version "18.2.48"
+  resolved "https://registry.yarnpkg.com/@types/react/-/react-18.2.48.tgz#11df5664642d0bd879c1f58bc1d37205b064e8f1"
+  integrity sha512-qboRCl6Ie70DQQG9hhNREz81jqC1cs9EVNcjQ1AU+jH6NFfSAhVVbrrY/+nSF+Bsk4AOwm9Qa61InvMCyV+H3w==
   dependencies:
     "@types/prop-types" "*"
     "@types/scheduler" "*"
@@ -615,12 +617,12 @@ axe-core@^4.6.2:
   resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.8.2.tgz#2f6f3cde40935825cf4465e3c1c9e77b240ff6ae"
   integrity sha512-/dlp0fxyM3R8YW7MFzaHWXrf4zzbr0vaYb23VBFCl83R7nWNPg/yaQw2Dc8jzCMmDVLhSdzH8MjrsuIUuvX+6g==
 
-axios@^1.5.0:
-  version "1.5.0"
-  resolved "https://registry.yarnpkg.com/axios/-/axios-1.5.0.tgz#f02e4af823e2e46a9768cfc74691fdd0517ea267"
-  integrity sha512-D4DdjDo5CY50Qms0qGQTTw6Q44jl7zRwY7bthds06pUGfChBCTcQs+N743eFWGEd6pRTMd6A+I87aWyFV5wiZQ==
+axios@^1.6.5:
+  version "1.6.5"
+  resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.5.tgz#2c090da14aeeab3770ad30c3a1461bc970fb0cd8"
+  integrity sha512-Ii012v05KEVuUoFWmMW/UQv9aRIc3ZwkWDcM+h5Il8izZCtRVpDUfwpoFf7eOtajT3QiGR4yDUx7lPqHJULgbg==
   dependencies:
-    follow-redirects "^1.15.0"
+    follow-redirects "^1.15.4"
     form-data "^4.0.0"
     proxy-from-env "^1.1.0"
 
@@ -1518,10 +1520,10 @@ flatted@^3.1.0:
   resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.7.tgz#609f39207cb614b89d0765b477cb2d437fbf9787"
   integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==
 
-follow-redirects@^1.15.0:
-  version "1.15.2"
-  resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
-  integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==
+follow-redirects@^1.15.4:
+  version "1.15.5"
+  resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.5.tgz#54d4d6d062c0fa7d9d17feb008461550e3ba8020"
+  integrity sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==
 
 for-each@^0.3.3:
   version "0.3.3"
@@ -3224,10 +3226,10 @@ typed-array-length@^1.0.4:
     for-each "^0.3.3"
     is-typed-array "^1.1.9"
 
-typescript@4.9.3:
-  version "4.9.3"
-  resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.3.tgz#3aea307c1746b8c384435d8ac36b8a2e580d85db"
-  integrity sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==
+typescript@^5.3.3:
+  version "5.3.3"
+  resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37"
+  integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==
 
 unbox-primitive@^1.0.2:
   version "1.0.2"
@@ -3239,6 +3241,11 @@ unbox-primitive@^1.0.2:
     has-symbols "^1.0.3"
     which-boxed-primitive "^1.0.2"
 
+undici-types@~5.26.4:
+  version "5.26.5"
+  resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
+  integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==
+
 untildify@^4.0.0:
   version "4.0.0"
   resolved "https://registry.yarnpkg.com/untildify/-/untildify-4.0.0.tgz#2bc947b953652487e4600949fb091e3ae8cd919b"
-- 
GitLab