Compare commits

...

3 Commits

View File

@ -34,14 +34,28 @@ function print_usage() {
echo "$0 -S [-o <output dir>]"
}
function print_help() {
printf "PHP Site Generator\n\n"
printf "SYNOPSIS:\n"
print_usage
printf "\nOPTIONS:\n"
printf "\t-o <output dir> Output directory\n"
printf "\t-s <source dir> Source directory\n"
printf "\t-j <num> Number of jobs to run\n"
printf "\t-S Run a server on localhost:8080\n"
printf "\t-h Show help information\n"
printf "\n"
}
while getopts "o:s:j:Sh" opt
do
case "$opt" in
o)
OUTPUT_DIR="$(echo "${OPTARG}" | sed 's:/*$::')"
OUTPUT_DIR="$(realpath --relative-base=./ "${OPTARG}")"
;;
s)
SOURCE_DIR="$(echo "${OPTARG}" | sed 's:/*$::')"
SOURCE_DIR="$(realpath --relative-base=./ "${OPTARG}")"
;;
j)
JOBS="${OPTARG}"
@ -56,7 +70,7 @@ do
SERVER_FLAG=1
;;
h)
print_usage
print_help
exit
;;
*)
@ -78,11 +92,11 @@ export SOURCE_DIR
function process_file() {
local file="$1"
local DEST_FILE
local DEST_FILE="${OUTPUT_DIR}/${file/#${SOURCE_DIR}\//}"
local DEST_DIR
if [[ $file = *.php ]]
then
DEST_FILE="${OUTPUT_DIR}/${file:((${#SOURCE_DIR} + 1)):-4}"
DEST_FILE="${DEST_FILE::-4}"
DEST_DIR="$(dirname "$DEST_FILE")"
if ! [ "$file" -nt "$DEST_FILE" ]
then
@ -96,7 +110,6 @@ function process_file() {
php "$file" > "$DEST_FILE"
echo "done"
else
DEST_FILE="${OUTPUT_DIR}/${file:((${#SOURCE_DIR} + 1))}"
DEST_DIR="$(dirname "$DEST_FILE")"
if ! [ "$file" -nt "$DEST_FILE" ]
then
@ -116,3 +129,13 @@ export -f process_file
find "$SOURCE_DIR" -type f -not -name '*.cfg.php' |
parallel -j"${JOBS}" process_file
SOURCE_FILE_LIST=$(cd "$SOURCE_DIR" && find . -type f -and -not -name '*.cfg.php' | sed 's/.php$//')
OUTPUT_FILE_LIST=$(cd "$OUTPUT_DIR" && find . -type f)
for file in $(echo "${SOURCE_FILE_LIST[@]}" "${OUTPUT_FILE_LIST[@]}" | tr ' ' '\n' | sort | uniq -u)
do
FILE_PATH=$(realpath --relative-base=./ "$OUTPUT_DIR/$file")
echo "Deleting file $FILE_PATH"
rm "$FILE_PATH"
done