Merge pull request #10387 from ToolJet/docs-pr/bash-modification

Modification in docs PR app's bash file to pick last version from doc…
This commit is contained in:
Adish M 2024-07-17 01:02:02 +05:30 committed by GitHub
commit 87887b605a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

30
docs/build-latest-version.sh Normal file → Executable file
View file

@ -1,9 +1,33 @@
#!/bin/bash
set -e
jq '[.[0]]' versions.json > tmp_versions.json
mv tmp_versions.json versions.json
CONFIG_FILE="docusaurus.config.js"
# Extract lastVersion from docusaurus.config.js using sed
LAST_VERSION=$(sed -n "s/.*lastVersion: *'\\([^']*\\)'.*/\\1/p" "$CONFIG_FILE")
if [ -z "$LAST_VERSION" ]; then
echo "Error: lastVersion not found in $CONFIG_FILE"
exit 1
fi
echo "Found lastVersion: $LAST_VERSION"
# Extract all version numbers from the entire file
ALL_VERSIONS=$(grep -oE "'[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z]+)?'" "$CONFIG_FILE" | sed "s/'//g" | sort -u -V -r)
if [ -z "$ALL_VERSIONS" ]; then
echo "Error: No versions found in $CONFIG_FILE"
exit 1
fi
echo "Found raw versions:"
echo "$ALL_VERSIONS"
# Convert the extracted versions into a JSON array format
VERSION_ARRAY=$(echo "$ALL_VERSIONS" | jq -R -s -c 'split("\n")[:-1] + ["'"$LAST_VERSION"'"] | unique')
echo "Updating versions.json with: $VERSION_ARRAY"
# Update versions.json with combined data
echo $VERSION_ARRAY | jq . > versions.json
# Install dependencies and build the project
npm i && npm run build
exec "$@"
exec "$@"