Compare commits
3 Commits
1afa6886ed
...
c80437a6b4
Author | SHA1 | Date | |
---|---|---|---|
c80437a6b4 | |||
67c83bf85a | |||
a32d24a086 |
35
phpsg.sh
35
phpsg.sh
@ -34,14 +34,28 @@ function print_usage() {
|
|||||||
echo "$0 -S [-o <output dir>]"
|
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
|
while getopts "o:s:j:Sh" opt
|
||||||
do
|
do
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
o)
|
o)
|
||||||
OUTPUT_DIR="$(echo "${OPTARG}" | sed 's:/*$::')"
|
OUTPUT_DIR="$(realpath --relative-base=./ "${OPTARG}")"
|
||||||
;;
|
;;
|
||||||
s)
|
s)
|
||||||
SOURCE_DIR="$(echo "${OPTARG}" | sed 's:/*$::')"
|
SOURCE_DIR="$(realpath --relative-base=./ "${OPTARG}")"
|
||||||
;;
|
;;
|
||||||
j)
|
j)
|
||||||
JOBS="${OPTARG}"
|
JOBS="${OPTARG}"
|
||||||
@ -56,7 +70,7 @@ do
|
|||||||
SERVER_FLAG=1
|
SERVER_FLAG=1
|
||||||
;;
|
;;
|
||||||
h)
|
h)
|
||||||
print_usage
|
print_help
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
@ -78,11 +92,11 @@ export SOURCE_DIR
|
|||||||
|
|
||||||
function process_file() {
|
function process_file() {
|
||||||
local file="$1"
|
local file="$1"
|
||||||
local DEST_FILE
|
local DEST_FILE="${OUTPUT_DIR}/${file/#${SOURCE_DIR}\//}"
|
||||||
local DEST_DIR
|
local DEST_DIR
|
||||||
if [[ $file = *.php ]]
|
if [[ $file = *.php ]]
|
||||||
then
|
then
|
||||||
DEST_FILE="${OUTPUT_DIR}/${file:((${#SOURCE_DIR} + 1)):-4}"
|
DEST_FILE="${DEST_FILE::-4}"
|
||||||
DEST_DIR="$(dirname "$DEST_FILE")"
|
DEST_DIR="$(dirname "$DEST_FILE")"
|
||||||
if ! [ "$file" -nt "$DEST_FILE" ]
|
if ! [ "$file" -nt "$DEST_FILE" ]
|
||||||
then
|
then
|
||||||
@ -96,7 +110,6 @@ function process_file() {
|
|||||||
php "$file" > "$DEST_FILE"
|
php "$file" > "$DEST_FILE"
|
||||||
echo "done"
|
echo "done"
|
||||||
else
|
else
|
||||||
DEST_FILE="${OUTPUT_DIR}/${file:((${#SOURCE_DIR} + 1))}"
|
|
||||||
DEST_DIR="$(dirname "$DEST_FILE")"
|
DEST_DIR="$(dirname "$DEST_FILE")"
|
||||||
if ! [ "$file" -nt "$DEST_FILE" ]
|
if ! [ "$file" -nt "$DEST_FILE" ]
|
||||||
then
|
then
|
||||||
@ -116,3 +129,13 @@ export -f process_file
|
|||||||
|
|
||||||
find "$SOURCE_DIR" -type f -not -name '*.cfg.php' |
|
find "$SOURCE_DIR" -type f -not -name '*.cfg.php' |
|
||||||
parallel -j"${JOBS}" process_file
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user