Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 154 lines (129 sloc) 5.126 kb
a4d80b40 »
2012-08-02
1 #!/bin/bash
2
c513c300 »
2012-08-12
3 # From an original script by Daniel Tull
4 # Somewhat mangled by Sam Deane
a4d80b40 »
2012-08-02
5
438223a6 »
2012-08-03
6 # Run this script from the root of your project.
7 # It makes a temporary directory and generates appledoc documentation for your
60f057bf »
2012-09-03 added options to control publishing, editing the commit
8 # project in that directory.
438223a6 »
2012-08-03
9 # It then makes a local clone of your documentation branch (called gh-pages, by default)
10 # copies the generated appledoc html into a folder in the branch (called Documentation by default)
11 # commits the new documentation and pushes it back to the project repo.
12 #
13 # Note that it doesn't push from the project repo, so the new documentation doesn't leave
60809db4 »
2012-08-12
14 # your machine - but it echos the git command that you'll need to execute to do the push.
438223a6 »
2012-08-03
15
a4d80b40 »
2012-08-02
16 # This script assumes:
438223a6 »
2012-08-03
17 # - the name of the root folder is the name of the project
60809db4 »
2012-08-12
18 # - your appledoc templates are in ~/.appledoc (can be a symlink)
438223a6 »
2012-08-03
19 # - you have a GlobalSettings.plist file in your appledoc templates folder
60f057bf »
2012-09-03 added options to control publishing, editing the commit
20 # - you've set values in GlobalSettings.plist for --project-company, --company-id
a4d80b40 »
2012-08-02
21
60809db4 »
2012-08-12
22 # The script looks at the remotes configured in the repo to try to work out what your github
23 # user name is, so that it can generate the correct urls for a docset feed.
24 # It looks for the first remote with the pattern: git@github.com:yourname/
25
a937329e »
2012-08-07
26 git=`xcrun --find git`
1f5ebb90 »
2012-08-07
27 docsetutil=`xcrun --find docsetutil`
a937329e »
2012-08-07
28 originaldirectory=`git rev-parse --show-toplevel`
29 codebranch=`$git rev-parse --abbrev-ref HEAD`
a4d80b40 »
2012-08-02
30 docbranch="gh-pages"
c513c300 »
2012-08-12
31 projectname=`basename "$PWD"`
60f057bf »
2012-09-03 added options to control publishing, editing the commit
32 docdirectory="Documentation"
9bfc022b »
2012-08-07
33 initialdefaultcommitmessage="Initial documentation"
34 updatedefaultcommitmessage="Update documentation"
35 defaultcommitmessage=$updatedefaultcommitmessage
a261f38c »
2012-08-03
36 tempdir=/tmp/gendoc
60f057bf »
2012-09-03 added options to control publishing, editing the commit
37 publish=true
38 open=false
39 editcommit=false
a4d80b40 »
2012-08-02
40
60809db4 »
2012-08-12
41 # find real templates location (.appledoc might be a link)
42 pushd $HOME > /dev/null
43 link=`readlink ".appledoc"`
44 if [[ $link != "" ]];
45 then
459f9ea8 »
2012-09-03 fixed the indenting that xcode helpfully broke
46 cd $link
60809db4 »
2012-08-12
47 else
459f9ea8 »
2012-09-03 fixed the indenting that xcode helpfully broke
48 cd ".appledoc"
60809db4 »
2012-08-12
49 fi
50 templates=`pwd`
51 popd > /dev/null
52
53 # try to fish out the github user from the git remotes - we use the first one that seems to be a github repo that we can write to
54 # (this logic may be flawed!)
55 remotes=`git remote -v`
56 pattern="([a-z]*).git@github.com:([a-zA-Z0-9]+)\/"
57 [[ $remotes =~ $pattern ]]
58 githubrepo=${BASH_REMATCH[1]}
59 githubuser=${BASH_REMATCH[2]}
60
a4d80b40 »
2012-08-02
61 # if we're on the documentation branch, something's gone wrong
62 if [[ "$codebranch" == "gh-pages" ]]
63 then
459f9ea8 »
2012-09-03 fixed the indenting that xcode helpfully broke
64 echo "You seem to be on the gh-pages branch. Checkout a code branch instead."
60f057bf »
2012-09-03 added options to control publishing, editing the commit
65 exit 1
a4d80b40 »
2012-08-02
66 fi
67
a261f38c »
2012-08-03
68 echo "Generating documentation for $projectname"
a4d80b40 »
2012-08-02
69
a261f38c »
2012-08-03
70 # make a clean temp directory
71 rm -rf "$tempdir"
72 mkdir -p -v "$tempdir"
a4d80b40 »
2012-08-02
73
60f057bf »
2012-09-03 added options to control publishing, editing the commit
74 # include settings file if it's present
75 if [ -e ./.appledoc.plist ]; then
459f9ea8 »
2012-09-03 fixed the indenting that xcode helpfully broke
76 echo "Found appledoc settings file"
77 settings=./.appledoc.plist
60f057bf »
2012-09-03 added options to control publishing, editing the commit
78 fi
a4d80b40 »
2012-08-02
79
15ffde03 »
2012-08-07
80 # generate docset and html, install docset in xcode, create atom feed and downloadable package
1f5ebb90 »
2012-08-07
81 appledoc \
459f9ea8 »
2012-09-03 fixed the indenting that xcode helpfully broke
82 --templates "$templates" \
83 --keep-intermediate-files \
84 --create-html \
85 --create-docset \
86 --install-docset \
87 --publish-docset \
88 --docsetutil-path "$docsetutil" \
89 --docset-atom-filename "docset.atom" \
90 --docset-feed-url "http://$githubuser.github.com/$projectname/$docdirectory/%DOCSETATOMFILENAME" \
91 --docset-package-url "http://$githubuser.github.com/$projectname/$docdirectory/%DOCSETPACKAGEFILENAME" \
92 --docset-fallback-url "http://$githubuser.github.com/projectname/$docdirectory/" \
93 --project-name $projectname \
94 -o "$tempdir" "$@" $settings ./
a4d80b40 »
2012-08-02
95
a937329e »
2012-08-07
96 # clone doc branch of current repo into temporary location
60809db4 »
2012-08-12
97 $git clone "$originaldirectory" "$tempdir/branch"
a937329e »
2012-08-07
98
99 if $git show-ref --tags --quiet --verify -- "refs/heads/$docbranch"
a4d80b40 »
2012-08-02
100 then
459f9ea8 »
2012-09-03 fixed the indenting that xcode helpfully broke
101 pushd "$tempdir/branch" > /dev/null
102 echo "Checking out $docbranch branch"
103 $git checkout $docbranch
9bfc022b »
2012-08-07
104 else
459f9ea8 »
2012-09-03 fixed the indenting that xcode helpfully broke
105 pushd "$tempdir/branch" > /dev/null
106 echo "Creating $docbranch branch"
107 defaultcommitmessage=$initialdefaultcommitmessage
108 $git symbolic-ref HEAD "refs/heads/$docbranch"
109 rm .git/index
110 $git clean -fdx
a4d80b40 »
2012-08-02
111 fi
112
113 # make sure stale docs are removed - re-adding will cause an update
9bfc022b »
2012-08-07
114 $git rm -rf "$docdirectory" --quiet
a4d80b40 »
2012-08-02
115
116 # move the generated docs to docdirectory and cleanup
15ffde03 »
2012-08-07
117 mkdir "$docdirectory"
118 mv -v ../html/* "$docdirectory"
119 mv -v ../publish/* "$docdirectory"
a4d80b40 »
2012-08-02
120
60f057bf »
2012-09-03 added options to control publishing, editing the commit
121 # add directory and commit with default message
a937329e »
2012-08-07
122 $git add -f -v "$docdirectory"
60f057bf »
2012-09-03 added options to control publishing, editing the commit
123 if $editcommit; then
459f9ea8 »
2012-09-03 fixed the indenting that xcode helpfully broke
124 $git commit -e -m "$defaultcommitmessage"
60f057bf »
2012-09-03 added options to control publishing, editing the commit
125 else
459f9ea8 »
2012-09-03 fixed the indenting that xcode helpfully broke
126 $git commit -m "$defaultcommitmessage"
60f057bf »
2012-09-03 added options to control publishing, editing the commit
127 fi
a4d80b40 »
2012-08-02
128
a261f38c »
2012-08-03
129 # push changes back to our repo
a937329e »
2012-08-07
130 $git push origin $docbranch
a261f38c »
2012-08-03
131
132 # remove temporary directory
133 rm -rf "$tempdir"
15ffde03 »
2012-08-07
134
60f057bf »
2012-09-03 added options to control publishing, editing the commit
135 popd > /dev/null
136
137 # if publishing is on, push the documentation pages, otherwise echo out the command that would push them
138 if $publish ; then
459f9ea8 »
2012-09-03 fixed the indenting that xcode helpfully broke
139 git push $githubrepo $docbranch:$docbranch
60f057bf »
2012-09-03 added options to control publishing, editing the commit
140 else
459f9ea8 »
2012-09-03 fixed the indenting that xcode helpfully broke
141 echo "To push the documentation changes, do:"
142 echo "git push $githubrepo $docbranch:$docbranch"
60f057bf »
2012-09-03 added options to control publishing, editing the commit
143 fi
144
145 # echo info on the location of the feed
146 echo "Feed URL is at http://$githubuser.github.com/$projectname/$docdirectory/docset.atom"
147 echo "Documentation changes may take a while to filter through..."
148
149 # open the top of the documentation pages in the browser
150 if $open ; then
459f9ea8 »
2012-09-03 fixed the indenting that xcode helpfully broke
151 open "http://$githubuser.github.com/$projectname/$docdirectory"
60f057bf »
2012-09-03 added options to control publishing, editing the commit
152 fi
153
Something went wrong with that request. Please try again.