npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

docroutes

v0.0.5

Published

A small tool to automatically extract documentation from typescript projects

Downloads

2

Readme

docroutes

This tool tries to solve the problem of keeping the documentation of your API in sync with the API. Instead of having a separate documentation you need to update every time you need to change something in your API, you document the routes in your codebase (you have documentation in your codebase, right?). You can then run the docroutes tool on your code base and generate one or more Markdown files containing not only your comments but also the types and interfaces your datatypes use.

npm version

Usage

docroutes [FLAGS] [FILES | DIRECTORIES]

Options:

--help:                     Show this help
--outdir [DIR]:             Set the output directory
--output [FILE]:            Set a single output file (all output is concatenated)
--config [FILE | DIR]:      Specify the path to tsconfig.json
--checkUnchanged            Check whether any file changes were made and return failure if so.
                            You can use this option to ensure files are up to date (e.g., in CI)

Any additional files or directories specified will be used as inputs to the typescript compiler.

Example

Defining routes happens by declaring types with a special structure. Additionally, the routes are made known to the tool by a special comment on the type or interface declaration:

#ExportRoute("/prefix/of/your/route")

The special marker needs to be the last part of the documentation of the route. An example of a full route declaration looks like this:

/**
 * Documentation for your route.
 *
 * #ExportRoute("/prefix/of/your/route")
 */
interface YourRoute {
    /**
     * This is your route.
     */
    "/your/:route": {
        /**
         * And this is the method of your route.
         */
        "POST": {
            authorization: string;
            body: { someThing: string };
            name: "Your Route";
            param: {
                /**
                 * Some parameter of your route.
                 */
                route: string;
            };
            query: {
                /**
                 * And some query parameter.
                 */
                someQueryParam?: boolean;
            }
            response: {
                /**
                 * This route might return status 201 with a number as response.
                 */
                201: number;
                /**
                 * Or it returns 202 without any body / an empty body.
                 */
                202: undefined;
            }
        };
    };
}

There is another example in src/example.ts. An example for the output can be found in example.md, which is generated from src/example.ts.

Assume our current directory points to your custom typescript project.

We now run:

docroutes --config . --outdir docs --output fulldoc.md --checkUnchanged
  • the tool will find all *.ts(x) files in your project
  • load it into the typescript compiler using your tsconfig.json file
  • extract all documented routes
  • for each route YourRoute, generate a file YourRoute.md in docs
  • also generate a single file containing all routes called fulldoc.md
  • return status 0 (success) if all files were already up to date
  • or return status 2 if any file was changed by running the tool

TODO

  • Extracting the data from the typescript AST is still quite basic. There is a good chance that something you write will not yet map cleanly to the internal representation
  • Generating Markdown is quite ad-hoc
  • Using the information we have, it would be nice to generate classes consuming or defining an API