Misc fixes

This commit is contained in:
2024-08-25 14:48:38 +02:00
parent e925c0831e
commit ff0fb951d1
+31 -29
View File
@@ -1,29 +1,30 @@
#!/usr/bin/env sh
#!/usr/bin/env bash
name="Application"
EXCLUDE_FILES="webxdc.js LICENSE README README.md *.sh *.xdc *~"
EXCLUDE_PATHS="webxdc.js LICENSE README README.md *.sh *.xdc *~"
function usage () {
echo "Usage: ${0} [-hgp]"
echo " -h Display this message"
echo " -f Lint and format all source files"
echo " -g Add pre-commit hook which formats and lints code"
echo " -p Optimize all files and pack the project as a WebXDC"
function usage() {
echo "Usage: ${0} [-hfgp] [-e PATH]"
echo " -h Display this message"
echo " -e [PATH] Filename or folder to exclude from package. For several"
echo " files or folders, use this flag several times with one argument."
echo " -f Lint and format all source files"
echo " -g Add pre-commit hook which formats and lints code"
echo " -p Optimize all files and pack the project as a WebXDC"
exit 0
}
function add_pre_commit_hook () {
function add_pre_commit_hook() {
echo "Not implemented."
:
}
function lint_and_format () {
function lint_and_format() {
if [[ -x "$(command -v rslint)" ]]; then
echo "Linting JavaScript source files."
find . -iname "*.js" -exec rslint -f {} \;
else
echo "rslint not found. Cannot lint source."
return -1
fi
if [[ -x "$(command -v js-beautify)" ]]; then
@@ -31,29 +32,27 @@ function lint_and_format () {
find . -iname "*.js" -exec js-beautify -r {} \;
else
echo "js-beautify not found. Cannot format source."
return -1
fi
}
# $1 - filename
function extract_toml () {
function extract_toml() {
while IFS='= ' read -r lhs rhs; do
if [[ ! $lhs =~ ^\ *# && -n $lhs ]]; then
rhs="${rhs%%\#*}"
rhs="${rhs%%*( )}"
rhs="${rhs%\"*}"
rhs="${rhs#\"*}"
declare -g $lhs="$rhs"
rhs="${rhs%%\#*}"
rhs="${rhs%%*( )}"
rhs="${rhs%\"*}"
rhs="${rhs#\"*}"
declare -g $lhs="$rhs"
fi
done < $1
done <$1
}
function webxdc_create () {
function webxdc_create() {
[[ ! -f ./index.html ]] && echo "Webxdc requires it's apps to have AT LEAST an index.html. Aborting." && exit -1
mkdir temp
if [[ -x "$(command -v minify)" ]]; then
echo "Minifying all source files."
cp --parents -r *.html *.css *.js temp/
@@ -77,7 +76,7 @@ function webxdc_create () {
else
echo "optipng not found. Not optimizing any PNG files."
fi
echo "Removing all existing xdc packages."
rm -f *.xdc
@@ -90,24 +89,27 @@ function webxdc_create () {
if [[ -x "$(command -v zip)" ]]; then
echo "Packing project into an xdc package."
zip -9 --recurse-paths "${name}.xdc" --exclude $EXCLUDE_FILES -- * > /dev/null
zip -9 --recurse-paths "${name}.xdc" --exclude $EXCLUDE_PATHS -- * >/dev/null
echo "Output: ${name}.xdc."
mv temp/* .
rmdir temp
mv temp/* . 2>/dev/null
rmdir temp/
else
echo "The program zip could not be found. It is required to pack Webxdc applications. Aborting."
mv temp/* . 2>/dev/null
rmdir temp/
exit -1
mv temp/* .
rmdir temp
fi
}
[[ "$#" -eq 0 ]] && usage
while getopts ":hgpf" option; do
while getopts ":h:egpf" option; do
case ${option} in
h)
usage
;;
e)
EXCLUDE_PATHS+=" ${OPTARG}"
;;
f)
lint_and_format
;;