Make the unit.js.tpl actually work with the new path of the files, remove silly printf hack for indentation by allowing only one indentation at a time and make sure empty lines don't get indented

This commit is contained in:
Tissevert 2020-05-16 17:04:46 +02:00
parent fcf5bdc55b
commit f0bd320683
1 changed files with 25 additions and 4 deletions

View File

@ -2,15 +2,36 @@
indent()
{
local tabs="$(printf '\t%.0s' `seq 1 $1`)"
sed "s|^|${tabs}|"
sed "s|^\(.\)|\t\1|"
}
moduleName()
{
local fileName="${1##*/}"
printf "${fileName%.*}"
}
MODULES=""
for file in "${@}"
do
MODULES="${MODULES}:$(moduleName "${file}")"
done
MODULES="${MODULES#:}"
includeModule()
{
cat <<EOF
function $(moduleName "${1}")() {
$(cat "${1}" | indent)
}
EOF
}
cat <<EOF
var unitJS = (function() {
return {
$(echo "${@}" | sed -e 's| |,\n|g' -e 's|\([^.\n]\+\)\.js|\u\1: \u\1|g' | indent 2)
$(printf "${MODULES}" | sed -e 's|:|,\n|g' -e 's|[^,\n]\+|&: &|g' | indent | indent)
};
$(cat "${@}" | indent 1)
$(for file in "${@}"; do includeModule "${file}"; done | indent)
})();
EOF