Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/next/external/extensions/gen-sample-extension-docs.sh
Views: 3956
## Hooks1function extension_metadata_ready__499_display_docs_generation_start_info() {2display_alert "Generating hook documentation and sample extension"3}45function extension_metadata_ready__docs_markdown() {6generate_markdown_docs_to_stdout >"${DEST}/"${LOG_SUBPATH}"/hooks.auto.docs.md"7}89function extension_metadata_ready__docs_sample_extension() {10mkdir -p "${SRC}/userpatches/extensions"11generate_sample_extension_to_stdout >"${SRC}/userpatches/extensions/sample-extension.sh"12}1314## Internal functions1516### Common stuff17function read_common_data() {18export HOOK_POINT_CALLS_COUNT=$(wc -l <"${EXTENSION_MANAGER_TMP_DIR}/hook_point_calls.txt")19export HOOK_POINT_CALLS_UNIQUE_COUNT=$(sort <"${EXTENSION_MANAGER_TMP_DIR}/hook_point_calls.txt" | uniq | wc -l)20export HOOK_POINTS_WITH_MULTIPLE_CALLS=""2122# Read the hook_points (main, official names) from the hook point ordering file.23export ALL_HOOK_POINT_CALLS=$(xargs echo -n <"${EXTENSION_MANAGER_TMP_DIR}/hook_point_calls.txt")24}2526function loop_over_hook_points_and_call() {27local callback="$1"28HOOK_POINT_COUNTER=029for one_hook_point in ${ALL_HOOK_POINT_CALLS}; do30export HOOK_POINT_COUNTER=$((HOOK_POINT_COUNTER + 1))31export HOOK_POINT="${one_hook_point}"32export MARKDOWN_HEAD="$(head -1 "${EXTENSION_MANAGER_TMP_DIR}/${one_hook_point}.orig.md")"33export MARKDOWN_BODY="$(tail -n +2 "${EXTENSION_MANAGER_TMP_DIR}/${one_hook_point}.orig.md")"34export COMPATIBILITY_NAMES="$(xargs echo -n <"${EXTENSION_MANAGER_TMP_DIR}/${one_hook_point}.compat")"35${callback}36done37}3839## Markdown stuff40function generate_markdown_docs_to_stdout() {41read_common_data42cat <<MASTER_HEADER43# Armbian build system extensibility documentation44- This documentation is auto-generated.45MASTER_HEADER4647[[ $HOOK_POINT_CALLS_COUNT -gt $HOOK_POINT_CALLS_UNIQUE_COUNT ]] && {48# Some hook points were called multiple times, determine which.49HOOK_POINTS_WITH_MULTIPLE_CALLS=$(comm -13 <(sort <"${EXTENSION_MANAGER_TMP_DIR}/hook_point_calls.txt" | uniq) <(sort <"${EXTENSION_MANAGER_TMP_DIR}/hook_point_calls.txt") | sort | uniq | xargs echo -n)5051cat <<MULTIPLE_CALLS_WARNING52- *Important:* The following hook points where called multiple times during the documentation generation. This can be indicative of a bug in the build system. Please check the sources for the invocation of the following hooks: \`${HOOK_POINTS_WITH_MULTIPLE_CALLS}\`.53MULTIPLE_CALLS_WARNING5455}5657cat <<PRE_HOOKS_HEADER58## Hooks59- Hooks are listed in the order they are called.60PRE_HOOKS_HEADER6162loop_over_hook_points_and_call "generate_markdown_one_hook_point_to_stdout"6364cat <<MASTER_FOOTER65------------------------------------------------------------------------------------------66MASTER_FOOTER6768}6970function generate_markdown_one_hook_point_to_stdout() {71# Hook name in 3rd level title, first line of description in a blockquote.72# The rest in a normal block.73cat <<HOOK_DOCS74### \`${one_hook_point}\`75> ${MARKDOWN_HEAD}7677${MARKDOWN_BODY}7879HOOK_DOCS8081[[ "${COMPATIBILITY_NAMES}" != "" ]] && {82echo -e "\n\nAlso known as (for backwards compatibility only):"83for old_name in ${COMPATIBILITY_NAMES}; do84echo "- \`${old_name}\`"85done86}8788echo ""89}9091## Bash sample extension stuff92generate_sample_extension_to_stdout() {93read_common_data94cat <<HEADER95# Sample Armbian build system extension with all extension methods.96# This file is auto-generated from and by the build system itself.97# Please, always use the latest version of this file as a starting point for your own extensions.98# Generation date: $(date)99# Read more about the build system at https://docs.armbian.com/Developer-Guide_Build-Preparation/100101HEADER102103loop_over_hook_points_and_call "generate_bash_sample_for_hook_point"104}105106generate_bash_sample_for_hook_point() {107# Include the markdown documentation as a comment.108# Right now clean it up naively (remove backticks, mostly) but we could pipe through stuff to get better plaintext. (pandoc is a 155mb binary FYI)109local COMMENT_HEAD="#### $(echo "${MARKDOWN_HEAD}" | tr '`' '"')"110# shellcheck disable=SC2001111local COMMENT_BODY="$(echo "${MARKDOWN_BODY}" | tr '`' '"' | sed -e 's/^/### /')"112113local bonus=""114[[ "${HOOK_POINT_COUNTER}" == "1" ]] && bonus="$(echo -e "\n\texport PROGRESS_DISPLAY=verysilent # Example: export a variable. This one silences the built.")"115116cat <<SAMPLE_BASH_CODE117${COMMENT_HEAD}118${COMMENT_BODY}119function ${HOOK_POINT}__be_more_awesome() {120# @TODO: Please rename this function to reflect what it does, but preserve the "${HOOK_POINT}__" prefix.121display_alert "Being awesome at \${HOOK_POINT}" "\${EXTENSION}" "info"${bonus}122}123124SAMPLE_BASH_CODE125}126127128