Skip to content

Commit

Permalink
Use file lists to populate frontend.js and backend.js
Browse files Browse the repository at this point in the history
  • Loading branch information
dotherightthing committed Dec 28, 2020
1 parent 0174cc5 commit 121b9a4
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ release*
.browserslistrc
.eslintrc
.stylelint*
js/*-es5.js
js/backend*.js
js/frontend*.js
nodemon.json
phpcs.xml
phpunit.xml.dist
Expand Down
67 changes: 66 additions & 1 deletion build-scripts/merge-js.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file removed js/backend.js
Empty file.
1 change: 1 addition & 0 deletions js/backend.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./js/_eslint.js
6 changes: 6 additions & 0 deletions js/frontend.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
./js/_eslint.js
./js/_keyboard-helpers.js
./js/_label.js
./js/_listbox.js
./js/_tabbed-carousel.js
./js/_init.js
1 change: 0 additions & 1 deletion listbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<head>
<meta charset="utf-8" />
<title>Listbox</title>
<script src="node_modules/@babel/polyfill/dist/polyfill.min.js"></script>
<script src="js/frontend-es5.js"></script>
<link rel="stylesheet" href="css/frontend.css" />
</head>
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion tabbed-carousel.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<head>
<meta charset="utf-8" />
<title>Tabbed carousel</title>
<script src="node_modules/@babel/polyfill/dist/polyfill.min.js"></script>
<script src="js/frontend-es5.js"></script>
<link rel="stylesheet" href="css/frontend.css" />
</head>
Expand Down

0 comments on commit 121b9a4

Please sign in to comment.