From d61f403a243ef15c970ce2e01c85c54e38bf5426 Mon Sep 17 00:00:00 2001 From: psvenk <45520974+psvenk@users.noreply.github.com> Date: Fri, 24 Apr 2020 13:45:21 -0400 Subject: [PATCH] Refactor build-lite.sh Instead of hardcoding substitutions, make build-lite.sh accept a syntax resembling that of the C preprocessor so that lite-specific changes can be made more easily. This commit also brings the lite-specific changes up to date with recent changes to the frontend codebase. --- build-lite.sh | 52 ++++++++++++++---------------------- public/home.html | 2 ++ public/js/buttonFunctions.js | 24 +++++++++++++++++ public/js/clock.js | 9 +++++++ public/js/home.js | 19 +++++++++++++ 5 files changed, 74 insertions(+), 32 deletions(-) diff --git a/build-lite.sh b/build-lite.sh index 496cc40c..92916433 100644 --- a/build-lite.sh +++ b/build-lite.sh @@ -4,7 +4,7 @@ # Note: This script has only been tested with Bash in a GNU environment # (on Linux); your mileage may vary on BSD, macOS, Cygwin/MSYS (Windows), etc. -rm -r dist-lite/ +rm -rf dist-lite/ mkdir -p dist-lite/ cp -r public/* dist-lite/ @@ -34,46 +34,34 @@ do done # https://stackoverflow.com/a/21256704 -cp -r ./node_modules/@fortawesome/fontawesome-free/webfonts/ dist-lite/fonts/fontawesome/webfonts +cp -r ./node_modules/@fortawesome/fontawesome-free/webfonts/ \ +dist-lite/fonts/fontawesome/webfonts # Copy Font Awesome files rm dist-lite/login.html # Remove login page -sed '/Logout/d' -i dist-lite/home.html -# Remove "Logout" button +perl -0777 -pi -e 's[][\1]g' \ +dist-lite/home.html -sed -e '1h;2,$H;$!d;g' -e 's/\ -\$\.ajax({\ -\ \ \ \ url:\ "\/data.*then(responseCallback);/\ -responseCallback({\ - classes: [],\ - recent: {\ - recentActivityArray: [],\ - recentAttendanceArray: []\ - },\ - overview: [],\ - username: "",\ - quarter: "0"\ -});/' \ --i dist-lite/js/home.js +perl -0777 -pi -e 's[\n((.|\n)*?)\n][]g' \ +dist-lite/home.html -sed -e '1h;2,$H;$!d;g' -e 's/\ -\$\.ajax({\ -\ \ \ \ url:\ "schedule.json.*then(schedulesCallback);/\ -schedulesCallback(\ -);/' \ --i dist-lite/js/clock.js +perl -0777 -pi -e 's[//#ifdef lite\n/\*\n((.|\n)*?)\n\*/\n//#endif][\1]g' \ +dist-lite/js/*.js -sed -e '/schedulesCallback(/r dist-lite/schedule.json' \ --i dist-lite/js/clock.js +perl -0777 -pi -e 's[//#ifndef lite\n((.|\n)*?)\n//#endif][]g' \ +dist-lite/js/*.js -# Replace AJAX calls with initialization using blank data -# https://unix.stackexchange.com/a/235016 -# https://unix.stackexchange.com/a/32912 +# Preprocess HTML and JS files to make lite-specific changes as needed +# https://stackoverflow.com/a/1103177 +# https://stackoverflow.com/a/5869735 -version="$(grep version package.json | sed 's/.*: "//' | sed 's/",//')" -# Get version number from package.json +sed -i -e '/#include dist-lite\/schedule.json/r dist-lite/schedule.json' \ +dist-lite/js/clock.js +# Include contents of schedule.json +# https://unix.stackexchange.com/a/32912 -sed -i 's/await \$\.ajax("\/version")/"'$version'"/g' dist-lite/js/* +version="$(git describe)" +sed -i 's/\/\/#include $version/"'$version'"/g' dist-lite/js/* # Hard-code version number diff --git a/public/home.html b/public/home.html index dfa04a65..3df3dd68 100644 --- a/public/home.html +++ b/public/home.html @@ -63,7 +63,9 @@

Aspine

+ +