1 | # Updating readme
|
2 |
|
3 | To update the README automatically, you can use a script. I prefer using GNU Make.
|
4 |
|
5 | ##### Makefile
|
6 |
|
7 | ```sh
|
8 | # Use mdx to update readme.md
|
9 | update: README.md
|
10 | README.md: lib/index.js lib/tableize.js # change this
|
11 | @( sed '/<!--api-->/q' $@; \
|
12 | echo; \
|
13 | ./node_modules/.bin/mdx $^ --format markdown; \
|
14 | sed -n '/<!--api:end-->/,$$p' $@ ) > $@_
|
15 | @mv $@_ $@
|
16 | ```
|
17 |
|
18 | You can then write your readme with `<!--api-->` and `<!--api:end-->` tags that will automatically be updated.
|
19 |
|
20 | ```md
|
21 | # package
|
22 | This is my readme.
|
23 |
|
24 | ## API
|
25 |
|
26 | <!--api-->
|
27 |
|
28 | ...everything here will be programatically updated
|
29 |
|
30 | <!--api:end-->
|
31 | ```
|
32 |
|
33 | To run the update, use `make update`. This will be a noop if the input files have not been updated.
|
34 |
|
35 | ```sh
|
36 | make update
|
37 | ```
|
38 |
|
39 | You can put this in your package's prepublish script.
|
40 |
|
41 | ##### package.json
|
42 |
|
43 | ```json
|
44 | {
|
45 | "scripts": {
|
46 | "prepublish": "make update"
|
47 | }
|
48 | }
|
49 | ```
|