Skip to content
This repository has been archived by the owner on Jun 2, 2020. It is now read-only.

Commit

Permalink
Build markdown API docs for JS and Go packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Gierth committed Nov 17, 2017
1 parent fff3e07 commit 320198c
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash

set -ex

usage() {
echo "Usage: package.sh github.com/some-org/some-repo v1.2.3 path/to/destination/"
exit 1
}

[ "$1" ] || usage
[ "$2" ] || usage
[ "$3" ] || usage

repo="$(echo "$1" | sed -e 's/^https:\/\///' -e 's/git:\/\///' -e 's/git@github.com:/github.com\//' -e 's/\.git$//')"
name="$(echo "$repo" | sed -e 's/.*\///')"
ref="$2"
dest="$3"

if echo "$name" | grep -P '^go-' > /dev/null; then

# Go: get the source, run godoc2md
export GOPATH="$(pwd)/tmp/gopath"
go get -d -u -v "$repo"
(cd "$GOPATH/src/$repo" && git reset --hard HEAD && git fetch && git checkout "$ref")
mkdir -vp "$dest/$name"
cat <<EOF > "$dest/$name/index.md"
+++
title = "$name"
description = "Reference for $name package"
+++
$(godoc2md -v "$repo")
EOF
else

# JS: clone repo, npm install, run aegir docs
tmpdir="tmp/js"
mkdir -vp "$tmpdir"
if [ ! -d "$tmpdir/$name" ]; then
git clone -q "https://$repo" "$tmpdir/$name"
else
(cd "$tmpdir/$name" && git reset --hard HEAD && git fetch && git checkout "$ref")
fi

cd "$tmpdir/$name"
npm install --save
# npm link aegir
node_modules/.bin/aegir docs -m
cd -
mkdir -vp "$dest/$name"
cat "$tmpdir/$name/docs/index.md" | sed -e 's/^<!--.*$//' > "$dest/$name/index.md"
fi

0 comments on commit 320198c

Please sign in to comment.