Skip to content

@stephansama packages / @stephansama/auto-readme

Auto Readme 🪄

Source codeDocumentationNPM Versionnpm downloads

Generate lists and tables for your README automagically based on your repository

Table of contents
Open Table of contents

Installation

sh
pnpm install @stephansama/auto-readme

Usage

In order to run the script you need to do two things

  1. Create either a heading or a comment to enable the corresponding feature
  2. Run the following command:
sh
pnpx @stephansama/auto-readme [options]

To turn on table of content enable the setting enableToc and add the following header

md
## Table of contents

To turn on the usage generator enable the setting enableUsage and add the following header

md
## Usage

To use the zod generator add the following comments

md
<!-- ZOD path="./path/to/zod.js" start -->
<!-- ZOD end -->

There are more Actions that you can use in conjunction with different languages and formats like so:

md
<!-- JS-WORKSPACE-TABLE start -->
<!-- JS-WORKSPACE-TABLE end -->

You can run auto-readme as a pre-commit git hook to automatically keep your READMEs up to date. For example, you can use husky to add the following to your .husky/pre-commit file:

sh
auto-readme -g

This will run auto-readme only when affected README files are changed

CLI Options

OptionAliasDescriptionTypeDefault
--changes-gCheck only changed git filesbooleanfalse
--check-kDo not write to files. Only check for changesbooleanfalse
--config-cPath to config filestring
--verbose-vwhether or not to display verbose loggingbooleanfalse

Most of the options in the schema below can also be used as command-line flags.

Configuration

auto-readme can be configured using a variety of files, such as package.json with an auto-readme property, or a standalone .autoreadmerc file. For more information on configuration files, see cosmiconfig.

Configuration File

You can configure auto-readme by creating a configuration file (or object) in the root of your project. The following file formats are supported:

  • package.json
  • .autoreadmerc.cjs
  • .autoreadmerc.js
  • .autoreadmerc.json
  • .autoreadmerc.mjs
  • .autoreadmerc.toml
  • .autoreadmerc.ts
  • .autoreadmerc.yaml
  • .autoreadmerc.yml
  • .autoreadmerc
  • .config/.autoreadmerc.json
  • .config/.autoreadmerc.toml
  • .config/.autoreadmerc.yaml
  • .config/.autoreadmerc.yml
  • .config/.autoreadmerc
  • .config/autoreadmerc.cjs
  • .config/autoreadmerc.js
  • .config/autoreadmerc.json
  • .config/autoreadmerc.mjs
  • .config/autoreadmerc.toml
  • .config/autoreadmerc.ts
  • .config/autoreadmerc.yaml
  • .config/autoreadmerc.yml
  • .config/autoreadmerc
  • autoreadme.config.cjs
  • autoreadme.config.js
  • autoreadme.config.mjs
  • autoreadme.config.ts

JSON Example

json
{
  "$schema": "./node_modules/@stephansama/auto-readme/config/schema.json",
  "disableEmojis": true
}

YAML Example

yaml
# yaml-language-server: $schema=./node_modules/@stephansama/auto-readme/config/schema.yaml
disableEmojis: true

JavaScript Example

javascript
/** @type {import('@stephansama/auto-readme').Config} */
export default {
  disableEmojis: true,
};

TypeScript Example

typescript
import type { Config } from "@stephansama/auto-readme";

export default {
  disableEmojis: true,
} satisfies Config;

Schema

Zod Schema

Actions

Comment action options

Enum, one of the following possible values:

  • 'ACTION'
  • 'PKG'
  • 'USAGE'
  • 'WORKSPACE'
  • 'ZOD'

Config

Object containing the following properties:

PropertyDescriptionTypeDefault
affectedRegexesArray<string>[]
collapseHeadingsArray<string>[]
defaultLanguageDefault language to infer projects fromLanguage
disableEmojisWhether or not to use emojis in markdown table headingsbooleanfalse
disableMarkdownHeadingsWhether or not to display markdown headingsbooleanfalse
enableTocgenerate table of contents for readmesbooleanfalse
enableUsageWhether or not to enable usage pluginbooleanfalse
headingsList of headings for different table outputsObject with dynamic keys of type Actions and values of type Array of Headings items (optional){"ACTION":["name","required","default","description"],"PKG":["name","version","devDependency"],"WORKSPACE":["name","version","downloads","description"],"ZOD":[]}
onlyReadmesWhether or not to only traverse readmesbooleantrue
onlyShowPublicPackagesOnly show public packages in workspacesbooleanfalse
removeScopeRemove common workspace scopestring''
templatesHandlebars templates used to fuel list and table generationObject with properties:
  • downloadImage: string
  • emojis: Object with dynamic keys of type Headings and values of type string - Table heading emojis used when enabled
  • registryUrl: string
  • versionImage: string
{"downloadImage":"https://img.shields.io/npm/dw/?labelColor=211F1F","emojis":{"default":"⚙️","description":"📝","devDependency":"💻","downloads":"📥","name":"🏷️","private":"🔒","required":"","version":""},"registryUrl":"https://www.npmjs.com/package/","versionImage":"https://img.shields.io/npm/v/?logo=npm&logoColor=red&color=211F1F&labelColor=211F1F"}
tocHeadingMarkdown heading used to generate table of contentsstring'Table of contents'
usageFileWorkspace level usage filestring''
usageHeadingMarkdown heading used to generate usage examplestring'Usage'
verbosewhether or not to display verbose loggingbooleanfalse

All properties are optional. (optional)

Formats

Enum, one of the following possible values:

  • 'LIST'
  • 'TABLE' (optional)

Default value: 'TABLE'

Headings

Table heading options

Enum, one of the following possible values:

  • 'default'
  • 'description'
  • 'devDependency'
  • 'downloads'
  • 'name'
  • 'private'
  • 'required'
  • 'version'

Language

Enum, one of the following possible values:

  • 'JS'
  • 'RS' (optional)

Default value: 'JS'

TableHeadings

Table heading action configuration

Object record with dynamic keys:

  • keys of type Actions
  • values of type Array of Headings items (optional) (optional)

Default value: {"ACTION":["name","required","default","description"],"PKG":["name","version","devDependency"],"WORKSPACE":["name","version","downloads","description"],"ZOD":[]}

Templates

Object containing the following properties:

PropertyDescriptionTypeDefault
downloadImagestring'https://img.shields.io/npm/dw/?labelColor=211F1F'
emojisTable heading emojis used when enabledObject with dynamic keys of type Headings and values of type string{"default":"⚙️","description":"📝","devDependency":"💻","downloads":"📥","name":"🏷️","private":"🔒","required":"","version":""}
registryUrlstring'https://www.npmjs.com/package/'
versionImagestring'https://img.shields.io/npm/v/?logo=npm&logoColor=red&color=211F1F&labelColor=211F1F'

All properties are optional.

Modules

ModuleDescription

args

comment

config

data

index

log

pipeline

plugin

schema

utils

Released under MIT license