Improved and modularized the build system

This commit is contained in:
2025-12-07 21:26:03 +01:00
parent 1e03a00cde
commit 36a286545c
7 changed files with 109 additions and 48 deletions

View File

@@ -4,51 +4,59 @@ set -e
ARCHIVE_DIR=tul-thesis
JS_AUTOGEN=src/data/autogen.js
mkdir -p $ARCHIVE_DIR
#echo -n "const programmes = " > $JS_AUTOGEN
#curl "https://stag.tul.cz/StagPortletsJSR168/ProhlizeniPrint?stateClass=cz.zcu.stag.portlets168.prohlizeni.browser.BrowserFakultaSearchState&wservice=programy/getStudijniProgramy&outputFormat=CSV&pouzePlatne=true&lang=cs" | csvjson -e cp1250 | jq --tab 'group_by(.fakulta | ascii_downcase) | [.[] | {
# key: .[0].fakulta | ascii_downcase | if . == "fe" then "ef" else . end | if . == "fa" then "fua" else . end,
# value: [.[] | {
# code: .kod | ascii_upcase,
# type: .typ | ascii_downcase // .titulZkr // .titul,
# title: .titulZkr // .titul // "bez titulu",
# form: .forma | ascii_downcase,
# year: .platnyOd | round,
# cs_name: .nazevCz // .nazev,
# en_name: .nazevAn // .nazev
# }]
#}] | from_entries' >> $JS_AUTOGEN
TEMPLATE=template_upstream
ZIP=template.zip
if [ ! -d $TEMPLATE ]; then
git clone git@gordon.zumepro.cz:tul/tultemplate2 $TEMPLATE
else
cd $TEMPLATE
git pull
cd ..
fi
function check_deps() {
echo "-> Checking dependencies"
for dep in "csvjson" "jq" "bash" "wget" "typst" "git" "git-lfs" "zip"
do
if type $dep &>/dev/null
then
echo " found $dep"
else
echo " missing dependency: $dep" 1>&2
exit 1
fi
done
}
TEMPLATE_PACKDIR=$TEMPLATE/target/pack/bundle
function build() {
mkdir -p $ARCHIVE_DIR
rm -rf $TEMPLATE_PACKDIR
cd $TEMPLATE
make bundle
cd ..
echo "-> Fetching programmes"
bash build/pull_programmes.sh | bash build/parse_programmes.sh > $JS_AUTOGEN
cp -r \
$TEMPLATE_PACKDIR/. \
$ARCHIVE_DIR
echo "-> Generating template bundle"
rm -r $ARCHIVE_DIR
bash build/bundle_template.sh $ARCHIVE_DIR $TEMPLATE
rm template.zip
zip -r template.zip $ARCHIVE_DIR
echo "-> Zipping archive"
rm $ZIP || true
zip -r $ZIP $ARCHIVE_DIR
echo "const available_templates = [" > $JS_AUTOGEN
ls -1 $ARCHIVE_DIR | grep "\.typ$" | sed -e 's/\(.*\)\..*/\t"\1",/g' >> $JS_AUTOGEN
echo "];" >> $JS_AUTOGEN
echo "-> Enumerating available templates"
bash build/enumerate_templates.sh $ARCHIVE_DIR >> $JS_AUTOGEN
date +%s%N > version
echo "-> Stamping build"
date +%s%N > version
}
function clean() {
rm -rf $ARCHIVE_DIR $JS_AUTOGEN $TEMPLATE $ZIP || true
}
subcommand=$1
case $subcommand in
"build")
check_deps
build
;;
"clean")
clean
;;
*)
echo "usage: build.sh build|clean"
;;
esac

21
build/bundle_template.sh Executable file
View File

@@ -0,0 +1,21 @@
#!/bin/bash
if [ ! -d $2 ]; then
git clone git@gordon.zumepro.cz:tul/tultemplate2 $2
else
cd $2
git pull
cd ..
fi
TEMPLATE_PACKDIR=$2/target/pack/bundle
rm -r $TEMPLATE_PACKDIR || true
cd $2
make bundle
cd ..
rm -r ./$1 || true
cp -r \
$TEMPLATE_PACKDIR/. \
$1

5
build/enumerate_templates.sh Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
echo -n "const available_templates=["
ls -1 $1 | grep "\.typ$" | sed -e 's/\(.*\)\..*/"\1"/g' | tr '\n' ','
echo -n "]"

19
build/parse_programmes.sh Executable file
View File

@@ -0,0 +1,19 @@
#!/bin/bash
echo -n "const programmes="
csvjson -e cp1250 \
| jq -rc '
group_by(.fakulta | ascii_downcase) | map({
key: (.[0].fakulta | ascii_downcase |
if . == "fe" then "ef" elif . == "fa" then "fua" else . end
),
value: map({
code: (.kod | ascii_upcase),
type: ((.typ | ascii_downcase) // .titulZkr // .titul),
title: (.titulZkr // .titul // "bez titulu"),
form: (.forma | ascii_downcase),
year: (.platnyOd | round),
cs_name: (.nazevCz // .nazev),
en_name: (.nazevAn // .nazev)
})
}) | from_entries'

3
build/pull_programmes.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
curl "https://stag.tul.cz/StagPortletsJSR168/ProhlizeniPrint?stateClass=cz.zcu.stag.portlets168.prohlizeni.browser.BrowserFakultaSearchState&wservice=programy/getStudijniProgramy&outputFormat=CSV&pouzePlatne=true&lang=cs"

14
flake.lock generated
View File

@@ -40,11 +40,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1764642553,
"narHash": "sha256-mvbFFzVBhVK1FjyPHZGMAKpNiqkr7k++xIwy+p/NQvA=",
"lastModified": 1764947035,
"narHash": "sha256-EYHSjVM4Ox4lvCXUMiKKs2vETUSL5mx+J2FfutM7T9w=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "f720de59066162ee879adcc8c79e15c51fe6bfb4",
"rev": "a672be65651c80d3f592a89b3945466584a22069",
"type": "github"
},
"original": {
@@ -160,12 +160,12 @@
"utils": "utils"
},
"locked": {
"lastModified": 1764752648,
"lastModified": 1764930776,
"lfs": true,
"narHash": "sha256-Tfb53MGuKIKOPBE/7Q33YCQ7YeErT8N4petwhqp/4eQ=",
"narHash": "sha256-h7Tq95B3w+yACAq35tzUk4AzIvo+eRfhdiqw8v8+1XY=",
"ref": "refs/heads/master",
"rev": "972cc19ecbc06b349e573b05aba006afdd0d136f",
"revCount": 207,
"rev": "359a0da6405befde08f0d03a0f047c2b643a818e",
"revCount": 210,
"type": "git",
"url": "https://git.zumepro.cz/tul/tultemplate2"
},

View File

@@ -8,6 +8,11 @@
outputs = { nixpkgs, utils, tultemplate2, ... }: (utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
studyProgrammeList = builtins.fetchurl {
name = "stag-raw_study_programmes";
url = "https://stag.tul.cz/StagPortletsJSR168/ProhlizeniPrint?stateClass=cz.zcu.stag.portlets168.prohlizeni.browser.BrowserFakultaSearchState&wservice=programy/getStudijniProgramy&outputFormat=CSV&pouzePlatne=true&lang=cs";
sha256 = "13m3cs2csjz3py4l03l14xqn9957j7vyy4s09x5l01f18gm12gh2";
};
tultemplategen = pkgs.stdenv.mkDerivation {
name = "tultemplategen";
src = ./.;
@@ -17,9 +22,9 @@
cp -R ${tultemplate2.packages.${system}.bundle} $packageRootDir
chmod -R +w $packageRootDir
${pkgs.zip}/bin/zip -r template.zip $packageRootDir
echo "const available_templates = [" > $autogenFile
ls -1 $packageRootDir | grep "\.typ$" | sed -e 's/\(.*\)\..*/\t"\1",/g' >> $autogenFile
echo "];" >> $autogenFile
PATH="$PATH:${pkgs.csvkit}/bin:${pkgs.jq}/bin"
cat ${studyProgrammeList} | ${pkgs.bash}/bin/bash build/parse_programmes.sh > $autogenFile
${pkgs.bash}/bin/bash build/enumerate_templates.sh $packageRootDir >> $autogenFile
'';
installPhase = ''