|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# |
| 4 | +# Smart little documentation generator. |
| 5 | +# GPL/LGPL |
| 6 | +# (c) Del 2015 http://www.babel.com.au/ |
| 7 | +# |
| 8 | + |
| 9 | +APPNAME='Omnipay eWay Gateway Module' |
| 10 | +CMDFILE=apigen.cmd.$$ |
| 11 | +DESTDIR=./documents |
| 12 | + |
| 13 | +# |
| 14 | +# Find apigen, either in the path or as a local phar file |
| 15 | +# |
| 16 | +if [ -f apigen.phar ]; then |
| 17 | + APIGEN="php apigen.phar" |
| 18 | + |
| 19 | +else |
| 20 | + APIGEN=`which apigen` |
| 21 | + if [ ! -f "$APIGEN" ]; then |
| 22 | + |
| 23 | + # Search for phpdoc if apigen is not found. |
| 24 | + if [ -f phpDocumentor.phar ]; then |
| 25 | + PHPDOC="php phpDocumentor.phar" |
| 26 | + |
| 27 | + else |
| 28 | + PHPDOC=`which phpdoc` |
| 29 | + if [ ! -f "$PHPDOC" ]; then |
| 30 | + echo "Neither apigen nor phpdoc is installed in the path or locally, please install one of them" |
| 31 | + echo "see http://www.apigen.org/ or http://www.phpdoc.org/" |
| 32 | + exit 1 |
| 33 | + fi |
| 34 | + fi |
| 35 | + fi |
| 36 | +fi |
| 37 | + |
| 38 | +# |
| 39 | +# As of version 4 of apigen need to use the generate subcommand |
| 40 | +# |
| 41 | +if [ ! -z "$APIGEN" ]; then |
| 42 | + APIGEN="$APIGEN generate" |
| 43 | +fi |
| 44 | + |
| 45 | +# |
| 46 | +# Without any arguments this builds the entire system documentation, |
| 47 | +# making the cache file first if required. |
| 48 | +# |
| 49 | +if [ -z "$1" ]; then |
| 50 | + # |
| 51 | + # Check to see that the cache has been made. |
| 52 | + # |
| 53 | + if [ ! -f dirlist.cache ]; then |
| 54 | + echo "Making dirlist.cache file" |
| 55 | + $0 makecache |
| 56 | + fi |
| 57 | + |
| 58 | + # |
| 59 | + # Build the apigen/phpdoc command in a file. |
| 60 | + # |
| 61 | + if [ ! -z "$APIGEN" ]; then |
| 62 | + echo "$APIGEN --php --tree --title '$APPNAME API Documentation' --destination $DESTDIR/main \\" > $CMDFILE |
| 63 | + cat dirlist.cache | while read dir; do |
| 64 | + echo "--source $dir \\" >> $CMDFILE |
| 65 | + done |
| 66 | + echo "" >> $CMDFILE |
| 67 | + |
| 68 | + elif [ ! -z "$PHPDOC" ]; then |
| 69 | + echo "$PHPDOC --sourcecode --title '$APPNAME API Documentation' --target $DESTDIR/main --directory \\" > $CMDFILE |
| 70 | + cat dirlist.cache | while read dir; do |
| 71 | + echo "${dir},\\" >> $CMDFILE |
| 72 | + done |
| 73 | + echo "" >> $CMDFILE |
| 74 | + |
| 75 | + else |
| 76 | + "Neither apigen nor phpdoc are found, how did I get here?" |
| 77 | + exit 1 |
| 78 | + fi |
| 79 | + |
| 80 | + # |
| 81 | + # Run the apigen command |
| 82 | + # |
| 83 | + rm -rf $DESTDIR/main |
| 84 | + mkdir -p $DESTDIR/main |
| 85 | + . ./$CMDFILE |
| 86 | + |
| 87 | + /bin/rm -f ./$CMDFILE |
| 88 | + |
| 89 | +# |
| 90 | +# The "makecache" argument causes the script to just make the cache file |
| 91 | +# |
| 92 | +elif [ "$1" = "makecache" ]; then |
| 93 | + echo "Find application source directories" |
| 94 | + find src -name \*.php -print | \ |
| 95 | + ( |
| 96 | + while read file; do |
| 97 | + grep -q 'class' $file && dirname $file |
| 98 | + done |
| 99 | + ) | sort -u | \ |
| 100 | + grep -v -E 'config|docs|migrations|phpunit|test|Test|views|web' > dirlist.app |
| 101 | + |
| 102 | + echo "Find vendor source directories" |
| 103 | + find vendor -name \*.php -print | \ |
| 104 | + ( |
| 105 | + while read file; do |
| 106 | + grep -q 'class' $file && dirname $file |
| 107 | + done |
| 108 | + ) | sort -u | \ |
| 109 | + grep -v -E 'config|docs|migrations|phpunit|codesniffer|test|Test|views' > dirlist.vendor |
| 110 | + |
| 111 | + # |
| 112 | + # Filter out any vendor directories for which apigen fails |
| 113 | + # |
| 114 | + echo "Filter source directories" |
| 115 | + mkdir -p $DESTDIR/tmp |
| 116 | + cat dirlist.app dirlist.vendor | while read dir; do |
| 117 | + if [ ! -z "$APIGEN" ]; then |
| 118 | + $APIGEN --quiet --title "Test please ignore" \ |
| 119 | + --source $dir \ |
| 120 | + --destination $DESTDIR/tmp && ( |
| 121 | + echo "Including $dir" |
| 122 | + echo $dir >> dirlist.cache |
| 123 | + ) || ( |
| 124 | + echo "Excluding $dir" |
| 125 | + ) |
| 126 | + |
| 127 | + elif [ ! -z "$PHPDOC" ]; then |
| 128 | + $PHPDOC --quiet --title "Test please ignore" \ |
| 129 | + --directory $dir \ |
| 130 | + --target $DESTDIR/tmp && ( |
| 131 | + echo "Including $dir" |
| 132 | + echo $dir >> dirlist.cache |
| 133 | + ) || ( |
| 134 | + echo "Excluding $dir" |
| 135 | + ) |
| 136 | + |
| 137 | + fi |
| 138 | + done |
| 139 | + echo "Documentation cache dirlist.cache built OK" |
| 140 | + |
| 141 | + # |
| 142 | + # Clean up |
| 143 | + # |
| 144 | + /bin/rm -rf $DESTDIR/tmp |
| 145 | + |
| 146 | +fi |
0 commit comments