Skip to content

Commit

Permalink
Feat: the JSON Schema HTML viewer generator script now supports gener…
Browse files Browse the repository at this point in the history
…ating only for one particular CycloneDX version, including the possibility of generating the HTML only for draft version of CycloneDX during dev time.

Signed-off-by: Nicolas-Peiffer <[email protected]>

Fix the deletion of the docs folder

Signed-off-by: Nicolas-Peiffer <[email protected]>
  • Loading branch information
Nicolas-Peiffer committed Aug 29, 2024
1 parent f18b992 commit 05767c6
Showing 1 changed file with 56 additions and 6 deletions.
62 changes: 56 additions & 6 deletions docgen/json/gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ THIS_PATH="$(realpath "$(dirname "$0")")"
SCHEMA_PATH="$(realpath "$THIS_PATH/../../schema")"
DOCS_PATH="$THIS_PATH/docs"
TEMPLATES_PATH="$THIS_PATH/templates"
VALID_CYCLONEDX_VERSIONS=(1.2 1.3 1.4 1.5 1.6)
DRAFT_CYCLONEDX_VERSIONS=()

echo "Deleting folder $DOCS_PATH"
rm -f -R "$DOCS_PATH"
mkdir -p "$DOCS_PATH/"{1.2,1.3,1.4,1.5,1.6}

# Check to see if generate-schema-doc is executable and is in the path. If not, install JSON Schema for Humans.
if ! [ -x "$(command -v generate-schema-doc)" ]
Expand All @@ -16,8 +18,31 @@ then
pip3 install -r "$THIS_PATH/requirements.txt"
fi

# Function to check if a version is in an array
version_in_list() {
local version="$1"
shift
local list=("$@")
for item in "${list[@]}"; do
if [[ "$item" == "$version" ]]; then
return 0
fi
done
return 1
}

generate () {
version="$1"

# Check if the version match a valid CycloneDX version or a draft under development
if ! version_in_list "$version" "${VALID_CYCLONEDX_VERSIONS[@]}" && ! version_in_list "$version" "${DRAFT_CYCLONEDX_VERSIONS[@]}"; then
echo "Failed: wrong CycloneDX version: $version"
exit 1
fi

echo "Create folder $DOCS_PATH/$version"
mkdir -p "$DOCS_PATH/$version"

title="CycloneDX v${version} JSON Reference"
echo "Generating: $title"

Expand Down Expand Up @@ -45,8 +70,33 @@ generate () {
sed -i -e "s/\${version}/$version/g" "$DOCS_PATH/$version/index.html"
}

generate 1.2
generate 1.3
generate 1.4
generate 1.5
generate 1.6
USAGE_HELP="Generate HTML JSON Schema navigator for CyccloneDX
Usage: $0 <version> : runs only for <version>
$0 : loops over all valid and draft CycloneDX versions"

# Main logic to handle the argument using a switch case
case "$#" in
0)
# No arguments provided: Loop over all VALID_CYCLONEDX_VERSIONS and DRAFT_CYCLONEDX_VERSIONS
for version in "${VALID_CYCLONEDX_VERSIONS[@]}" "${DRAFT_CYCLONEDX_VERSIONS[@]}"; do
generate "$version"
done
;;
1)
case "$1" in
"-h"|"--help")
echo "Usage: $USAGE_HELP"
exit 1
;;
*)
# One argument provided: Call generate with the specific version
generate "$1"
;;
esac
;;
*)
# More than one argument provided: Show usage help
echo "Usage: $USAGE_HELP"
exit 1
;;
esac

0 comments on commit 05767c6

Please sign in to comment.