Compare commits

..

No commits in common. "c80437a6b451945fd368e9f7a824c8d523656e9d" and "1afa6886edc8936fbc8d816354a14c004953b0c3" have entirely different histories.

View File

@ -34,28 +34,14 @@ 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="$(realpath --relative-base=./ "${OPTARG}")"
OUTPUT_DIR="$(echo "${OPTARG}" | sed 's:/*$::')"
;;
s)
SOURCE_DIR="$(realpath --relative-base=./ "${OPTARG}")"
SOURCE_DIR="$(echo "${OPTARG}" | sed 's:/*$::')"
;;
j)
JOBS="${OPTARG}"
@ -70,7 +56,7 @@ do
SERVER_FLAG=1
;;
h)
print_help
print_usage
exit
;;
*)
@ -92,11 +78,11 @@ export SOURCE_DIR
function process_file() {
local file="$1"
local DEST_FILE="${OUTPUT_DIR}/${file/#${SOURCE_DIR}\//}"
local DEST_FILE
local DEST_DIR
if [[ $file = *.php ]]
then
DEST_FILE="${DEST_FILE::-4}"
DEST_FILE="${OUTPUT_DIR}/${file:((${#SOURCE_DIR} + 1)):-4}"
DEST_DIR="$(dirname "$DEST_FILE")"
if ! [ "$file" -nt "$DEST_FILE" ]
then
@ -110,6 +96,7 @@ 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
@ -129,13 +116,3 @@ 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