diff --git a/README.md b/README.md index 8c5d308..a09eaf8 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,13 @@ Synopsis: `isidore [options]` Commands: -- `new [-i] `: create a new project directory ``. Use `-i` for - interactive mode. -- `build [-v]`: build the website (default). Use `-v` for verbose. +- `new [-i] `: create a new project. + - ``: new project directory. + - `-i`: interactive mode. +- `build [-v] [-j]`: build the website. + - `-j`: number of jobs to run concurrently. With `0` it compiles all files + at once. + - `-v`: run with verbose output. - `serve`, `server`: run an HTTP server of the output on port 8080. - `clean`: cleans build files. - `help`: show help information. diff --git a/isidore.sh b/isidore.sh index 8a449d7..071fd95 100755 --- a/isidore.sh +++ b/isidore.sh @@ -92,8 +92,8 @@ function print_help() print_usage echo -e "\nCOMMANDS: new [-i] - Create a new Isidore project (use interactive mode with '-i') - build + Create a new Isidore project + build [-v] [-j] Build the project rooted in the current directory serve | server Serve a local HTTP server of the output directory on port 8080 @@ -172,6 +172,7 @@ function clean_project() # # Params: # $1 - Verbose flag +# $2 - Maximum number of jobs to run ## function build_project() { @@ -184,26 +185,40 @@ function build_project() mkdir -p $OUTPUT_DIR/${i:${#SOURCE_DIR}} 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)') do - if [[ $i =~ .*\.(php|PHP) ]] - then - : ${i:${#SOURCE_DIR}} - local OUT_FILE="$OUTPUT_DIR/${_: :-4}" - if [ $1 == 1 ] + while (( $2 != 0 )) && (( ${NUM_JOBS@P} >= $2 )) + do + wait -n + done + + # parallel block + ( + if [[ $i =~ .*\.(php|PHP) ]] then - echo "Building $OUT_FILE ..." + : ${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 $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 + ) & done + + # wait for jobs to finish + wait -n } set_config_vars @@ -244,6 +259,7 @@ case $1 in new_project $NEW_DIR $INTERACTIVE;; build) VERBOSE=0 + JOBS=1 if [ $# -gt 1 ] then for i in ${@:2} @@ -251,6 +267,14 @@ case $1 in case $i in -v) VERBOSE=1;; + -j*) + if ! [[ "$i" =~ ^-j[0-9]+$ ]] + then + echo "Argument '$i' badly formatted. Should be '-j' where is a number." + print_usage + exit 1 + fi + JOBS=${i:2};; *) echo "Unknown argument for build '$i'. Use the 'help' subcommand." print_usage @@ -258,7 +282,7 @@ case $1 in esac done fi - build_project $VERBOSE;; + build_project $VERBOSE $JOBS;; serve|server) php -S localhost:8080 -t $OUTPUT_DIR/;; clean)