From 169b5f93a1adeba9d6ae4619e12d07193d2d9895 Mon Sep 17 00:00:00 2001
From: Jonas Groeger <jonas.groeger_extern@fjd.de>
Date: Mon, 8 Jan 2024 16:14:45 +0100
Subject: [PATCH] refactor(build): simplify shell scripts

---
 build.sh           | 28 ++++++++++++++++++++++++++++
 bundle.sh          |  8 --------
 create_examples.sh | 29 -----------------------------
 package.json       |  2 +-
 4 files changed, 29 insertions(+), 38 deletions(-)
 create mode 100755 build.sh
 delete mode 100755 bundle.sh
 delete mode 100755 create_examples.sh

diff --git a/build.sh b/build.sh
new file mode 100755
index 0000000..8eb3564
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,28 @@
+#!/usr/bin/env sh
+
+# set -euxo pipefail
+
+node scripts/bundle.js spec/set-payload.schema.json \
+                       dist/set-payload.schema.json
+
+rm -rf examples examples_fail
+mkdir -p examples examples_fail
+
+# Create examples using template files
+for template in templates/*.json; do
+
+    # Get the name of the template
+    template_name=$(basename "$template")
+
+    # Create the example
+    set -- "1.0.0" "1.0.1" "1.0.2" "1.0.11" "1.1.0" "1.5.11"
+    for version in "$@"; do
+        sed -e "s|SCHEMA_VERSION|$version|g" "$template" > ./examples/"$template_name"_"$version".json
+    done
+
+   set -- "2.0.0" "3.0.1" "2.0.2" "2.0.11" "2.1.0" "3.5.11"
+    for version in "$@"; do
+        sed -e "s|SCHEMA_VERSION|$version|g" "$template" > ./examples_fail/"$template_name"_"$version".json
+    done
+
+done
diff --git a/bundle.sh b/bundle.sh
deleted file mode 100755
index fc85033..0000000
--- a/bundle.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/usr/bin/env sh
-
-# set -euxo pipefail
-
-node scripts/bundle.js spec/authentication-tags.schema.json dist/authentication-tags.schema.json
-node scripts/bundle.js spec/problems.schema.json            dist/problems.schema.json
-node scripts/bundle.js spec/set-payload.schema.json         dist/set-payload.schema.json
-sh create_examples.sh
diff --git a/create_examples.sh b/create_examples.sh
deleted file mode 100755
index b112e71..0000000
--- a/create_examples.sh
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/usr/bin/env sh
-
-# Create a directory for the examples
-rm -rf examples
-rm -rf examples_fail
-mkdir -p examples
-mkdir examples_fail
-
-
-# Run over Templates and create examples
-for template in templates/*.json; do
-    # Get the name of the template
-    template_name=$(basename $template)
-
-    # Get the name of the example
-    example_name=${template_name%.template}
-
-    # Create the example
-    set -- "1.0.0" "1.0.1" "1.0.2" "1.0.11" "1.1.0" "1.5.11"
-    for version in  "$@"; do
-        cat $template | sed -e "s|SCHEMA_VERSION|$version|g" > ./examples/"$template_name"_"$version".json
-    done
-
-   set -- "2.0.0" "3.0.1" "2.0.2" "2.0.11" "2.1.0" "3.5.11"
-    for version in  "$@"; do
-        cat $template | sed -e "s|SCHEMA_VERSION|$version|g" > ./examples_fail/"$template_name"_"$version".json
-    done
-
-done
diff --git a/package.json b/package.json
index 0718a19..ff2f015 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "scripts": {
-    "bundle": "sh bundle.sh",
+    "bundle": "sh build.sh",
     "lint": "ajv compile --spec=draft2020 -c ajv-formats -s dist/set-payload.schema.json",
     "test": "ajv validate --errors=text --verbose --all-errors -d examples/**/*.json --spec=draft2020 -c ajv-formats -s dist/set-payload.schema.json",
     "test_higher_version": "! ajv validate --errors=text --verbose --all-errors -d examples_fail/**/*.json --spec=draft2020 -c ajv-formats -s dist/set-payload.schema.json"
-- 
GitLab