reformat code

This commit is contained in:
Václav Uruba 2023-09-09 15:09:06 +02:00
parent 061d332228
commit f9b78ce765
Signed by: uruba
GPG Key ID: 9D8E987C4B2E1E9C

44
mige.sh
View File

@ -10,10 +10,10 @@ SOURCEDIR=$( dirname -- $BASH_SOURCE )
OPTION_ASSETS=false OPTION_ASSETS=false
check_files () { check_files () {
if [ ! -f "$SOURCEDIR/$TEMPLATE_HEADER" ]; then echo "Header template '$TEMPLATE_HEADER' doesn't exist."; exit 2; fi if [ ! -f "$SOURCEDIR/$TEMPLATE_HEADER" ]; then echo "Header template '$TEMPLATE_HEADER' doesn't exist."; exit 2; fi
if [ ! -f "$SOURCEDIR/$TEMPLATE_FOOTER" ]; then echo "Header template '$TEMPLATE_FOOTER' doesn't exist."; exit 2; fi if [ ! -f "$SOURCEDIR/$TEMPLATE_FOOTER" ]; then echo "Header template '$TEMPLATE_FOOTER' doesn't exist."; exit 2; fi
if [ ! -d "$SOURCEDIR/$DIR_CONTENT" ]; then echo "Content directory '$DIR_CONTENT' doesn't exist. Create it and add some content!"; exit 2; fi if [ ! -d "$SOURCEDIR/$DIR_CONTENT" ]; then echo "Content directory '$DIR_CONTENT' doesn't exist. Create it and add some content!"; exit 2; fi
if [ ! -d "$SOURCEDIR/$DIR_DIST" ]; then mkdir "$SOURCEDIR/$DIR_DIST"; echo "Directory '$DIR_DIST' created."; fi if [ ! -d "$SOURCEDIR/$DIR_DIST" ]; then mkdir "$SOURCEDIR/$DIR_DIST"; echo "Directory '$DIR_DIST' created."; fi
if [[ $OPTION_ASSETS == true && ! -s "$SOURCEDIR/$DIR_ASSETS" ]]; then echo "Directory '$DIR_ASSETS' doesn't exist. Create it and add some assets!"; exit 2; fi if [[ $OPTION_ASSETS == true && ! -s "$SOURCEDIR/$DIR_ASSETS" ]]; then echo "Directory '$DIR_ASSETS' doesn't exist. Create it and add some assets!"; exit 2; fi
} }
@ -27,23 +27,23 @@ read_options() {
} }
process_file () { process_file () {
local timep=$(date +%s%N) local timep=$(date +%s%N)
mkdir -p $( dirname "$1" | sed "s/$SOURCEDIR\/$DIR_CONTENT/$SOURCEDIR\/$DIR_DIST/" ) mkdir -p $( dirname "$1" | sed "s/$SOURCEDIR\/$DIR_CONTENT/$SOURCEDIR\/$DIR_DIST/" )
local file_output=$( echo "$1" | sed "s/$SOURCEDIR\/$DIR_CONTENT/$SOURCEDIR\/$DIR_DIST/" ) local file_output=$( echo "$1" | sed "s/$SOURCEDIR\/$DIR_CONTENT/$SOURCEDIR\/$DIR_DIST/" )
cat "$SOURCEDIR/$TEMPLATE_HEADER" "$1" "$SOURCEDIR/$TEMPLATE_FOOTER" > $file_output cat "$SOURCEDIR/$TEMPLATE_HEADER" "$1" "$SOURCEDIR/$TEMPLATE_FOOTER" > $file_output
while read -r variable; do while read -r variable; do
if [[ $variable =~ ^([0-9]+)=(.+)$ ]]; then if [[ $variable =~ ^([0-9]+)=(.+)$ ]]; then
local variable_name=${BASH_REMATCH[1]} local variable_name=${BASH_REMATCH[1]}
local variable_value=${BASH_REMATCH[2]} local variable_value=${BASH_REMATCH[2]}
sed -i "s/\$$variable_name/$variable_value/g;/$variable/d" $file_output sed -i "s/\$$variable_name/$variable_value/g;/$variable/d" $file_output
else else
echo -e "\e[38;5;208mWarning: could not match '$variable' as a variable assignment.\e[0m" echo -e "\e[38;5;208mWarning: could not match '$variable' as a variable assignment.\e[0m"
fi fi
done < <(grep -P '^\d+=.+$' $1) done < <(grep -P '^\d+=.+$' $1)
timep=$((($(date +%s%N) - $timep)/1000000)) timep=$((($(date +%s%N) - $timep)/1000000))
echo -e "\e[32mFile $1 processed to $file_output ($timep ms).\e[0m" echo -e "\e[32mFile $1 processed to $file_output ($timep ms).\e[0m"
} }
process_assets () { process_assets () {
@ -55,9 +55,9 @@ process_assets () {
} }
main () { main () {
while IFS= read -d '' file_content; do while IFS= read -d '' file_content; do
process_file "${file_content}" </dev/null process_file "${file_content}" </dev/null
done < <(find "$SOURCEDIR/$DIR_CONTENT" -type f -print0) done < <(find "$SOURCEDIR/$DIR_CONTENT" -type f -print0)
if [ $OPTION_ASSETS = true ]; then if [ $OPTION_ASSETS = true ]; then
process_assets process_assets