Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made it more configurable #1

Merged
merged 2 commits into from Sep 3, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 41 additions & 13 deletions gendoc.sh
Expand Up @@ -5,7 +5,7 @@

# Run this script from the root of your project.
# It makes a temporary directory and generates appledoc documentation for your
# project in that directory.
# project in that directory.
# It then makes a local clone of your documentation branch (called gh-pages, by default)
# copies the generated appledoc html into a folder in the branch (called Documentation by default)
# commits the new documentation and pushes it back to the project repo.
Expand All @@ -17,7 +17,7 @@
# - the name of the root folder is the name of the project
# - your appledoc templates are in ~/.appledoc (can be a symlink)
# - you have a GlobalSettings.plist file in your appledoc templates folder
# - you've set values in GlobalSettings.plist for --project-company, --company-id
# - you've set values in GlobalSettings.plist for --project-company, --company-id

# The script looks at the remotes configured in the repo to try to work out what your github
# user name is, so that it can generate the correct urls for a docset feed.
Expand All @@ -29,20 +29,23 @@ originaldirectory=`git rev-parse --show-toplevel`
codebranch=`$git rev-parse --abbrev-ref HEAD`
docbranch="gh-pages"
projectname=`basename "$PWD"`
docdirectory="documentation"
docdirectory="Documentation"
initialdefaultcommitmessage="Initial documentation"
updatedefaultcommitmessage="Update documentation"
defaultcommitmessage=$updatedefaultcommitmessage
tempdir=/tmp/gendoc
publish=true
open=false
editcommit=false

# find real templates location (.appledoc might be a link)
pushd $HOME > /dev/null
link=`readlink ".appledoc"`
if [[ $link != "" ]];
then
cd $link
cd $link
else
cd ".appledoc"
cd ".appledoc"
fi
templates=`pwd`
popd > /dev/null
Expand All @@ -59,7 +62,7 @@ githubuser=${BASH_REMATCH[2]}
if [[ "$codebranch" == "gh-pages" ]]
then
echo "You seem to be on the gh-pages branch. Checkout a code branch instead."
exit 1
exit 1
fi

echo "Generating documentation for $projectname"
Expand All @@ -68,6 +71,11 @@ echo "Generating documentation for $projectname"
rm -rf "$tempdir"
mkdir -p -v "$tempdir"

# include settings file if it's present
if [ -e ./.appledoc.plist ]; then
echo "Found appledoc settings file"
settings=./.appledoc.plist
fi

# generate docset and html, install docset in xcode, create atom feed and downloadable package
appledoc \
Expand All @@ -83,18 +91,18 @@ appledoc \
--docset-package-url "http://$githubuser.github.com/$projectname/$docdirectory/%DOCSETPACKAGEFILENAME" \
--docset-fallback-url "http://$githubuser.github.com/projectname/$docdirectory/" \
--project-name $projectname \
-o "$tempdir" "$@" ./
-o "$tempdir" "$@" $settings ./

# clone doc branch of current repo into temporary location
$git clone "$originaldirectory" "$tempdir/branch"

if $git show-ref --tags --quiet --verify -- "refs/heads/$docbranch"
then
cd "$tempdir/branch"
pushd "$tempdir/branch" > /dev/null
echo "Checking out $docbranch branch"
$git checkout $docbranch
else
cd "$tempdir/branch"
pushd "$tempdir/branch" > /dev/null
echo "Creating $docbranch branch"
defaultcommitmessage=$initialdefaultcommitmessage
$git symbolic-ref HEAD "refs/heads/$docbranch"
Expand All @@ -110,16 +118,36 @@ mkdir "$docdirectory"
mv -v ../html/* "$docdirectory"
mv -v ../publish/* "$docdirectory"

# add directory and commit with default message, allowing editing
# add directory and commit with default message
$git add -f -v "$docdirectory"
$git commit -e -m "$defaultcommitmessage"
if $editcommit; then
$git commit -e -m "$defaultcommitmessage"
else
$git commit -m "$defaultcommitmessage"
fi

# push changes back to our repo
$git push origin $docbranch

# remove temporary directory
rm -rf "$tempdir"

popd > /dev/null

# if publishing is on, push the documentation pages, otherwise echo out the command that would push them
if $publish ; then
git push $githubrepo $docbranch:$docbranch
else
echo "To push the documentation changes, do:"
echo "git push $githubrepo $docbranch:$docbranch"
fi

# echo info on the location of the feed
echo "Feed URL is at http://$githubuser.github.com/$projectname/$docdirectory/docset.atom"
echo "To push the documentation changes, do:"
echo "git push $githubrepo $docbranch:$docbranch"
echo "Documentation changes may take a while to filter through..."

# open the top of the documentation pages in the browser
if $open ; then
open "http://$githubuser.github.com/$projectname/$docdirectory"
fi