Compare commits
No commits in common. "735afe998241e2a1cf6e38fe07dcb352fccb481b" and "48bdc40932c5f43052f7ff5ea17bfc0d6a8b6205" have entirely different histories.
735afe9982
...
48bdc40932
13
README.md
13
README.md
@ -14,15 +14,10 @@ Synopsis: `isidore <command> [options]`
|
||||
|
||||
Commands:
|
||||
|
||||
- `new [args] <dir>`: create a new project.
|
||||
- `<dir>`: new project directory.
|
||||
- `-i`: interactive mode.
|
||||
- `build [args]`: build the website.
|
||||
- `-j<n>`: number of jobs to run concurrently. With `0` it compiles all files
|
||||
at once.
|
||||
- `-v`: run with verbose output.
|
||||
- `serve`, `server [args]`: run an HTTP server of the output (default port 8080).
|
||||
- `-p <port>`: port number to bind server to.
|
||||
- `new [-i] <dir>`: create a new project directory `<dir>`. Use `-i` for
|
||||
interactive mode.
|
||||
- `build`: build the website (default).
|
||||
- `serve`, `server`: run an HTTP server of the output on port 8080.
|
||||
- `clean`: cleans build files.
|
||||
- `help`: show help information.
|
||||
- `version`: show Isidore version number.
|
||||
|
@ -4,7 +4,7 @@
|
||||
- New project subcommand
|
||||
- Basic project compilation
|
||||
- v0.2
|
||||
- Don't compile already compiled files
|
||||
- Multi-thread compiling
|
||||
- Helper functions & variables
|
||||
- v0.3
|
||||
- Markdown support
|
||||
|
132
isidore.sh
132
isidore.sh
@ -27,9 +27,9 @@ PROG_NAME=$0
|
||||
PROJECT_NAME="Isidore"
|
||||
|
||||
SOURCE_DIR="site/"
|
||||
TMP_DIR="/tmp/isidore-workdesk/"
|
||||
OUTPUT_DIR="output/"
|
||||
TEMPLATE_DIR="templates/"
|
||||
PROJECT_CONFIG_FILE="config.php"
|
||||
|
||||
##
|
||||
# Create the configuration file. This function is called if it does not already
|
||||
@ -92,11 +92,11 @@ function print_help()
|
||||
print_usage
|
||||
echo -e "\nCOMMANDS:
|
||||
new [-i] <dir>
|
||||
Create a new Isidore project
|
||||
build [-v] [-j<n>]
|
||||
Create a new Isidore project (use interactive mode with '-i')
|
||||
build
|
||||
Build the project rooted in the current directory
|
||||
serve | server [-p <port>]
|
||||
Serve a local HTTP server of the output directory
|
||||
serve | server
|
||||
Serve a local HTTP server of the output directory on port 8080
|
||||
clean
|
||||
Clean the built files
|
||||
version
|
||||
@ -110,7 +110,7 @@ function print_help()
|
||||
##
|
||||
function check_in_project()
|
||||
{
|
||||
if ! [ -f "$PROJECT_CONFIG_FILE" ] || ! [ -f "./.isidore-version" ]
|
||||
if ! [ -f "./config.php" ] || ! [ -f "./.isidore-version" ]
|
||||
then
|
||||
echo "ERROR: You are not currently in the root of an Isidore project."
|
||||
exit 1
|
||||
@ -128,9 +128,9 @@ function new_project()
|
||||
{
|
||||
echo "$PROJECT_NAME v$ISIDORE_VERSION"
|
||||
|
||||
local NEW_PROJECT_DIR=$1
|
||||
local NEW_PROJECT_NAME="New Project"
|
||||
local NEW_PROJECT_URL="http://example.com/"
|
||||
NEW_PROJECT_DIR=$1
|
||||
NEW_PROJECT_NAME="New Project"
|
||||
NEW_PROJECT_URL="http://example.com/"
|
||||
if [ $2 == 1 ]
|
||||
then
|
||||
echo -n "Project name: "
|
||||
@ -146,12 +146,12 @@ function new_project()
|
||||
\$site_name = \"$NEW_PROJECT_NAME\";
|
||||
\$site_author = \"$ISIDORE_AUTHOR_NAME\";
|
||||
\$site_url = \"$NEW_PROJECT_URL\";
|
||||
?>" >> $NEW_PROJECT_DIR/$PROJECT_CONFIG_FILE
|
||||
?>" >> $NEW_PROJECT_DIR/config.php
|
||||
echo "$ISIDORE_VERSION" > $NEW_PROJECT_DIR/.isidore-version
|
||||
|
||||
echo "New project created."
|
||||
[ $2 == 0 ] &&
|
||||
echo "Consider taking a look at the $NEW_PROJECT_DIR/$PROJECT_CONFIG_FILE file."
|
||||
echo "Consider taking a look at the $NEW_PROJECT_DIR/config.php file."
|
||||
}
|
||||
|
||||
##
|
||||
@ -169,67 +169,41 @@ function clean_project()
|
||||
|
||||
##
|
||||
# Build the project.
|
||||
#
|
||||
# Params:
|
||||
# $1 - Verbose flag
|
||||
# $2 - Maximum number of jobs to run
|
||||
##
|
||||
function build_project()
|
||||
{
|
||||
check_in_project
|
||||
|
||||
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
|
||||
mkdir -p $OUTPUT_DIR/${i:${#SOURCE_DIR}}
|
||||
mkdir -p $TMP_DIR/$i
|
||||
done
|
||||
|
||||
# number of current jobs
|
||||
local NUM_JOBS="\j"
|
||||
|
||||
for i in $(find site -type f -regextype posix-extended -not -regex '.*\.(cfg|CFG)\.(php|PHP)')
|
||||
for i in $(find $SOURCE_DIR -name '*.php' -not -name '*.cfg.php')
|
||||
do
|
||||
while (( $2 != 0 )) && (( ${NUM_JOBS@P} >= $2 ))
|
||||
do
|
||||
wait -n
|
||||
done
|
||||
|
||||
# parallel block
|
||||
(
|
||||
if [[ $i =~ .*\.(php|PHP) ]]
|
||||
then
|
||||
: ${i:${#SOURCE_DIR}}
|
||||
local OUT_FILE="$OUTPUT_DIR/${_: :-4}"
|
||||
if [ $1 == 1 ]
|
||||
then
|
||||
echo "Building $OUT_FILE ..."
|
||||
fi
|
||||
cat $PROJECT_CONFIG_FILE $i | php > $OUT_FILE
|
||||
else
|
||||
local OUT_FILE="$OUTPUT_DIR/${i:${#SOURCE_DIR}}"
|
||||
if [ $1 == 1 ]
|
||||
then
|
||||
echo "Copying $OUT_FILE ..."
|
||||
fi
|
||||
cp $i $OUT_FILE
|
||||
fi
|
||||
) &
|
||||
cat $CFG_HEADER_FILE $i > $TMP_DIR/$i
|
||||
: ${i:${#SOURCE_DIR}}
|
||||
OUT_FILE="$OUTPUT_DIR/${_: :-4}"
|
||||
php $TMP_DIR/$i > $OUT_FILE
|
||||
done
|
||||
|
||||
# wait for jobs to finish
|
||||
wait -n
|
||||
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
|
||||
|
||||
if [ $# -lt 1 ]
|
||||
then
|
||||
echo "No subcommand was specified. Use the 'help' subcommand."
|
||||
print_usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
new)
|
||||
if [ $# -lt 2 ]
|
||||
@ -250,59 +224,17 @@ case $1 in
|
||||
then
|
||||
NEW_DIR="$i"
|
||||
else
|
||||
echo "Unknown argument for new '$i'. Use the 'help' subcommand."
|
||||
echo "Unknown argument for new '$i'. Use the 'help' command."
|
||||
print_usage
|
||||
exit 1
|
||||
fi;;
|
||||
fi
|
||||
esac
|
||||
done
|
||||
new_project $NEW_DIR $INTERACTIVE;;
|
||||
build)
|
||||
VERBOSE=0
|
||||
JOBS=1
|
||||
for i in ${@:2}
|
||||
do
|
||||
case $i in
|
||||
-v)
|
||||
VERBOSE=1;;
|
||||
-j*)
|
||||
if ! [[ "$i" =~ ^-j[0-9]+$ ]]
|
||||
then
|
||||
echo "Argument '$i' badly formatted. Should be '-j<n>' where <n> is a number."
|
||||
print_usage
|
||||
exit 1
|
||||
fi
|
||||
JOBS=${i:2};;
|
||||
*)
|
||||
echo "Unknown argument for build '$i'. Use the 'help' subcommand."
|
||||
print_usage
|
||||
exit 1;;
|
||||
esac
|
||||
done
|
||||
build_project $VERBOSE $JOBS;;
|
||||
build_project;;
|
||||
serve|server)
|
||||
PORT=8080
|
||||
shift
|
||||
while getopts "p:" opt
|
||||
do
|
||||
case $opt in
|
||||
p)
|
||||
if ! [[ "$OPTARG" =~ ^[0-9]+$ ]]
|
||||
then
|
||||
echo "Invalid port $OPTARG. Please enter a number."
|
||||
exit 1
|
||||
fi
|
||||
PORT=$OPTARG;;
|
||||
?)
|
||||
echo "Invalid argument $OPTARG. Use the 'help' subcommand."
|
||||
print_usage
|
||||
exit 1;;
|
||||
:)
|
||||
echo "Option -$OPTARG requires an argument."
|
||||
exit 1;;
|
||||
esac
|
||||
done
|
||||
php -S localhost:$PORT -t $OUTPUT_DIR/;;
|
||||
php -S localhost:8080 -t $OUTPUT_DIR/;;
|
||||
clean)
|
||||
clean_project;;
|
||||
help)
|
||||
@ -310,7 +242,7 @@ case $1 in
|
||||
version)
|
||||
echo "$PROJECT_NAME v$ISIDORE_VERSION";;
|
||||
*)
|
||||
echo "Unknown command $1. Use the 'help' subcommand."
|
||||
echo "Unknown command $1. Use the 'help' command."
|
||||
print_usage
|
||||
exit 1;;
|
||||
esac
|
||||
|
Loading…
Reference in New Issue
Block a user