UnitJS/unit.js.tpl

37 lines
530 B
Smarty
Executable file

#!/bin/sh
indent()
{
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 {
$(printf "${MODULES}" | sed -e 's|:|,\n|g' -e 's|[^,\n]\+|&: &|g' | indent | indent)
};
$(for file in "${@}"; do includeModule "${file}"; done | indent)
})();
EOF