Skip to content

Commit

Permalink
Revamp build_changed.sh to use just, and only rebuild the changed file
Browse files Browse the repository at this point in the history
  • Loading branch information
utensil committed Sep 30, 2024
1 parent a5f1675 commit b812e12
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 35 deletions.
16 changes: 8 additions & 8 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ function bun_build {
# if the file extension is .css
if [[ $FILE == *".css" ]]; then
echo "🚀 lightningcss"
bunx lightningcss-cli --minify --bundle --targets '>= 0.25%' bun/$FILE -o output/$FILE
just css bun/$FILE
# check result
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
echo "🚨 lightningcss failed with $EXIT_CODE"
exit $EXIT_CODE
fi
# EXIT_CODE=$?
# if [ $EXIT_CODE -ne 0 ]; then
# echo "🚨 lightningcss failed with $EXIT_CODE"
# exit $EXIT_CODE
# fi
else
bun run ./bun_build.js bun/$FILE
just js bun/$FILE
# bun build bun/$FILE --outdir output
fi
done
Expand Down Expand Up @@ -116,7 +116,7 @@ function build {
echo "⭐ Rebuilding bun"
bun_build
echo "⭐ Rebuilding forest"
opam exec -- forester build # 2>&1 > build/forester.log # --dev
just forest
show_result
# echo "⭐ Copying assets"
copy_extra_assets
Expand Down
42 changes: 17 additions & 25 deletions build_changed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,44 @@ set -eo pipefail
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
PROJECT_ROOT="$SCRIPT_DIR"

function remove_output_file {
echo "🚨removing output/$1"
rm output/$1
}

while IFS= read -r line; do
IFS=':' read -ra ADDR <<< "$line"
EVENT="${ADDR[0]}"
CHANGED_FILE="${ADDR[1]}"
# echo emoji for information
echo "ℹ️$EVENT: $CHANGED_FILE"
echo "ℹ️ $EVENT: $CHANGED_FILE"
CHANGED_FILE_BASENAME=$(basename $CHANGED_FILE)
# get the dirname of the changed file
CHANGED_FILE_DIRNAME=$(basename $(dirname $CHANGED_FILE))
# # get the file name relative to the project root
# CHANGED_FILE_RELATIVE=$(realpath --relative-to=$PROJECT_ROOT $CHANGED_FILE)
CHANGED_FILE_RELATIVE=$(realpath --relative-to=$PROJECT_ROOT $CHANGED_FILE)
# echo "📂$CHANGED_FILE_DIRNAME"
if [[ $CHANGED_FILE == *".css" ]] || [[ $CHANGED_FILE == *".js" ]]; then
# remove_output_file $CHANGED_FILE_BASENAME
./build.sh
if [[ $CHANGED_FILE == *".css" ]]; then
just css $CHANGED_FILE_RELATIVE
# this should cover .js .ts .jsx .tsx
elif [[ $CHANGED_FILE_DIRNAME == "bun" ]]; then
just js $CHANGED_FILE_RELATIVE
elif [[ $CHANGED_FILE == *".xsl" ]]; then
remove_output_file $CHANGED_FILE_BASENAME
./build.sh
just copy $CHANGED_FILE_RELATIVE
elif [[ $CHANGED_FILE == *".tree" ]]; then
# remove_output_file $CHANGED_FILE_BASENAME
./build.sh
just forest
elif [[ $CHANGED_FILE == *".tex" ]]; then
./build.sh
# even with full rebuild, updates to preambles are NOT reflected
# ./build.sh
just forest
elif [[ $CHANGED_FILE == *".bib" ]]; then
./bib.sh
just bib
elif [[ $CHANGED_FILE == *".glsl" ]]; then
mkdir -p output/shader/
cp -f assets/shader/* output/shader/
just glsl $CHANGED_FILE_RELATIVE
elif [[ $CHANGED_FILE == *".typ" ]]; then
mkdir -p output/shader/
cp -f assets/typst/* output/typst/
just typ $CHANGED_FILE_RELATIVE
elif [[ $CHANGED_FILE == *".domain" ]] || [[ $CHANGED_FILE == *".style" ]] || [[ $CHANGED_FILE == *".substance" ]] || [[ $CHANGED_FILE == *".trio.json" ]]; then
mkdir -p output/penrose/
cp -f assets/penrose/* output/penrose/
elif [[ $CHANGED_FILE_DIRNAME == "bun" ]]; then
./build.sh
just penrose $CHANGED_FILE_RELATIVE
else
echo "🤷 No action for $LINE"
fi

(mkdir -p build/live && realpath --relative-to=$PROJECT_ROOT $CHANGED_FILE > build/live/updated_file.txt)
done

touch build/live/trigger.txt
touch build/live/trigger.txt
2 changes: 1 addition & 1 deletion dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ POLL="--poll 500ms" # $POLL
BUZY_UPDATE="--on-busy-update queue" # $BUZY_UPDATE
DEBOUNCE="--debounce 500ms" # $DEBOUNCE

watchexec --quiet --ignore-nothing --no-meta $DEBOUNCE --project-origin . -e tree,tex,bib,css,js,jsx,xsl,ts,tsx,glsl,typ,domain,style,substance,trio.json -w trees -w assets -w tex -w bun --emit-events-to=stdio -- ./build_changed.sh &
watchexec --quiet --ignore-nothing --no-meta $DEBOUNCE --project-origin . -e tree,tex,bib,css,js,jsx,xsl,ts,tsx,glsl,typ,domain,style,substance,json -w trees -w assets -w tex -w bun --emit-events-to=stdio -- ./build_changed.sh &

export PORT=1314

Expand Down
1 change: 1 addition & 0 deletions dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ app.listen(port, async ({ hostname, port }) => {

// postpone to debounce
setTimeout(() => {
console.log('🔥live reload:', updated_file_name.trim())
app.server?.publish(
'update',
JSON.stringify({
Expand Down
25 changes: 25 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,30 @@ thm:
bib:
./bib.sh

glsl SOURCE:
mkdir -p output/shader/
cp -f {{SOURCE}} output/shader/

css SOURCE:
bunx lightningcss-cli --minify --bundle --targets '>= 0.25%' {{SOURCE}} -o output/{{file_name(SOURCE)}}

js SOURCE:
bun run bun_build.js {{SOURCE}}

forest:
opam exec -- forester build # 2>&1 > build/forester.log # --dev

copy SOURCE:
-rm output/{{file_name(SOURCE)}} > /dev/null 2>&1
cp -f {{SOURCE}} output/

typ SOURCE:
mkdir -p output/typst/
cp -f {{SOURCE}} output/typst/

penrose SOURCE:
mkdir -p output/penrose/
cp -f {{SOURCE}} output/penrose/

# act:
# ./act.sh
2 changes: 1 addition & 1 deletion trees/uts-000Q.tree
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

\loadjs{penrose.js}
\penrose{penrose/walk-on-spheres.trio.json}
}
}

0 comments on commit b812e12

Please sign in to comment.