Skip to content

Commit

Permalink
Change build-lite.sh to POSIX sh syntax
Browse files Browse the repository at this point in the history
This should solve incompatibilities with non-GNU systems.
  • Loading branch information
psvenk committed May 4, 2020
1 parent 06f0113 commit fbca634
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
40 changes: 21 additions & 19 deletions build-lite.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
#!/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 '\[|\]' \
| 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 @@ -63,5 +65,5 @@ dist-lite/js/clock.js
# https://unix.stackexchange.com/a/32912

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

0 comments on commit fbca634

Please sign in to comment.