|
| 1 | +set -e |
| 2 | + |
| 3 | +# Determine the latest stable release tag on nodejs/node (skip pre-releases |
| 4 | +# like `-rc`/`-nightly`, taking the highest version-sorted tag). |
| 5 | +LATEST_TAG=$(git ls-remote --tags --refs --sort='-v:refname' \ |
| 6 | + https://github.com/nodejs/node.git 'v*' \ |
| 7 | + | awk -F/ '$NF !~ /-/ { print $NF; exit }') |
| 8 | + |
| 9 | +if [ -z "$LATEST_TAG" ]; then |
| 10 | + echo "Could not determine the latest nodejs/node release tag" >&2 |
| 11 | + exit 1 |
| 12 | +fi |
| 13 | + |
| 14 | +# Persist the tag so the build step can use it as the docs version |
| 15 | +echo "$LATEST_TAG" > .node-tag |
| 16 | + |
| 17 | +echo "Building docs for nodejs/node $LATEST_TAG" |
| 18 | + |
| 19 | +# Clone the repository at that tag with no checkout and shallow history |
| 20 | +git clone --depth 1 --branch "$LATEST_TAG" --filter=blob:none --sparse \ |
| 21 | + https://github.com/nodejs/node.git |
| 22 | + |
| 23 | +# Move into the cloned directory |
| 24 | +cd node |
| 25 | + |
| 26 | +# Enable sparse checkout and specify the folder |
| 27 | +git sparse-checkout set lib doc . |
| 28 | + |
| 29 | +# TODO(@avivkeller): Remove this rewrite once nodejs/node embeds |
| 30 | +# `<DocumentationIndex />` directly. |
| 31 | +INTRODUCED_IN=$(sed -n 's/^<!--introduced_in=\(.*\)-->$/\1/p' ./doc/api/documentation.md) |
| 32 | + |
| 33 | +{ |
| 34 | + printf -- '---\nmdx: true\ntype: misc\n' |
| 35 | + if [ -n "$INTRODUCED_IN" ]; then |
| 36 | + printf -- 'introduced_in: %s\n' "$INTRODUCED_IN" |
| 37 | + fi |
| 38 | + printf -- '---\n' |
| 39 | + sed \ |
| 40 | + -e 's|<!-- STABILITY_OVERVIEW_SLOT_BEGIN -->|<DocumentationIndex />|' \ |
| 41 | + -e '/^<!--.*-->$/d' \ |
| 42 | + -e '/^<!-- YAML$/,/^-->$/d' \ |
| 43 | + ./doc/api/documentation.md |
| 44 | +} > ./doc/api/index.md |
| 45 | + |
| 46 | +rm ./doc/api/documentation.md |
| 47 | + |
| 48 | +# Move back out |
| 49 | +cd .. |
| 50 | + |
| 51 | +# Install dependencies |
| 52 | +pnpm install --frozen-lockfile |
| 53 | + |
| 54 | +# Create the ./out directory |
| 55 | +mkdir -p out |
0 commit comments