Skip to content

Instantly share code, notes, and snippets.

@ymek
Created August 2, 2016 17:18
Show Gist options
  • Save ymek/c846281dcae8910e5c94e14ded3cfdbd to your computer and use it in GitHub Desktop.
Save ymek/c846281dcae8910e5c94e14ded3cfdbd to your computer and use it in GitHub Desktop.
Generate HTML/Markdown from RAML on file changes
#!/usr/bin/env bash
#
# Attempts to regenerate HTML and Markdown files from RAML upon component
# file changes.
#
# NOTE: Requires `fswatch`
FSWATCH=$(which fswatch)
RAML2HTML=$(which raml2html)
RAML2MD=$(which raml2md)
EXCLUSION_PATTERN=".*"
INCLUSION_PATTERN=".*\.([ry]aml|example|schema|json)"
RAML_DOCNAME="agents"
WATCH_FOLDER="./"
# Check for supporting libs
[[ -e ${FSWATCH} ]] || echo "fswatch not found. Run 'brew install fswatch' and try again."
[[ -e ${RAML2HTML} ]] || echo "raml2html not found. Run 'npm install -g raml2tml' and try again."
[[ -e ${RAML2MD} ]] || echo "raml2md not found. Run 'npm install -g raml2md' and try again."
[[ -e ${FSWATCH} && -e ${RAML2HTML} && -e ${RAML2MD} ]] || exit 1
${FSWATCH} -r -o -E -e "${EXCLUSION_PATTERN}" -i "${INCLUSION_PATTERN}" ${WATCH_FOLDER} | \
xargs -I'{}' sh -c \
"${RAML2HTML} ${RAML_DOCNAME}.raml > _generated/${RAML_DOCNAME}.html && \
${RAML2MD} ${RAML_DOCNAME}.raml > _generated/${RAML_DOCNAME}.md"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment