├── LICENSE ├── Makefile ├── README.md ├── bpkg.json └── nman.sh /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Joseph Werle 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | BIN ?= nman 3 | PREFIX ?= /usr/local 4 | 5 | install: 6 | cp nman.sh $(PREFIX)/bin/$(BIN) 7 | 8 | uninstall: 9 | rm -f $(PREFIX)/bin/$(BIN) 10 | 11 | check: 12 | @if ! type -f ronn > /dev/null 2>&1; then echo "Missing ronn(1)"; exit -1; fi 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | nman(1) 2 | ==== 3 | 4 | Read the node.js [core api](http://nodejs.org/api/) in man page format 5 | 6 | ## install 7 | 8 | [bpkg](https://github.com/bpkg/bpkg) 9 | 10 | ```sh 11 | $ bpkg install nman -g 12 | ``` 13 | 14 | *source:* 15 | 16 | ```sh 17 | $ git clone https://github.com/jwerle/nman.git 18 | $ cd ./nman 19 | $ make install 20 | ``` 21 | 22 | or 23 | 24 | ```sh 25 | (cd /tmp && git clone --depth 1 https://github.com/jwerle/nman.git && cd nman && sudo make install && cd -) 26 | ``` 27 | 28 | ## usage 29 | 30 | ```sh 31 | $ nman fs 32 | ``` 33 | 34 | ## license 35 | 36 | MIT 37 | -------------------------------------------------------------------------------- /bpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nman", 3 | "version": "0.0.2", 4 | "description": "Read the node.js core api in man page format", 5 | "scripts": [ "nman.sh" ], 6 | "install": "make install" 7 | } 8 | -------------------------------------------------------------------------------- /nman.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | VERSION="0.0.2" 4 | 5 | ## sets optional variable from environment 6 | opt () { eval "if [ -z "\${$1}" ]; then ${1}=${2}; fi"; } 7 | 8 | opt TMPDIR "/tmp/" 9 | opt CACHE_DIR="${TMPDIR}nman-cache" 10 | opt OUTPUT="ronn" 11 | opt API_URL "https://raw.githubusercontent.com/nodejs/node/main/doc/api" 12 | opt DOC_EXT "md" 13 | 14 | ## output usage 15 | usage () { 16 | { 17 | echo "usage: nman [-hV]" 18 | echo "" 19 | echo "examples:" 20 | echo " $ nman fs" 21 | echo " $ nman stream" 22 | echo " $ nman buffer" 23 | } >&2 24 | } 25 | 26 | ## output error 27 | error () { 28 | { 29 | printf "error: %s\n" "${@}" 30 | } >&2 31 | } 32 | 33 | ## main 34 | nman () { 35 | local mod="$1" 36 | local let is_cached=0 37 | local url="${API_URL}/${mod}.${DOC_EXT}" 38 | local mdfile="${CACHE_DIR}/${mod}.${DOC_EXT}" 39 | local manfile="${CACHE_DIR}/${mod}.man" 40 | local md="" 41 | local man="" 42 | 43 | ## ensure cache dir exists 44 | if ! test -d "${CACHE_DIR}"; then 45 | mkdir -p "${CACHE_DIR}" 46 | fi 47 | 48 | ## if it exists in cache dir then 49 | ## use it with output method 50 | if test -f "${mdfile}" && test -f "${manfile}"; then 51 | md="$(cat ${mdfile})" 52 | is_cached=1 53 | else 54 | ## fetch new copy 55 | md="$(curl -s -L "${url}")" 56 | fi 57 | 58 | ## fail on bad rc 59 | if [ "$?" -gt "0" ]; then 60 | return 1 61 | fi 62 | 63 | ## fail on empty buf 64 | if [ -z "${md}" ]; then 65 | return 1 66 | fi 67 | 68 | if [ "0" == "${is_cached}" ]; then 69 | ## store cache 70 | touch "${mdfile}" 71 | { 72 | echo "node - ${mod}" 73 | echo "====================" 74 | echo "" 75 | echo "${md}" 76 | } >> "${mdfile}" 77 | fi 78 | 79 | if [ "stdout" = "${OUTPUT_METHOD}" ]; then 80 | cat "${mdfile}" 81 | return 0 82 | fi 83 | 84 | if test -f "${manfile}"; then 85 | man "${manfile}" 86 | return $? 87 | fi 88 | 89 | ## determine output method 90 | case "${OUTPUT_METHOD}" in 91 | ronn) 92 | man="$(ronn -W -r --pipe ${mdfile} 2>/dev/null)" 93 | ;; 94 | 95 | curl) 96 | man="$(curl -s -# -F page=@${mdfile} http://mantastic.herokuapp.com)" 97 | ;; 98 | 99 | *) return 1 ;; 100 | esac 101 | 102 | rm -f "${manfile}" 103 | touch "${manfile}" 104 | echo "${man}" >> "${manfile}" 105 | man "${manfile}" 106 | } 107 | 108 | ## feature test 109 | features () { 110 | 111 | case "${OUTPUT}" in 112 | stdout) 113 | OUTPUT_METHOD="stdout" 114 | ;; 115 | 116 | curl) 117 | OUTPUT_METHOD="curl" 118 | ;; 119 | 120 | *) 121 | OUTPUT_METHOD="ronn" 122 | ;; 123 | esac 124 | 125 | if [ "stdout" != "${OUTPUT}" ]; then 126 | if ! type -f "${OUTPUT_METHOD}" > /dev/null 2>&1; then 127 | OUTPUT_METHOD="curl" 128 | if ! type -f curl > /dev/null 2>&1; then 129 | error "Unable to determine a suitable output method" 130 | exit -1 131 | fi 132 | fi 133 | fi 134 | } 135 | 136 | ## parse opts 137 | { 138 | while true; do 139 | arg="$1" 140 | if [ "" = "${arg}" ]; then 141 | usage 142 | exit 1 143 | elif [ "-" != "${arg:0:1}" ]; then 144 | break; 145 | fi 146 | 147 | case "${arg}" in 148 | -V|--version) 149 | echo "${VERSION}" 150 | exit 0 151 | ;; 152 | 153 | -h|--help) 154 | usage 155 | exit 0 156 | ;; 157 | 158 | *) 159 | error "Unknown option: \`${arg}'" 160 | usage 161 | exit 1 162 | ;; 163 | esac 164 | shift 165 | done 166 | } 167 | 168 | ## detect feature output 169 | features 170 | 171 | nman "$@" 172 | exit $? 173 | --------------------------------------------------------------------------------