Consolodate project directories into variables.

This commit is contained in:
Nicolás A. Ortega Froysa 2022-11-08 15:52:12 +01:00
parent bfcd194a09
commit 7c1aec3497

View File

@ -26,6 +26,11 @@ ISIDORE_AUTHOR_NAME=""
PROG_NAME=$0
PROJECT_NAME="Isidore"
SOURCE_DIR="site/"
TMP_DIR="/tmp/isidore-workdesk/"
OUTPUT_DIR="output/"
TEMPLATE_DIR="templates/"
##
# Create the configuration file. This function is called if it does not already
# exist.
@ -134,8 +139,8 @@ function new_project()
read NEW_PROJECT_URL
fi
mkdir $NEW_PROJECT_DIR
mkdir -p $NEW_PROJECT_DIR/site/
mkdir -p $NEW_PROJECT_DIR/templates/
mkdir -p $NEW_PROJECT_DIR/$SOURCE_DIR
mkdir -p $NEW_PROJECT_DIR/$TEMPLATE_DIR
echo \
"<?php
\$site_name = \"$NEW_PROJECT_NAME\";
@ -155,9 +160,9 @@ function new_project()
function clean_project()
{
check_in_project
if [ -d "./output/" ]
if [ -d "$OUTPUT_DIR" ]
then
rm -r ./output/
rm -r $OUTPUT_DIR
fi
echo "Project cleaned."
}
@ -169,31 +174,32 @@ function build_project()
{
check_in_project
mkdir -p ./output/
WORKDESK="/tmp/isidore-workdesk"
CFG_HEADER_FILE="$WORKDESK/config-header.php"
mkdir -p $WORKDESK
for i in $(find site/ -name '*.php' -not -name '*.cfg.php')
CFG_HEADER_FILE="$TMP_DIR/config-header.php"
mkdir -p $OUTPUT_DIR
mkdir -p $TMP_DIR
echo "<?php include(getcwd() . '/config.php'); ?>" > $CFG_HEADER_FILE
for i in $(find $SOURCE_DIR -type d)
do
echo "<?php include getcwd() . '/config.php'; ?>" > $CFG_HEADER_FILE
mkdir -p $WORKDESK/${i%/*}
cat $CFG_HEADER_FILE $i > $WORKDESK/$i
# the 4 offset is to avoid including `site/`
: ${i:4}
OUT_DIR="./output/${_%/*}"
mkdir -p $OUT_DIR
: ${i: :-4}
OUT_FILE="$OUT_DIR/${_##*/}"
php $WORKDESK/$i > $OUT_FILE
mkdir -p $OUTPUT_DIR/${i:${#SOURCE_DIR}}
mkdir -p $TMP_DIR/$i
done
for i in $(find site/ -type f -not -name '*.php')
for i in $(find $SOURCE_DIR -name '*.php' -not -name '*.cfg.php')
do
mkdir -p ./output/${i%/*}
cp $i ./output/$i
cat $CFG_HEADER_FILE $i > $TMP_DIR/$i
: ${i:${#SOURCE_DIR}}
OUT_FILE="$OUTPUT_DIR/${_: :-4}"
php $TMP_DIR/$i > $OUT_FILE
done
rm -r $WORKDESK
for i in $(find $SOURCE_DIR -type f -not -name '*.php')
do
cp $i $OUTPUT_DIR/${i:${#SOURCE_DIR}}
done
rm -r $TMP_DIR
}
set_config_vars
@ -228,7 +234,7 @@ case $1 in
build)
build_project;;
serve|server)
php -S localhost:8080 -t ./output/;;
php -S localhost:8080 -t $OUTPUT_DIR/;;
clean)
clean_project;;
help)