├── .gitignore ├── common-readme.png ├── package.json ├── template.md ├── api_formatting.md ├── cli.js ├── common-readme.svg └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /common-readme.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hackergrrl/common-readme/HEAD/common-readme.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "common-readme", 3 | "description": "Generates a readme for your node modules.", 4 | "version": "1.1.0", 5 | "repository": { 6 | "url": "git://github.com/noffle/common-readme.git" 7 | }, 8 | "bin": { 9 | "common-readme": "cli.js" 10 | }, 11 | "dependencies": { 12 | "camelcase": "^5.0.0", 13 | "minimist": "^1.2.0" 14 | }, 15 | "license": "ISC" 16 | } 17 | -------------------------------------------------------------------------------- /template.md: -------------------------------------------------------------------------------- 1 | # $$REPO 2 | 3 | > $$1LINER 4 | 5 | background details relevant to understanding what this module does 6 | 7 | ## Usage 8 | 9 | ```javascript 10 | $$EXAMPLE 11 | ``` 12 | 13 | ## API 14 | 15 | ```js 16 | const $$rePo = require('$$REPO') 17 | ``` 18 | 19 | See [api_formatting.md](api_formatting.md) for tips. 20 | 21 | ## Installation 22 | 23 | With [npm](https://npmjs.org/): 24 | 25 | ```shell 26 | npm install $$REPO 27 | ``` 28 | 29 | With [yarn](https://yarnpkg.com/en/): 30 | 31 | ```shell 32 | yarn add $$REPO 33 | ``` 34 | 35 | ## Acknowledgments 36 | 37 | $$REPO was inspired by... 38 | 39 | ## See Also 40 | 41 | - [`noffle/common-readme`](https://github.com/noffle/common-readme) 42 | - ... 43 | 44 | ## License 45 | 46 | $$ZEE_LICENSE 47 | -------------------------------------------------------------------------------- /api_formatting.md: -------------------------------------------------------------------------------- 1 | # api formatting 2 | 3 | there's no one style for expressing a node api, but here are some common 4 | patterns with explanations: 5 | 6 | ## var r = repo(name, opts={}) 7 | 8 | Produces a new REPO with name `name`. Valid `opts` keys include 9 | 10 | - `db` (required) - uses the levelup instance `db` 11 | - `count` (optional) - does the thing `count` times 12 | 13 | > Shows how to create an instance of an object. `opts` is indicated to be the 14 | > empty object by default, and its required and optional parameters are 15 | > detailed. 16 | 17 | ## r.work(hard, cb(err, res)) 18 | 19 | Puts `r` to work. If `hard` is `true`, it'll even work pretty hard at it. `cb` 20 | will be called with the result of the work. 21 | 22 | > A method on the object. More importantly the indicator that it accepts a 23 | > callback function (`cb` or `callback` are both popular names). The callback's 24 | > parameters are named in `work`'s signature. 25 | 26 | ## r.pipe(stream), stream.pipe(r) 27 | 28 | `r` implements a readable stream or writeable stream, respectively. 29 | 30 | > `r` inherits `Readable` or `Writeable`, or both. 31 | 32 | ## r.on('foo', cb(bar)) 33 | 34 | `r` can raise an event named `'foo'` with the argument `bar`. 35 | 36 | > `r` is an EventEmitter, and is known to emit an event with the given name. The 37 | > callback that is ultimately called has the expected parameter `bar`. 38 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var fs = require('fs') 4 | var path = require('path') 5 | var camel = require('camelcase') 6 | var args = require('minimist')(process.argv) 7 | 8 | if (args.h || args.help) { 9 | usage() 10 | console.error() 11 | console.error('Generate a readme for your node module.') 12 | process.exit(1) 13 | } 14 | 15 | function usage () { 16 | console.error() 17 | console.log('USAGE: common-readme [-r|--repo REPO-NAME] [-l|--license LICENSE]') 18 | } 19 | 20 | var checkPkg = fs.existsSync(path.join(process.cwd(), 'package.json')) || args.l || args.license || args.r || args.repo || null 21 | 22 | if (!checkPkg) { 23 | console.error('no package.json found and no license and repo name set!') 24 | usage() 25 | process.exit(1) 26 | } 27 | 28 | var pkg = require(path.join(process.cwd(), 'package.json')) 29 | 30 | // one liner 31 | var oneliner = pkg.description || 'one-liner description of the module' 32 | 33 | // license 34 | var license = args.l || args.license || pkg.license || null 35 | if (!license) { 36 | console.error('no license set or found in package.json!') 37 | usage() 38 | process.exit(1) 39 | } 40 | 41 | // repo name 42 | var repo = args.r || args.repo || pkg.name || null 43 | if (!repo) { 44 | console.error('no repo name set or found in package.json!') 45 | usage() 46 | process.exit(1) 47 | } 48 | var repoCamel = camel(repo) 49 | 50 | // example.js 51 | var example = getExampleJs() 52 | function getExampleJs () { 53 | try { 54 | return fs.readFileSync(path.join(__dirname, 'example.js')) 55 | } catch (e) { 56 | return "var $$$rePo = require('$$$REPO')\n\nconsole.log('hello world') // => hello world" 57 | } 58 | } 59 | 60 | // read the template and regex match templated vars 61 | fs.readFileSync(path.join(__dirname, 'template.md')).toString().split('\n') 62 | .forEach(function (line) { 63 | console.log(processLine(line)) 64 | }) 65 | 66 | function processLine (line) { 67 | line = line.replace(/\$\$EXAMPLE/, example) 68 | line = line.replace(/\$\$REPO/, repo) 69 | line = line.replace(/\$\$rePo/, repoCamel) 70 | line = line.replace(/\$\$1LINER/, oneliner) 71 | line = line.replace(/\$\$ZEE_LICENSE/, license) 72 | line = line.replace(/\$\$r/, repo.charAt(0).toLowerCase()) 73 | return line 74 | } 75 | -------------------------------------------------------------------------------- /common-readme.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 93 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
3 |