-
-
Save Kibubu/84b43aae76f49bba9e8102c897273324 to your computer and use it in GitHub Desktop.
Wrapper for mermaid-cli run within a docker container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Wrapper for mermaid-cli run within a docker container | |
# copy mmdc into $bin and use as you would use mermaid-cli | |
# Ensures the script exits if a command fails | |
set -e | |
# Docker image to use | |
DOCKER_IMAGE="minlag/mermaid-cli" | |
# Initial variable setup | |
input_file="" | |
output_file="" | |
config_file="" | |
css_file="" | |
puppeteer_config_file="" | |
# Parse command line arguments | |
while (( "$#" )); do | |
case "$1" in | |
-h|--help) | |
docker run --rm -it $DOCKER_IMAGE mmdc -h | |
exit 0 | |
;; | |
-i|--input) | |
input_file=$2 | |
shift 2 | |
;; | |
-o|--output) | |
output_file=$2 | |
shift 2 | |
;; | |
-c|--configFile) | |
config_file=$2 | |
shift 2 | |
;; | |
-C|--cssFile) | |
css_file=$2 | |
shift 2 | |
;; | |
-p|--puppeteerConfigFile) | |
puppeteer_config_file=$2 | |
shift 2 | |
;; | |
--) # end argument parsing | |
shift | |
break | |
;; | |
-*|--*=) # unsupported flags | |
echo "Error: Unsupported flag $1" >&2 | |
exit 1 | |
;; | |
*) # preserve positional arguments | |
params="$params $1" | |
shift | |
;; | |
esac | |
done | |
# # Ensure necessary files are specified | |
# if [ -z "$input_file" ]; then | |
# echo "Input file must be specified with -i or --input." | |
# exit 1 | |
# fi | |
if [ -n "$input_file" ] && [ -z "$output_file" ]; then | |
output_file="$input_file.svg" # default output naming if not specified | |
fi | |
# if [ -z "$output_file" ]; then | |
# output_file="$input_file.svg" # default output naming if not specified | |
# fi | |
# Prepare Docker volume mappings | |
input_args="-h" | |
volume_args="" | |
if [ -n "$input_file" ]; then | |
volume_args="-v $(pwd)/$input_file:/data/$input_file" | |
output_dir=$(dirname "$output_file") | |
output_base=$(basename "$output_file") | |
volume_args+=" -v $(pwd)/$output_dir:/data/$output_dir" | |
input_args="-i /data/$input_file" | |
output_args="-o /data/$output_dir/$output_base" | |
fi | |
# Additional files | |
if [ -n "$config_file" ]; then | |
volume_args+=" -v $(pwd)/$config_file:/data/$config_file" | |
fi | |
if [ -n "$css_file" ]; then | |
volume_args+=" -v $(pwd)/$css_file:/data/$css_file" | |
fi | |
if [ -n "$puppeteer_config_file" ]; then | |
volume_args+=" -v $(pwd)/$puppeteer_config_file:/data/$puppeteer_config_file" | |
fi | |
# Run the Docker command with all mounted volumes | |
docker run --rm -it \ | |
$volume_args \ | |
-w /data \ | |
$DOCKER_IMAGE mmdc $input_args $output_args $params |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment