11#! /bin/bash
2- # set -x
2+ # set -x
33
44# requires drawio desktop and libxml2-utils
55drawio=' /mnt/c/Program Files/draw.io/draw.io.exe'
66in=' src/aec3po.drawio'
77xml=diagrams.xml
8+ extension=' png' # png or pdf
9+ output_dir=' resources/diagrams/'
810declare -a filters
911
1012# Function to display help
1113usage () {
12- echo " Usage: $0 input.drawio -f filter1 -f filter2 ..."
13- echo " input.drawio Specify the input draw.io file (mandatory)"
14- echo " -f, --filter VALUE Specify one or more filters (optional)"
15- echo " -h, --help Show this help message"
14+ echo " Usage: $0 [FILTER] [FILTER] ..."
15+ echo " FILTER Specify one or more filters (optional)"
16+ echo " -h, --help Show this help message"
1617 exit 1
1718}
1819
1920# Parse arguments
20- if [[ -z " $1 " || " $1 " == " -h" || " $1 " == " --help" ]]; then
21+ if [[ " $1 " == " -h" || " $1 " == " --help" ]]; then
2122 usage
2223fi
2324
24- in=$1
25- shift
26-
27- while [[ " $1 " =~ ^- && ! " $1 " == " --" ]]; do
28- case $1 in
29- -f | --filter ) shift ; filters+=($1 );;
30- -h | --help ) usage;;
31- * ) usage;;
32- esac
25+ while [[ " $1 " != " " ]]; do
26+ filters+=($1 )
3327 shift
3428done
3529
36- # Validate mandatory argument
37- if [[ -z " $in " ]]; then
38- echo " Error: Input file is required."
39- usage
40- fi
41-
4230# Export all tab names from the .drawio file
4331echo " Extracting tabs" 1>&2
4432" $drawio " --export --format xml --uncompressed -o $xml $in > /dev/null 2& > /dev/null
@@ -49,19 +37,20 @@ IFS=$'\n'
4937tabs=($( xmllint --xpath " //diagram/@name" $xml | sed -E ' s/ name="([^"]+)"/\1/g' ) ) # an array
5038rm $xml
5139
40+ mkdir -p $output_dir
5241for (( i= 0 ; i< ${# tabs[@]} ; i++ ))
5342do
5443 tab=" ${tabs[$i]} "
5544 if [[ ${# filters[@]} -eq 0 ]]; then
5645 echo " Exporting: $tab " 1>&2
57- " $drawio " -x -f png -s 2 -p $i -o " resources/diagrams/ $ tab .png " " $in " > /dev/null 2& > /dev/null
46+ " $drawio " -x -f $extension -s 2 -p $i -o " $output_dir$ tab .$extension " " $in " > /dev/null 2& > /dev/null
5847 else
5948 exported=false
6049 for filter in " ${filters[@]} " ; do
6150 if [[ " $exported " = " false" ]]; then
6251 if [[ " ${tab,,} " =~ ${filter,,} ]]; then
6352 echo " Exporting: $tab " 1>&2
64- " $drawio " -x -f png -s 2 -p $i -o " $tab .png " " $in " > /dev/null 2& > /dev/null
53+ " $drawio " -x -f $extension -s 2 -p $i -o " $output_dir$ tab .$extension " " $in " > /dev/null 2& > /dev/null
6554 exported=true
6655 fi
6756 fi
0 commit comments