Home

Awesome

docts

build status dependency status npm version

This is a command-line tool to generate API documentation for TypeScript projects based on information about types and exported declarations extracted using readts. Run docts inside your package and it parses the .d.ts files referenced from the typings key of your package.json. Then it replaces any section titled API in your README.md file with new automatically generated content. For an example of its output, see the API section below.

If your package is a Git working tree and the repository field in package.json points to a Github URL, links to relevant parts of the code published on Github are added next to functions, classes and methods. Each link looks like <> and includes the hash of the latest commit which changed the relevant file. If that file is dirty in the working tree, the link points to whatever is on the current branch instead. This minimizes changes to the links while trying to keep them pointed to the correct location in latest code.

Any additional TypeScript configuration should be defined in tsconfig.json in the root if your package.

Usage

Start by making a backup of your README.md.

Then install:

npm install --save-dev docts

Make sure your package.json has a typings section and add in the scripts section:

  "scripts": {
    "docts": "docts"
  }

Finally run:

npm run docts

API

Docs generated using docts

<a name="api-DocBuilder"></a>

Class DocBuilder

<em>TypeScript project Markdown documentation builder.</em>
Source code: <>

Methods:

new( ) <sup><code>DocBuilder</code></sup> <>
 ▪ basePath <sup><code>string</code></sup>
.build( ) <sup><code>Promise<any></code></sup> <>
<em>Generate API documentation for the package.</em>
<em>Returns promise resolving to an array of text split by line breaks.</em>

<a name="api-Markdown"></a>

Class Markdown

<em>Represents a Markdown file.</em>
Source code: <>

Methods:

new( ) <sup><code>Markdown</code></sup> <>
 ▪ markdownPath <sup><code>string</code></sup>
.readSections( ) <sup><code>Section[]</code></sup> <>
<em>Read the file and split each heading into a separate section.</em>
.writeSections( ) <sup><code>Promise<void></code></sup> <>
<em>Replace file contents with a new list of sections.</em>
 ▪ sectionList <sup><code>Section[]</code></sup>

Properties:

.path <sup><code>string</code></sup>

<a name="api-Section"></a>

Class Section

<em>Represents a section in a Markdown file.</em>
Source code: <>

Properties:

.header <sup><code>string[]</code></sup>
<em>Heading and its markup split by newlines.</em>
<em>Heading is a line beginning with # or followed by another line full of - or =.</em>
.content <sup><code>string[]</code></sup>
<em>Section content split by newlines.</em>
.name <sup><code>string</code></sup>
<em>Heading with markup stripped.</em>

<a name="api-patchReadme"></a>

Function patchReadme

<em>Patch section titled API of README.md file in given directory.</em>
Source code: <>

patchReadme( ) <sup><code>void</code></sup> <>
 ▪ basePath <sup><code>string</code></sup>

License

The MIT License

Copyright (c) 2016 BusFaster Ltd