https://github.com/boneskull/whatsnu
https://github.com/boneskull/whatsnu
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/boneskull/whatsnu
- Owner: boneskull
- License: apache-2.0
- Created: 2020-10-22T18:49:54.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T21:53:12.000Z (over 3 years ago)
- Last Synced: 2024-10-29T22:36:15.629Z (over 1 year ago)
- Language: JavaScript
- Size: 989 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# whatsnu
> Provide a "What's New" subcommand to your users -- a library for CLI apps
## Install
```shell
$ npm install whatsnu
```
## Example
```js
#!/usr/bin/env node
'use strict';
require('yargs')
.scriptName('example-cli')
.command({
command: 'whats-new',
description: 'Print recent changes to terminal',
handler: async () => {
const whatsnu = require('whatsnu');
const {error, changes} = await whatsnu(__dirname, {
header: "# What's new in example-cli"
});
if (error) {
console.error(error);
process.exitCode = 1;
} else {
console.log(changes);
}
},
})
.help().argv;
```
## API
### `whatsnu(pkg [,opts])`
Returns markdown from your `CHANGELOG` file, rendered appropriately for a terminal.
`{string} pkg`: Path to your package's `package.json`, or a close directory (parent dirs will be searched). `__dirname` usually works.
Options (all are _optional_):
- `{string} changelog`: Path to `CHANGELOG`; defaults to `CHANGELOG.md` in same dir as the found `package.json`
- `{Object} pattern`: Key/value pairs to match a [`marked`](https://npm.im/marked) `Token` (as returned by its lexer) for `version`. Default is `{type: 'header', depth: 2}` which looks for your `package.json`'s `version` in second-level headings. If your version number is found in top-level headings, use `{type: 'header', depth: 1}`.
- `{string} versionProp`: `Token` property in which to find the version; defaults to `text` and probably needn't be changed
- `{TerminalRendererOptions} rendererOpts`: Options for [`marked-terminal`](https://npm.im/marked-terminal)
- `{string} header`: Markdown header to prepend to the output
- `{string} footer`: Markdown footer to append to the output
Returns:
- `{Promise<{changes, error>}`: If `error` is present, `changes` won't be, and vice-versa.
- `{string} changes`: The notes for the version, rendered in terminal-appropriate Markdown. You'll probably `console.log()` this.
- `{Error} error`: If an exception was thrown, this is it. Do with it what you will.
## License
Copyright © 2020 Christopher Hiller. Licensed Apache-2.0