Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change build-lite.sh to POSIX sh syntax #121

Merged
merged 1 commit into from
May 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions build-lite.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
#!/bin/bash
#!/bin/sh
# Build script for a "lite" (purely client-side) version of Aspine

# 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.
# This script has been written in POSIX sh but has only been tested
# in Bash in a GNU environment.

# Dependencies: grep with support for context, sed, perl

rm -rf dist-lite/
mkdir -p dist-lite/

cp -r public/* dist-lite/

mappings="$(
grep -A100 'new Map' serve.js \
| grep -A3 '^ \[' \
| grep -Ev '\[|\]' \
| grep \' \
| sed 's/ '\''//' \
| sed 's/'\'',*//'
)"
| sed 's/'\'',*//' \
| while read -r endpoint
do
read -r path

mkdir -p "$(dirname "dist-lite/$endpoint")"
# Create the parent directory
cp "./$path" "dist-lite/$endpoint"
# Copy the node module to dist-lite
done
# grep and sed commands explanation:
# Find the line in serve.js containing 'new Map' and get the next 100 lines
# Limit the search to lines that contain ' [' and the next three lines
# Remove lines with brackets
# Remove leading whitespace and single quote character
# Remove trailing single quote character and comma (if any)

echo $mappings | \
while read -d ' ' endpoint
do
read -d ' ' path

mkdir -p "$(dirname dist-lite$endpoint)"
# Create the parent directory
cp ".$path" "dist-lite$endpoint"
# Copy the node module to dist-lite
done
# https://stackoverflow.com/a/21256704

cp -r ./node_modules/@fortawesome/fontawesome-free/webfonts/ \
dist-lite/fonts/fontawesome/webfonts
# Copy Font Awesome files
Expand Down Expand Up @@ -62,6 +60,10 @@ dist-lite/js/clock.js
# Include contents of schedule.json
# https://unix.stackexchange.com/a/32912

version="$(git describe | sed 's/^v\?\(.*\)/\1/')"
sed -i 's/\/\/#include $version/"'$version'"/g' dist-lite/js/*
version="$(git describe | sed 's/^v//')"

for file in dist-lite/js/*
do
sed -i '' -e 's/\/\/#include version/"'"$version"'"/g' "$file"
done
# Hard-code version number (use sed to trim 'v')
4 changes: 2 additions & 2 deletions public/js/buttonFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ let exportTableData = async function(prefs) {
//#ifdef lite
/*
obj.version = (
//#include $version
//#include version
);
*/
//#endif
Expand Down Expand Up @@ -375,7 +375,7 @@ let importTableData = async function(obj) {
//#ifdef lite
/*
let version = (
//#include $version
//#include version
);
*/
//#endif
Expand Down
2 changes: 1 addition & 1 deletion public/js/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ $.ajax("/version").then(ver => $("#version").text(ver));
//#ifdef lite
/*
$("#version").text(
//#include $version
//#include version
);
*/
//#endif