From a31f1743751d67cebe8a63c4620b34a3e073eebf Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Thu, 30 Dec 2021 02:45:29 +0000 Subject: [PATCH] add dark variants to ts janky but works, and should report if theres a situation its not ready to handle. --- .gitignore | 1 + Makefile | 19 ++++++++++++------- scripts/dark-variant.sh | 33 +++++++++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index f923b57..fd2b94f 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ instructions-debian.txt cl.md ./telegram/ mautrix/ +tempts/ matacc.txt diff --git a/Makefile b/Makefile index ef6bcc1..7254eff 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,7 @@ ifeq ($(DEBUG), on) SOURCEMAP := --sourcemap TYPECHECK := tsc -noEmit --project ts/tsconfig.json # jank - COPYTS := rm -r $(DATA)/web/js/ts; cp -r ts $(DATA)/web/js + COPYTS := rm -r $(DATA)/web/js/ts; cp -r tempts $(DATA)/web/js UNCSS := cp $(DATA)/web/css/bundle.css $(DATA)/bundle.css else LDFLAGS := -s -w $(LDFLAGS) @@ -91,13 +91,18 @@ email: typescript: $(TYPECHECK) + $(adding dark variants to typescript) + -rm -r tempts + cp -r ts tempts + scripts/dark-variant.sh ts tempts + scripts/dark-variant.sh ts tempts/modules $(info compiling typescript) -mkdir -p $(DATA)/web/js - -$(ESBUILD) --bundle ts/admin.ts $(SOURCEMAP) --outfile=./$(DATA)/web/js/admin.js --minify - -$(ESBUILD) --bundle ts/pwr.ts $(SOURCEMAP) --outfile=./$(DATA)/web/js/pwr.js --minify - -$(ESBUILD) --bundle ts/form.ts $(SOURCEMAP) --outfile=./$(DATA)/web/js/form.js --minify - -$(ESBUILD) --bundle ts/setup.ts $(SOURCEMAP) --outfile=./$(DATA)/web/js/setup.js --minify - -$(ESBUILD) --bundle ts/crash.ts --outfile=./$(DATA)/crash.js --minify + -$(ESBUILD) --bundle tempts/admin.ts $(SOURCEMAP) --outfile=./$(DATA)/web/js/admin.js --minify + -$(ESBUILD) --bundle tempts/pwr.ts $(SOURCEMAP) --outfile=./$(DATA)/web/js/pwr.js --minify + -$(ESBUILD) --bundle tempts/form.ts $(SOURCEMAP) --outfile=./$(DATA)/web/js/form.js --minify + -$(ESBUILD) --bundle tempts/setup.ts $(SOURCEMAP) --outfile=./$(DATA)/web/js/setup.js --minify + -$(ESBUILD) --bundle tempts/crash.ts --outfile=./$(DATA)/crash.js --minify $(COPYTS) swagger: @@ -130,7 +135,7 @@ variants-html: $(info copying html) cp -r html $(DATA)/ $(info adding dark variants to html) - scripts/dark-variant.sh $(DATA)/html + scripts/dark-variant.sh html $(DATA)/html copy: $(info copying fonts) diff --git a/scripts/dark-variant.sh b/scripts/dark-variant.sh index 2dd6abb..0b6a9dd 100755 --- a/scripts/dark-variant.sh +++ b/scripts/dark-variant.sh @@ -1,7 +1,32 @@ #!/bin/bash -for f in $1/*.html; do - for color in neutral positive urge warning info critical; do - sed -i "s/~${color}/~${color} dark:~d_${color}/g" $f +if [[ "$1" == "html" ]]; then + for f in $2/*.html; do + for color in neutral positive urge warning info critical; do + sed -i "s/~${color}/~${color} dark:~d_${color}/g" $f + done done -done +elif [[ "$1" == "ts" ]]; then + for f in $2/*.ts; do + # FIXME: inline html + for l in $(grep -n "~neutral\|~positive\|~urge\|~warning\|~info\|~critical" $f | sed -e 's/:.*//g'); do + # for l in $(sed -n '/classList/=' $f); do + line=$(sed -n "${l}p" $f) + echo $line | grep "classList" &> /dev/null + if [ $? -eq 0 ]; then + echo $line | sed 's/.*classList//; s/).*//' | grep "~neutral\|~positive\|~urge\|~warning\|~info\|~critical" &> /dev/null + if [ $? -eq 0 ]; then + echo "found classList @ " $l + for color in neutral positive urge warning info critical; do + sed -i "${l},${l}s/\"~${color}\"/\"~${color}\", \"dark:~d_${color}\"/g" $f + done + else + echo "FIX: classList found, but color tag wasn't in it" + fi + else + echo "found inline @ " $l ", " $(sed -n "${l}p" $f) + sed -i "${l},${l}s/~${color}/~${color} dark:~d_${color}/g" $f + fi + done + done +fi