Skip to content

Commit

Permalink
feat(docs): use fadroma-schema to generate docs
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed Aug 16, 2023
1 parent a8cb7cf commit ae792e0
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,32 +100,26 @@ rm -rf ${DOCS_FOLDER}/*
dependencies = ["docs-clean", "schema"]
description = "Generate documentation"
script = '''
echo "🔎 Checking jsonschema2md installed..."
if ! which jsonschema2md >/dev/null;
then
echo "\n❌ jsonschema2md could not be found"
echo " Consider installing jsonschema2md to generate documentation.\n"
echo "> \`npm install -g @adobe/jsonschema2md\`\n\n"
exit 1
fi
echo "📦 Installing fadroma-schema..."
npm install --save-dev @fadroma/[email protected]
echo "📚 Generating documentation in ${DOCS_FOLDER} folder..."
mkdir -p $SCHEMA_FOLDER
find contracts/*/schema -type f -maxdepth 1 -name '*.json' \
-exec sh -c 'cp "$@" "$0"' $SCHEMA_FOLDER/ {} +
rm -rf $DOCS_FOLDER
mkdir -p $DOCS_FOLDER
for SCHEMA in $(ls $SCHEMA_FOLDER); do
awk "{sub(\"#/definitions\",\"./${SCHEMA}/#/definitions\")} {print}" ${SCHEMA_FOLDER}/${SCHEMA} > ${SCHEMA_FOLDER}/tmp
mv ${SCHEMA_FOLDER}/tmp ${SCHEMA_FOLDER}/${SCHEMA}
done
rm -rf $DOCS_FOLDER
npm exec fadroma-schema ${SCHEMA_FOLDER}/tmp > "${SCHEMA%.json}.md"
jsonschema2md -d schema -o $DOCS_FOLDER --schema-extension json --schema-out $DOCS_FOLDER/schema
sed -i.tmp -E 's/([a-zA-Z]+)<([a-zA-Z0-9]+)>/<code>\1\&lt;\2\&gt;\<\/code>/g' $DOCS_FOLDER/*.md
rm $DOCS_FOLDER/*.tmp
mv "${SCHEMA%.json}.md" "docs/${SCHEMA%.json}.md"
done
rm -rf $SCHEMA_FOLDER
Expand Down

0 comments on commit ae792e0

Please sign in to comment.