Last active
October 29, 2018 01:04
-
-
Save Risto-Stevcev/fbcc2b4c84f752740f69d0ecdeb62001 to your computer and use it in GitHub Desktop.
Helper shell script to run odoc for bucklescript projects
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 | |
readonly PKG_NAME_RE='.*\"name\":\s*"\(.*\)".*' | |
readonly PKG_NAME=$( | |
cat bsconfig.json \ | |
| grep "\"name\":" \ | |
| sed -e 's/'"${PKG_NAME_RE}"'/\1/g' | |
) | |
readonly DOCS=${1:-docs} | |
readonly ODOC=$(which odoc) | |
readonly LIB=./lib/bs | |
readonly CMT_FILES=$(find ${LIB} -name "*.cmt") | |
readonly ODOC_FILES=$(echo ${CMT_FILES} | sed "s/cmt/odoc/g") | |
readonly INCLUDES=$(find ${LIB} -type d | tail -n +2 | xargs echo | sed -e 's/ / -I /g' -e 's/^/-I /') | |
function cleanup_folder { | |
echo "<< Cleanup folder..." | |
rm -rf ${DOCS} | |
mkdir ${DOCS} | |
echo ">> Done!" | |
} | |
function compile_docs { | |
echo "<< Compiling docs..." | |
for file in ${CMT_FILES}; do | |
${ODOC} compile \ | |
${INCLUDES} \ | |
--pkg=${PKG_NAME} \ | |
${file} | |
done | |
echo ">> Done!" | |
} | |
function generate_html { | |
echo "<< Generating HTML..." | |
for file in ${ODOC_FILES}; do | |
${ODOC} html \ | |
${INCLUDES} \ | |
-o ${DOCS} \ | |
--semantic-uris \ | |
${file} | |
done | |
echo ">> Done!" | |
} | |
function cleanup_strings { | |
echo "<< Cleanup strings..." | |
find ${DOCS} -type f -name "*.html" -exec \ | |
perl -i.bak -pe 's|\"BS:.*?@\"|\"BS\"|g' {} + | |
echo ">> Done!" | |
} | |
function add_support_files { | |
echo "<< Add support files..." | |
${ODOC} support-files -o ${DOCS} | |
find ${DOCS} -name "*.css" -exec \ | |
sed -i -e 's/max-width: 90ex;//' -e 's/margin-left: calc(10vw + 20ex);/margin-left: 20px;/' {} + | |
echo ">> Done!" | |
} | |
if which odoc; then | |
cleanup_folder | |
compile_docs | |
generate_html | |
cleanup_strings | |
add_support_files | |
echo "Finished!" | |
else | |
echo -e "\nCouldn't find odoc. Make sure it's on your \$PATH" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment