From 0eed8a644e55d84e47d9043af17546d8b7948fab Mon Sep 17 00:00:00 2001 From: Jerome Date: Tue, 20 Oct 2020 22:19:47 +0200 Subject: [PATCH] #35 #19 --- Dockerfile | 2 +- outputs/build.dac | 6 +----- outputs/document/build.dac | 13 +++---------- outputs/note/build.dac | 11 ++--------- outputs/slides/build.dac | 11 ++--------- outputs/slides/html/build.dac | 14 ++++---------- scripts/docsascode/2asciidoc.sh | 4 ++-- scripts/docsascode/2md.sh | 4 ++-- scripts/docsascode/2rst.sh | 4 ++-- scripts/docsascode/buildDoc.sh | 21 ++++++++++++++------- scripts/docsascode/checkDoc.sh | 4 ++-- scripts/docsascode/entrypoint.sh | 8 +++++++- scripts/docsascode/meta_tools.sh | 4 ++-- scripts/docsascode/yq_functions.sh | 12 ++++++------ 14 files changed, 50 insertions(+), 68 deletions(-) diff --git a/Dockerfile b/Dockerfile index a821bc9..f3c358c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -153,7 +153,7 @@ RUN wget $(curl -s https://api.github.com/repos/mikefarah/yq/releases/latest | g # ----- DocsAsCode ----- -ADD scripts/docsascode/*.tex /usr/local/bin/templates/ +# ADD scripts/docsascode/*.tex /usr/local/bin/templates/ ADD scripts/docsascode/*.lua /usr/local/bin/templates/ ADD scripts/docsascode/*.sh /usr/local/bin/ diff --git a/outputs/build.dac b/outputs/build.dac index 29d7356..9b3516f 100644 --- a/outputs/build.dac +++ b/outputs/build.dac @@ -2,9 +2,5 @@ # set -xe function process { - echo "nothing to process" -} - -function postprocess { - echo "nothing to postprocess" + printf "nothing to process\n" } \ No newline at end of file diff --git a/outputs/document/build.dac b/outputs/document/build.dac index 16efabb..8f17766 100644 --- a/outputs/document/build.dac +++ b/outputs/document/build.dac @@ -50,17 +50,10 @@ function process { asciidoctor-pdf "${cmd_args[@]}" "$source_folder/.$filename.adoc" - echo " → file generated: "$output_file_prefix$filename.pdf -} - -function postprocess { - local input_file=$1 - local source_folder=$2 - local destination_folder=$3 - local filename=$4 - rm -rf $destination_folder/.asciidoctor/ rm -f $source_folder/.$filename.adoc chown $PID:$GID $destination_folder/$output_file_prefix$filename.pdf -} \ No newline at end of file + + echo $output_file_prefix$filename.pdf +} diff --git a/outputs/note/build.dac b/outputs/note/build.dac index 1dafd65..4a3e549 100644 --- a/outputs/note/build.dac +++ b/outputs/note/build.dac @@ -50,17 +50,10 @@ function process { asciidoctor-pdf "${cmd_args[@]}" "$source_folder/.$filename.adoc" - echo " → file generated: "$output_file_prefix$filename.pdf -} - -function postprocess { - local input_file=$1 - local source_folder=$2 - local destination_folder=$3 - local filename=$4 - rm -rf $destination_folder/.asciidoctor/ rm -f $source_folder/.$filename.adoc chown $PID:$GID $destination_folder/$output_file_prefix$filename.pdf + + echo $output_file_prefix$filename.pdf } \ No newline at end of file diff --git a/outputs/slides/build.dac b/outputs/slides/build.dac index b8bbb1e..83b38ef 100644 --- a/outputs/slides/build.dac +++ b/outputs/slides/build.dac @@ -50,17 +50,10 @@ function process { asciidoctor-pdf "${cmd_args[@]}" "$source_folder/.$filename.adoc" - echo " → file generated: "$output_file_prefix$filename.pdf -} - -function postprocess { - local input_file=$1 - local source_folder=$2 - local destination_folder=$3 - local filename=$4 - rm -rf $destination_folder/.asciidoctor/ rm -f $source_folder/.$filename.adoc chown $PID:$GID $destination_folder/$output_file_prefix$filename.pdf + + echo $output_file_prefix$filename.pdf } \ No newline at end of file diff --git a/outputs/slides/html/build.dac b/outputs/slides/html/build.dac index 9ce8038..8c45349 100644 --- a/outputs/slides/html/build.dac +++ b/outputs/slides/html/build.dac @@ -28,19 +28,13 @@ function process { asciidoctor-revealjs $options_diagram $options_style $options_higlighter $source_folder/.$filename.adoc $options_output chmod -R a+w $custom_destination_folder/ - echo " → file generated: "$filename.html - decktape automatic $custom_destination_folder/$filename.html $custom_destination_folder/$filename.pdf >> /dev/null - echo " → file generated: "$filename.pdf -} - -function postprocess { - local input_file=$1 - local source_folder=$2 - local destination_folder=$3 - local filename=$4 + # decktape automatic $custom_destination_folder/$filename.html $custom_destination_folder/$filename.pdf >> /dev/null + # echo " → file generated: "$filename.pdf rm -f $source_folder/.$filename.adoc chown $PID:$GID $custom_destination_folder/$filename.html $custom_destination_folder/$filename.pdf + + echo $filename.html } \ No newline at end of file diff --git a/scripts/docsascode/2asciidoc.sh b/scripts/docsascode/2asciidoc.sh index e5293a3..8259a78 100755 --- a/scripts/docsascode/2asciidoc.sh +++ b/scripts/docsascode/2asciidoc.sh @@ -4,7 +4,7 @@ source yq_functions.sh if [ "$#" -ne 2 ]; then - echo "Illegal number of parameters" + printf "Illegal number of parameters\n" exit -1 fi @@ -69,7 +69,7 @@ case "$1" in ;; *) - echo "extension not supported. only rst,md and adoc." + printf "extension not supported. only rst,md and adoc.\n" exit -1 ;; esac diff --git a/scripts/docsascode/2md.sh b/scripts/docsascode/2md.sh index b5a2f82..7f4452d 100755 --- a/scripts/docsascode/2md.sh +++ b/scripts/docsascode/2md.sh @@ -2,7 +2,7 @@ # set -xe if [ "$#" -ne 2 ]; then - echo "Illegal number of parameters" + printf "Illegal number of parameters\n" exit -1 fi @@ -27,7 +27,7 @@ case "$1" in ;; *) - echo "extension not supported. only rst,md, adoc." + printf "extension not supported. only rst,md, adoc.\n" exit -1 ;; esac diff --git a/scripts/docsascode/2rst.sh b/scripts/docsascode/2rst.sh index 4876328..5353ae5 100755 --- a/scripts/docsascode/2rst.sh +++ b/scripts/docsascode/2rst.sh @@ -2,7 +2,7 @@ # set -xe if [ "$#" -ne 2 ]; then - echo "Illegal number of parameters" + printf "Illegal number of parameters\n" exit -1 fi @@ -20,7 +20,7 @@ case "$1" in ;; *) - echo "extension not supported. only rst,md, adoc." + printf "extension not supported. only rst,md, adoc.\n" exit -1 ;; esac diff --git a/scripts/docsascode/buildDoc.sh b/scripts/docsascode/buildDoc.sh index 85f588f..b097075 100755 --- a/scripts/docsascode/buildDoc.sh +++ b/scripts/docsascode/buildDoc.sh @@ -16,12 +16,14 @@ function build_doc { [[ ! -z "$DEFAULT_DESTINATION" ]] && destination_folder=$DEFAULT_DESTINATION - echo "process file: "$filenameWithExtension + printf "process file: "$filenameWithExtension"\n" # prepare outputs initMeta $input_file - local meta_outputs=( $(readInMeta keywords $DEFAULT_OUTPUT) ) + local meta_outputs=$(readInMeta keywords $DEFAULT_OUTPUT) + meta_outputs=(${meta_outputs//,/ }) + # clean array declare -a outputs_arr for output in "${meta_outputs[@]}"; do @@ -83,7 +85,7 @@ function build_doc { # cp basic asciidoctor themes for dac theme extend cp -rf $(gem environment gemdir)/gems/asciidoctor-pdf-$ASCIIDOCTOR_PDF_VERSION/data/themes/* $current_output_template_path/ - echo " - process output: "$output + printf " - process output: "$output"\n" # prepare to launch commands to produce output rm -f $ymlFile @@ -94,8 +96,14 @@ function build_doc { source $current_output_template_path/build.dac # launch process - process $input_file $pathname $destination_folder $filenameNoExtension - postprocess $input_file $pathname $destination_folder $filenameNoExtension + resultFile=$(process $input_file $pathname $destination_folder $filenameNoExtension) + + if [ -f $destination_folder/$resultFile ]; then + printf " → file generated: "$resultFile"\n" + generatedFiles+=( "$destination_folder$resultFile" ) + else + printf " → NO file generated\n" + fi # clear temp folder rm -rf $current_output_template_path @@ -103,7 +111,6 @@ function build_doc { # remove ouput copy rm -rf /_output/ - } [[ -z "$DEFAULT_OUTPUT" ]] && DEFAULT_OUTPUT=output.document @@ -121,7 +128,7 @@ do shift ;; *) - echo "extension not supported. only rst,md, adoc." + printf "extension not supported. only rst,md, adoc.\n" exit -1 ;; esac diff --git a/scripts/docsascode/checkDoc.sh b/scripts/docsascode/checkDoc.sh index ab33488..a98f873 100755 --- a/scripts/docsascode/checkDoc.sh +++ b/scripts/docsascode/checkDoc.sh @@ -73,7 +73,7 @@ function check_doc { source $current_exe_folder/check.dac - echo -e "\nprocess file: "$1 + printf "\nprocess file: "$1"\n" #merge all .dict file into a single with pws header and remove blank lines cat $current_exe_folder/*.dict >> $current_exe_folder/.GLOBAL.dict 2>/dev/null @@ -105,7 +105,7 @@ do shift ;; *) - echo "extension not supported. only rst,md, adoc." + printf "extension not supported. only rst,md, adoc.\n" exit -1 ;; esac diff --git a/scripts/docsascode/entrypoint.sh b/scripts/docsascode/entrypoint.sh index be937ab..7b40bea 100755 --- a/scripts/docsascode/entrypoint.sh +++ b/scripts/docsascode/entrypoint.sh @@ -1,9 +1,15 @@ #! /bin/bash # set -xe +declare -a generatedFiles + case $1 in build) shift + # init list of generated files + # launch build of files source buildDoc.sh $* + # return generated files list + # echo ${generatedFiles[@]} ;; check) shift source checkDoc.sh $* @@ -11,5 +17,5 @@ case $1 in assemble) shift source assembleDoc.sh $* ;; - *) echo "usage : build sourcefiles\n check sourcefiles";; + *) printf "usage : build sourcefiles\n check sourcefiles\nassemble pdfFiles\n";; esac diff --git a/scripts/docsascode/meta_tools.sh b/scripts/docsascode/meta_tools.sh index 45a395e..e6d53cf 100755 --- a/scripts/docsascode/meta_tools.sh +++ b/scripts/docsascode/meta_tools.sh @@ -5,7 +5,7 @@ metaFile=/tmp/meta.yml function initMeta { if [ "$#" -ne 1 ]; then - echo "Illegal number of parameters" + printf "Illegal number of parameters\n" exit -1 fi @@ -34,7 +34,7 @@ function initMeta { ;; *) - echo "extension not supported. only rst,md, adoc." + printf "extension not supported. only rst,md, adoc.\n" exit -1 ;; esac diff --git a/scripts/docsascode/yq_functions.sh b/scripts/docsascode/yq_functions.sh index 54ea562..8f82fb9 100755 --- a/scripts/docsascode/yq_functions.sh +++ b/scripts/docsascode/yq_functions.sh @@ -44,12 +44,12 @@ function testreadVarInYml { printf "a:\n b: c\n e: ~\n" > $ymlFile cat $ymlFile - if [ "$(readVarInYml a.b D)" != 'c' ]; then echo "exit 1: $(readVarInYml a.b D)"; fi - if [ "$(readVarInYml a.b)" != 'c' ]; then echo "exit 2: $(readVarInYml a.b)"; fi - if [ "$(readVarInYml a.c D)" != 'D' ]; then echo "exit 3: $(readVarInYml a.c D)"; fi - if [ "$(readVarInYml a.c)" != '' ]; then echo "exit 4: $(readVarInYml a.c)"; fi - if [ "$(readVarInYml a.e D)" != 'D' ]; then echo "exit 5: $(readVarInYml a.e D)"; fi - if [ "$(readVarInYml a.e)" != '' ]; then echo "exit 6: $(readVarInYml a.e)"; fi + if [ "$(readVarInYml a.b D)" != 'c' ]; then printf "exit 1: $(readVarInYml a.b D)\n"; fi + if [ "$(readVarInYml a.b)" != 'c' ]; then printf "exit 2: $(readVarInYml a.b)\n"; fi + if [ "$(readVarInYml a.c D)" != 'D' ]; then printf "exit 3: $(readVarInYml a.c D)\n"; fi + if [ "$(readVarInYml a.c)" != '' ]; then printf "exit 4: $(readVarInYml a.c)\n"; fi + if [ "$(readVarInYml a.e D)" != 'D' ]; then printf "exit 5: $(readVarInYml a.e D)\n"; fi + if [ "$(readVarInYml a.e)" != '' ]; then printf "exit 6: $(readVarInYml a.e)\n"; fi rm -rf /tmp/test.yml ymlFile=$tmpYmlFile