update-docs
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

update-docs

update-docs allows you to use test cases to populate and update your documentation examples.

With update-docs, you can ensure that:

  • Your code continues to support your documentation examples.
  • The output of your documentation examples remains up-to-date.

Install

npm install -D update-docs

How to Use

1. Label code blocks in your documentation

<!---My Code⠀Block-->

```typescript

```

(Note the three -s)

2. Set up the UpdateDocs class

import { UpdateDocs } from 'update-docs'

const docs = new UpdateDocs({
    documentationGlobs: ['**/*.md'],
    testGlobs: ['test/**.test.ts'],
    modifyIndent: indent => indent.replace(/\t/g, '    ')
})

beforeAll(() => {
    docs.updateExamples()
})

3. Write a test case

test('addition', () => {
    // start docs My Code Block
    const sum = 2 + 2
    sum // {{sum}}
    // end docs My Code Block
    expect(sum).toBe(4)
    docs.replaceToken('My Code Block', '{{' + 'sum' + '}}', sum)
})

4. Save changes

afterAll(() => {
    docs.write()
})

My Code Block

const sum = 2 + 2
sum // 4

That's it!

Now, when your run your test, UpdateDocs will update the code samples in your documentation, run the tests, and replace any tokens with their results.

See the UpdateDocs class for more API documentation.

This README is generated using update-docs! See README.test.ts for that implementation.

(P.S. You can repeat the same code block name in multiple files to keep them in sync.)

Readme

Keywords

none

Package Sidebar

Install

npm i update-docs

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

15.4 kB

Total Files

5

Last publish

Collaborators

  • lukebrody