generated from okp4/template-rust
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs): use fadroma-schema to generate docs
- Loading branch information
Showing
1 changed file
with
9 additions
and
15 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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\<\2\>\<\/code>/g' $DOCS_FOLDER/*.md | ||
rm $DOCS_FOLDER/*.tmp | ||
mv "${SCHEMA%.json}.md" "docs/${SCHEMA%.json}.md" | ||
done | ||
rm -rf $SCHEMA_FOLDER | ||
|