From 121b9a4c0627e06aaed6a53fdfe53c86a4a518da Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Mon, 28 Dec 2020 13:35:34 +1300 Subject: [PATCH] Use file lists to populate frontend.js and backend.js --- .gitignore | 3 +- build-scripts/merge-js.sh | 67 ++++++++++++++++++- js/{classes/_config.js => _eslint.js} | 0 js/{init.js => _init.js} | 0 ...yboard-helpers.js => _keyboard-helpers.js} | 0 js/{classes/label.js => _label.js} | 0 js/{classes/listbox.js => _listbox.js} | 0 ...tabbed-carousel.js => _tabbed-carousel.js} | 0 js/backend.js | 0 js/backend.txt | 1 + js/frontend.txt | 6 ++ listbox.html | 1 - package.json | 3 +- tabbed-carousel.html | 1 - 14 files changed, 76 insertions(+), 6 deletions(-) rename js/{classes/_config.js => _eslint.js} (100%) rename js/{init.js => _init.js} (100%) rename js/{classes/keyboard-helpers.js => _keyboard-helpers.js} (100%) rename js/{classes/label.js => _label.js} (100%) rename js/{classes/listbox.js => _listbox.js} (100%) rename js/{classes/tabbed-carousel.js => _tabbed-carousel.js} (100%) delete mode 100644 js/backend.js create mode 100644 js/backend.txt create mode 100644 js/frontend.txt diff --git a/.gitignore b/.gitignore index 9c00c9c..451367b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,8 @@ release* .browserslistrc .eslintrc .stylelint* -js/*-es5.js +js/backend*.js +js/frontend*.js nodemon.json phpcs.xml phpunit.xml.dist diff --git a/build-scripts/merge-js.sh b/build-scripts/merge-js.sh index fc3f7ed..9b247a5 100755 --- a/build-scripts/merge-js.sh +++ b/build-scripts/merge-js.sh @@ -18,4 +18,69 @@ # v: print shell input lines as they are read (including all comments!) set -e -cat ./js/classes/_config.js ./js/classes/*.js ./js/init.js > ./js/frontend.js +# https://www.cyberciti.biz/faq/bash-read-file-names-from-a-text-file-and-take-action/ +# IFS = Internal Field Separator +# -r = newline +# file = variable name + +# ===== BACKEND ===== + +backendJs="${1:-./js/backend.js}" +backendSrc="${1:-./js/backend.txt}" +backendTimestamp=$(date +"/* backend.js - generated %d/%m/%Y at %T from: */") +index=0 + +# if backendSrc doesn't exist +if [ ! -f "$backendSrc" ]; then + echo "$0 - File $backendSrc not found."; + exit 1; +fi + +# if backendJs exists empty it, otherwise create it +echo "${backendTimestamp}" > "${backendJs}" + +# read file list in backendSrc, copy filename to backendJs +while IFS= read -r file +do + index=$(($index+1)) + echo "/* $index $file */" >> "${backendJs}" +done < "${backendSrc}" + +echo "\r" >> "${backendJs}" + +# read file list in backendSrc, copy contents to backendJs +while IFS= read -r file +do + cat $file >> "${backendJs}" +done < "${backendSrc}" + +# ===== FRONTEND ===== + +frontendJs="${1:-./js/frontend.js}" +frontendSrc="${1:-./js/frontend.txt}" +frontendTimestamp=$(date +"/* frontend.js - generated %d/%m/%Y at %T from: */") +index=0 + +# if frontendSrc doesn't exist +if [ ! -f "$frontendSrc" ]; then + echo "$0 - File $frontendSrc not found."; + exit 1; +fi + +# if frontendJs exists empty it, otherwise create it +echo "${frontendTimestamp}" > "${frontendJs}" + +# read file list in frontendSrc, copy filename to frontendJs +while IFS= read -r file +do + index=$(($index+1)) + echo "/* $index $file */" >> "${frontendJs}" +done < "${frontendSrc}" + +echo "\r" >> "${frontendJs}" + +# read file list in frontendSrc, copy contents to frontendJs +while IFS= read -r file +do + cat $file >> "${frontendJs}" +done < "${frontendSrc}" diff --git a/js/classes/_config.js b/js/_eslint.js similarity index 100% rename from js/classes/_config.js rename to js/_eslint.js diff --git a/js/init.js b/js/_init.js similarity index 100% rename from js/init.js rename to js/_init.js diff --git a/js/classes/keyboard-helpers.js b/js/_keyboard-helpers.js similarity index 100% rename from js/classes/keyboard-helpers.js rename to js/_keyboard-helpers.js diff --git a/js/classes/label.js b/js/_label.js similarity index 100% rename from js/classes/label.js rename to js/_label.js diff --git a/js/classes/listbox.js b/js/_listbox.js similarity index 100% rename from js/classes/listbox.js rename to js/_listbox.js diff --git a/js/classes/tabbed-carousel.js b/js/_tabbed-carousel.js similarity index 100% rename from js/classes/tabbed-carousel.js rename to js/_tabbed-carousel.js diff --git a/js/backend.js b/js/backend.js deleted file mode 100644 index e69de29..0000000 diff --git a/js/backend.txt b/js/backend.txt new file mode 100644 index 0000000..31e6872 --- /dev/null +++ b/js/backend.txt @@ -0,0 +1 @@ +./js/_eslint.js diff --git a/js/frontend.txt b/js/frontend.txt new file mode 100644 index 0000000..54911fe --- /dev/null +++ b/js/frontend.txt @@ -0,0 +1,6 @@ +./js/_eslint.js +./js/_keyboard-helpers.js +./js/_label.js +./js/_listbox.js +./js/_tabbed-carousel.js +./js/_init.js diff --git a/listbox.html b/listbox.html index 60ac888..efe16a6 100644 --- a/listbox.html +++ b/listbox.html @@ -3,7 +3,6 @@ Listbox - diff --git a/package.json b/package.json index 1077f15..bf0b76d 100644 --- a/package.json +++ b/package.json @@ -35,10 +35,9 @@ }, "scripts": { "changelog": "npm run changelog --prefix $npm_package_config_wpdtrt_npm_scripts", - "compile": "npm run compile --prefix $npm_package_config_wpdtrt_npm_scripts", + "compile": "./build-scripts/merge-js.sh && npm run compile --prefix $npm_package_config_wpdtrt_npm_scripts", "docs": "npm run docs --prefix $npm_package_config_wpdtrt_npm_scripts", "lint": "npm run lint --prefix $npm_package_config_wpdtrt_npm_scripts", - "merge:js": "./build-scripts/merge-js.sh", "release": "npm run release --prefix $npm_package_config_wpdtrt_npm_scripts", "server": "http-server ./", "test": "npm run test --prefix $npm_package_config_wpdtrt_npm_scripts && npx cypress run", diff --git a/tabbed-carousel.html b/tabbed-carousel.html index 7875f54..f53d472 100644 --- a/tabbed-carousel.html +++ b/tabbed-carousel.html @@ -3,7 +3,6 @@ Tabbed carousel -