|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +API_VERSION=$1 |
| 4 | +DOCS_PATH=docs/surfaces/admin |
| 5 | +SRC_PATH=src/surfaces/admin |
| 6 | +COMPONENTS_DEFINITIONS=src/surfaces/admin/components.d.ts |
| 7 | +COMPONENTS_TS=src/surfaces/admin/components.ts |
| 8 | +SHOPIFY_DEV_PATH="../../../shopify-dev" |
| 9 | +DOT_DEV_DOCS_JSON="$SHOPIFY_DEV_PATH/db/data/docs/templated_apis/app_bridge/generated_docs_data.json" |
| 10 | +GENERATED_DOCS_JSON="./$DOCS_PATH/generated/generated_docs_data.json" |
| 11 | + |
| 12 | +fail_and_exit() { |
| 13 | + echo "** Failed to generate docs" |
| 14 | + echo "See https://vault.shopify.io/page/Extension-Docs~SkgE.md" |
| 15 | + exit $1 |
| 16 | +} |
| 17 | + |
| 18 | +run_sed() { |
| 19 | + if [[ "$OSTYPE" == "darwin"* ]]; then |
| 20 | + # macOS |
| 21 | + sed -i '' "$1" "$2" |
| 22 | + else |
| 23 | + # Linux and other Unix-like systems |
| 24 | + sed -i "$1" "$2" |
| 25 | + fi |
| 26 | +} |
| 27 | + |
| 28 | +if [ -z $API_VERSION ] |
| 29 | +then |
| 30 | + API_VERSION="unstable" |
| 31 | + echo "Building docs for 'unstable' admin UI extensions API. You can add a calver version argument (e.g. 'yarn docs:admin 2023-07') to generate the docs for a stable version." |
| 32 | +else |
| 33 | + echo "Building docs for '$API_VERSION' admin UI extensions API." |
| 34 | + echo "When generating docs for a stable version, 'unstable' docs are not regenerated. This avoids overwriting other unstable changes that are not included in this version." |
| 35 | + echo "If you need to update the 'unstable' version, run this command again without the '$API_VERSION' parameter." |
| 36 | +fi |
| 37 | + |
| 38 | +COMPILE_DOCS="yarn tsc --project $DOCS_PATH/tsconfig.ab.docs.json --moduleResolution node --target esNext --module CommonJS && yarn generate-docs --overridePath ./$DOCS_PATH/typeOverride.json --input ./$DOCS_PATH/reference ./$SRC_PATH --typesInput ./$SRC_PATH --output ./$DOCS_PATH/generated" |
| 39 | +# COMPILE_STATIC_PAGES="yarn tsc $DOCS_PATH/staticPages/*.doc.ts --moduleResolution node --target esNext --module CommonJS && yarn generate-docs --isLandingPage --input ./$DOCS_PATH/staticPages --output ./$DOCS_PATH/generated" |
| 40 | + |
| 41 | +# Rename components.d.ts to components.ts so it can be picked up be the compiler |
| 42 | +cp $COMPONENTS_DEFINITIONS $COMPONENTS_TS |
| 43 | +# Remove references to HTMLElement |
| 44 | +run_sed "s/typeof globalThis.HTMLElement/any/" $COMPONENTS_TS |
| 45 | + |
| 46 | +eval $COMPILE_DOCS |
| 47 | +build_exit=$? |
| 48 | + |
| 49 | +# Remove .doc.js files |
| 50 | +find ./ -name '*.doc*.js' -exec rm -r {} \; |
| 51 | +# Remove components.ts as it's no longer needed |
| 52 | +rm $COMPONENTS_TS |
| 53 | + |
| 54 | +if [ $build_exit -ne 0 ]; then |
| 55 | + fail_and_exit $build_exit |
| 56 | +fi |
| 57 | + |
| 58 | +# Make sure https://shopify.dev URLs are relative so they work in Spin. |
| 59 | +# See https://github.com/Shopify/generate-docs/issues/181 |
| 60 | +run_sed 's/https:\/\/shopify.dev//gi' ./$DOCS_PATH/generated/generated_docs_data.json |
| 61 | +sed_exit=$? |
| 62 | +if [ $sed_exit -ne 0 ]; then |
| 63 | + fail_and_exit $sed_exit |
| 64 | +fi |
| 65 | + |
| 66 | +if [ -d $SHOPIFY_DEV_PATH ]; then |
| 67 | + mkdir -p $SHOPIFY_DEV_PATH/db/data/docs/templated_apis/app_bridge |
| 68 | + |
| 69 | + jq 'map(select(.category != "Experimental Components"))' $DOT_DEV_DOCS_JSON > temp1.json |
| 70 | + |
| 71 | + jq 'map(.category = "Experimental Components")' $GENERATED_DOCS_JSON > temp2.json |
| 72 | + |
| 73 | + jq -s '.[0] + .[1]' temp1.json temp2.json > $DOT_DEV_DOCS_JSON |
| 74 | + |
| 75 | + rm temp1.json temp2.json |
| 76 | + |
| 77 | + rsync -a --delete ./$DOCS_PATH/screenshots/ $SHOPIFY_DEV_PATH/app/assets/images/templated-apis-screenshots/admin-extensions/$API_VERSION |
| 78 | + |
| 79 | + if [ -n "$SPIN_SHOPIFY_DEV_SERVICE_FQDN" ]; then |
| 80 | + echo "Docs: https://$SPIN_SHOPIFY_DEV_SERVICE_FQDN/docs/api/admin-extensions" |
| 81 | + else |
| 82 | + echo "Docs: https://shopify-dev.myshopify.io/docs/api/admin-extensions" |
| 83 | + fi |
| 84 | +else |
| 85 | + echo "Not copying docs to shopify-dev because it was not found at $SHOPIFY_DEV_PATH." |
| 86 | +fi |
0 commit comments