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

Build markdown API docs for JS and Go packages #43

Merged
merged 1 commit into from
Dec 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions scripts/pkg2md.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash

set -e

# Dependencies:
# - npm install aegir
# - go get -u github.com/davecheney/godoc2md

usage() {
echo "Usage: scripts/pkg2md.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
#
# TODO also render subdirectories
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 = "$name module reference"
+++

EOF
godoc2md -v "$repo" >> "$dest/$name/index.md"
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"
aegir docs -m
cd -
mkdir -vp "$dest/$name"
cat <<EOF > "$dest/$name/index.md"
+++
title = "$name"
description = "$name module reference"
+++

EOF
cat "$tmpdir/$name/docs/index.md" | sed -e 's/^<!--.*$//' >> "$dest/$name/index.md"
fi