Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

thought

nknapp144MIT5.0.0

A customizable documentation generator for github projects

readme

thought

NPM version Github Actions Status Greenkeeper badge

A customizable documentation generator for github projects

Every npm-package should have a README-file that contains a short description of what it is and what it does, an explanation of how to install it, one or more usage examples and an API-reference for all functions, parameters and options.

Thought helps you create such a README without a lot of hassle.

Easy startup: Thought uses handlebars with a default set of templates, partials and helpers to create a README.md- and a CONTRIBUTING.md-file. The input of the template is mainly the package.json-file of your project. Just run thought run -a in your project folder.

Examples that actually work: The file examples/example.js is included into the README by default. You can use require('../') to reference your package and thus build examples that are executable and testable. When you run thought run -a, the ../ will be replaced by the name of your package. The example will be run and the output will be included as well.

Fully customizable: You can change every template, partials and helper if you need to. And since you are writing Handlebars-templates, you can use helpers like {{npm 'lodash}} to create a link to a package's npm-page and {{dirTree '.thought' 'snippets/**'}} to generate directory-trees.

Plugins: You can write plugins that bundle your customizations. You can write a thought-plugin-my-name-base that contains all the customizations that you need in your module. Or you can bundle certain functionalities, like the thought-plugin-jsdoc and share them on npm.

Basic Usage

Starting with version 2.0, Thought will support NodeJS LTS and active versions. Dropping support for pre-LTS versions will not be considered a breaking change.

The most basic way to use Thought is to go into your directory of your package.json and type

npm -g install thought
thought run -a

Warning: Thought does not work correctly in Windows machines, because of the separator "\" instead of "/" If you want to fix that, please contact me.

Thought will then create the files README.md and CONTRIBUTING.md with reasonable default texts for Open-Source projects in JavaScript that are hosted on http://npmjs.com.

Examples

Thought can be used just as-is or in a more sophisticated fashion. The more work you put in, the better the documentation that comes out. The following example show the different levels of details:

  • The first example shows the generated documentation for a very simple, newly generated npm-package.
  • The second example-project demonstrates the following features:
    • an example program in the README
    • a link to a LICENSE-file
    • a JSDoc-Reference of the main file
    • badges for npm, travis, coveralls and greenkeeper
  • The third example-project shows how to
    • override contents with custom content (using custom partials and custom templates)
    • create new files by adding templates
    • add custom helpers that can be called from within templates and partials
    • add a custom preprocessor to modify the input data (i.e. the package.json and the configuration)
  • The fourth example-project demonstrates how to bundle customizations into a plugin that can be reused and published on npm.
  • The (probably) largest example is Thought itself. All the documentation is generated by Thought. In fact, some of the features like the ignore-option of the {{dirTree}}-helper were added in order to generate the documentation properly. Have a look at the .thought-directory and learn what is possible.

CLI options

Calling thought --help will print a command-line reference:

Usage: thought [options] [command]

Options:
  -V, --version              output the version number
  -d, --debug                higher stack-trace-limit, long stack-traces
  -h, --help                 display help for command

Commands:
  run [options]              Generate documentation from your package.json
                             and some templates.
  init                       Register scripts in the current module's
                             package.json
  eject [prefix] [filename]  Extract part of thought's default templates into
                             the local configuration directory
  up-to-date                 Perform up-to-date check of the current
                             documentation. Exit with non-zero exit-code when
                             thought must be run again.
  help [command]             display help for command

thought init: Using Thought as version-script for npm

thought init will install thought run -a as version script in your package.json. This will run thought every time you bump the package-version using npm version. The updated documenation will be commited along with the version bump.

This is especially helpful when using the helper withPackageOf to include links to files in your github repository (since these links then include the version tag on github).

thought up-to-date: Using Thought as pre-push hook.

Along with the library husky, Thought can be used as pre-push hook to prevent missing README updates. When you change things that would otherwise update the documentation (like an example), it can easily happen that you push those changes without running Thought first.

You can prevent this from happening by using husky and a prepush script

// Edit package.json
{
  "scripts": {
    "prepush": "thought up-to-date"
  }
}

The command thought up-to-date runs Thought without writing any files, but it checks if any of the files that would have been written, would have been changed by the write. If this is the case, it exits with a non-zero exit-code and prints an error message.

Attention: This will not work properly if the output of examples includes variable parts such as the current timestamp or local wheather conditions

Calling thought from node.

const thought = require('thought')

thought({
  addToGit: true
})

API reference

thought(options)

Execute Thought in the current directory

Kind: global function
Api: public

Param Type Description
options object
[options.cwd] string the working directory to use as project root (deprecated because it does not always work as expected)
[options.addToGit] boolean add created files to git

Builtin Handlebars-helpers

The documentation for the builtin-helpers can be found here

License

thought is published under the MIT-license.

See LICENSE.md for details.

Release-Notes

For release notes, see CHANGELOG.md

Contributing guidelines

See CONTRIBUTING.md.

changelog

5.0.0 (2024-07-16)

  • chore!: drop Node support for versions before 14 (45be5cd)

Features

  • add badges for gh-actions (8f55fb6)
  • also load Handlebars helper from .thought/helpers.cjs (add52df)

Reverts

  • Revert "chore: fix CI for Windows" (706e675)
  • Revert "chore: fix CI for Windows (2)" (a898057)
  • Revert "chore: fix CI for Windows (3)" (56392f8)

BREAKING CHANGES

  • Node 13.x and before are not supported anymore

4.0.1 (2024-07-14)

4.0.0 (2020-07-02)

chore

  • drop support for Node 8 (1153f00)

Features

  • add command "eject" to override default files in the current project (8040572)

BREAKING CHANGES

  • drops support for Node 8

3.0.1 (2020-06-08)

Bug Fixes

  • replace module-path in examples with different quotes (a88eb0a)

3.0.0 (2020-01-27)

Bug Fixes

  • do not generate CONTRIBUTING.md by default (0348d34)
  • support for modules inside a mono-repo (1346e33)

Code Refactoring

  • remove "check-engines"-option (721f34d)

BREAKING CHANGES

  • "check-engines"-options removed
  • CONTRIBUTING.md is not generated anymore

Version 2.0.0 (Wed, 20 Feb 2019 22:02:31 GMT)

  • BREAKING CHANGES

    • b437746 auto-drop support for unsupported versions NodeJS - Nils Knappmeier (BREAKING CHANGE): In the future, only supported versions (LTS and active) of NodeJS will be supported by this package.
    • 15ed4b6 feat: remove greenkeeper autodetection in hasGreenkeeper-helper - Nils Knappmeier The Greenkeeper badge now has to be configured in .thought/config.js
  • refactorings

    • 043ff2a refactor: use promise-based fs-extra instead of pify(fs()) - Nils Knappmeier
    • a0011fd refactor: remove obsolete packages - Nils Knappmeier
    • a84fdd9 fix: remove implicit use of Q - Nils Knappmeier
    • b19ea37 chore: remove unneeded devDependency "recursive-copy" - Nils Knappmeier
    • 02760c5 refactor: replace 'm-io' by 'fs-extra' and 'glob' - Nils Knappmeier
    • 22e58cc chore: bump dependency versions, use nyc instead of istanbul - Nils Knappmeier
  • bump dependency versions

  • bugfixes

    • def3693 fix: fix silently rejected promise warning in dirTree helper - Nils Knappmeier
    • 003e932 fix: handle missing plugins properly in config - Nils Knappmeier

Version 1.5.2 (Fri, 25 Aug 2017 21:01:33 GMT)

  • c1d5831 Remove NodeJS 7 from travis build. Add NodeJS 8 - Nils Knappmeier
  • 28d3171 Bump dependency versions, fix code style - Nils Knappmeier
    • It also bumps the dependency of "trace-and-clarify-if-possible", which disables "trace@2" for NodeJS 8.

Version 1.5.1 (Sun, 02 Jul 2017 21:56:57 GMT)

  • Fix tests for npm-badge from shields.io - Nils Knappmeier
  • 6f7b912 Remove "preversion"-script from package.json - Nils Knappmeier
  • 314d5c3 Remove "find-package"-dependency from cli-script (+ refactoring) - Nils Knappmeier
  • 6e2f575 372a953 Use npm-badge from shields.io - Nils Knappmeier
    • This one may be controversial in terms of Semver, because tests of old Thought versions are failing due to this change, but I consider this to be a patch-change only, because it fixes the badge for scoped packages and the badge is not really supposed to be parsed (humans still see mainly the same badge)

Version 1.5.0 (Sun, 25 Jun 2017 08:52:58 GMT)

  • 0a694ac Generate codecov-badge if codecov appears in .travis.yml or appveyor.yml - Nils Knappmeier

Version 1.4.0 (Sat, 24 Jun 2017 21:24:30 GMT)

  • d97570f Add @rawUrl special-variable to "#withPackageOf"-helper - Nils Knappmeier

Version 1.3.0 (Sat, 10 Jun 2017 20:44:35 GMT)

  • b52a6fe Helper '#withPackageOf' adds file-path relative to the project root - Nils Knappmeier

Version 1.2.0 (Mon, 22 May 2017 19:17:41 GMT)

  • a3405c5 Helper "withPackageOf" now also supports github-ssh-urls in package.json - Nils Knappmeier
  • 134ac29 New helper "repoWebUrl" - Nils Knappmeier

Version 1.1.5 (Sun, 21 May 2017 15:02:04 GMT)

  • 4f22c1f Fixed "thought init" process - Nils Knappmeier

Version 1.1.4 (Sun, 21 May 2017 12:35:54 GMT)

  • 3475e8f Fix removal of q (2) - Nils Knappmeier

Version 1.1.3 (Sun, 21 May 2017 12:34:06 GMT)

  • 4ff79e3 Fix removal of q - Nils Knappmeier
  • 61204e1 fix(package): update customize-write-files to version 2.0.0 - greenkeeper[bot]

Version 1.1.2 (Sun, 09 Apr 2017 08:57:35 GMT)

  • 68adcb4 Fix removal of q-deep - Nils Knappmeier

Version 1.1.1 (Sat, 08 Apr 2017 22:17:20 GMT)

  • 6c9b552 chore(package): update customize to version 2.0.1 - greenkeeper[bot]
  • 6a21993 Remove use of q-specific function "Promise~done()" - Nils Knappmeier
  • 8731a6f chore(package): update dependencies - greenkeeper[bot]

Version 1.1.0 (Fri, 07 Apr 2017 11:39:49 GMT)

  • 35e700d Generell documentation overhaul - Nils Knappmeier
  • cd9f970 Add "arr"-helper and options "dot" and "ignore" to {{dirtree}}-helper - Nils Knappmeier
  • 4579887 option "links='true'" to generate links in the {{dirTree}}-helper - Nils Knappmeier
  • a6b3fe4 Update "init"-command for use with node 6+ - Nils Knappmeier
  • 12d151a Add "badges.greenkeeper"-option to .thought/config.js - Nils Knappmeier

Version 1.0.4 (Sat, 25 Mar 2017 00:25:36 GMT)

  • 5d7fe7c Replace call to lodash in preprocessor - Nils Knappmeier

Version 1.0.3 (Sat, 25 Mar 2017 00:19:43 GMT)

  • bada175 Bump version of customize-engine-handlebars (reduce size) - Nils Knappmeier
  • 075e30d "customize-engine-handlebars" must be a normal dependency - Nils Knappmeier
  • 52e9ca7 Add "files"-property to package.json (reduce size) - Nils Knappmeier
  • 9b2c076 Use "popsicle" instead of request-promise (smaller) - Nils Knappmeier

Version 1.0.2 (Fri, 24 Mar 2017 16:29:01 GMT)

  • f6a19c6 Replace lodash-dependency by smaller functions - Nils Knappmeier

Version 1.0.1 (Fri, 24 Mar 2017 12:23:35 GMT)

  • 2963a51 Fix link to handlebars-directory in README - Nils Knappmeier

Version 1.0.0 (Fri, 24 Mar 2017 10:47:13 GMT)

  • 1c68d98 More documentation (especially API-docs of the helpers) - Nils Knappmeier
  • 84446b4 Support for loading plugins - Nils Knappmeier
  • dac01c6 "hasGreenkeeper" now returns "false" for projects without repo-url - Nils Knappmeier

Version 0.11.0 (Sun, 19 Mar 2017 16:41:52 GMT)

  • 0f2b229 Update depedency-versions - Nils Knappmeier
  • 00452b4 BREAKING: Change "htmlId"-helper to match the GitHub way of creating url-hashes - Nils Knappmeier
  • 5ad6c17 Add tests for all helpers - Nils Knappmeier
  • 8f2cc3b BREAKING: Do not resolve "directories"-property in preprocessor - Nils Knappmeier
  • d7e0f94 Add tests for "addToGit" and projects with examples - Nils Knappmeier
  • 2c12bf1 BREAKING: Remove jsdoc-helper, apidoc-helper + a lot of chore - Nils Knappmeier
  • 2909051 BREAKING: Remove support for old node versions + Support for greenkeeper - Nils Knappmeier
  • afb708f Simple framework for integration-tests - Nils Knappmeier

Version 0.10.0 (Fri, 13 Jan 2017 13:38:25 GMT)

  • 05cfa0e Add parameter 'up-to-date-hook' for checking generated files (#4) - Nils Knappmeier

Version 0.9.4 (Tue, 20 Dec 2016 00:19:44 GMT)

  • 6fc2471 Use new customize-version from github - Nils Knappmeier

Version 0.9.3 (Tue, 20 Dec 2016 00:03:45 GMT)

  • a5ce38b Update m-io version for handling of missing "templates" directory - Nils Knappmeier

Version 0.9.2 (Mon, 19 Dec 2016 23:52:15 GMT)

  • f2dd765 More replacements of q-io by m-io - Nils Knappmeier

Version 0.9.1 (Mon, 19 Dec 2016 23:05:19 GMT)

  • d360f70 Use "m-io/fs" instead of "q-io/fs" - Nils Knappmeier

Version 0.9.0 (Mon, 19 Dec 2016 22:19:10 GMT)

  • c76f64c Use "trace-and-clarify-if-possible" - Nils Knappmeier
  • 2ecdeba Upgrade package dependencies - Nils Knappmeier
  • 1467cf9 Reduce size by replacing jsdoc-to-markdown with jsdoc-parse and dmd - Nils Knappmeier

Version 0.8.1 (Tue, 12 Jul 2016 20:54:47 GMT)

  • b3cbd2b Use "thoughtful-release" to update the changelog on version bumps - Nils Knappmeier

Version 0.8.0 (Tue, 12 Jul 2016 20:46:16 GMT)

  • 1c8a344 Minor JSDoc comments added - Nils Knappmeier
  • 8465f12 Add White-space control to badge-partials - Nils Knappmeier
  • c02604f Appveyor badge must be there only if 'appveyor.yml' is present - Nils Knappmeier
  • d761a92 Badges are now in separate partials. Badge for Appveyor - Nils Knappmeier

Version 0.7.0 (Wed, 27 Jan 2016 19:22:15 GMT)

  • f6d322b Add release anchor to CHANGELOG.md - Nils Knappmeier
  • fd46555 Fix for travis and Coveralls badges - Nils Knappmeier
  • 4857c6e Added "github" helper to create links to github files. - Nils Knappmeier
  • 781f63e Use "customize-write-files" to save the resulting files to disk. - Nils Knappmeier
  • 8ad63d2 Remove "API"-header if no main-file is configured - Nils Knappmeier
  • 327adcb Only show "npm install..." if package is not marked as private. - Nils Knappmeier
  • f9b117e Show badges based on conditions - Nils Knappmeier
  • 1bbdc8f Remove redundant badge - Nils Knappmeier
  • af24469 {{withPackageOf}}: Remove leading "git+" from dependency repository urls - Nils Knappmeier

v0.6.1 - 2015-11-29

Doc

  • Remove development notice in README.md

v0.6.0 - 2015-11-29

Change

  • Renamed helper "dirtree" to "dirTree"
  • dirTree-helper is no async
  • Using archy for tree-rendering

v0.5.3 - 2015-11-08

Fix

  • Accept all unstable version of customize.

v0.5.2 - 2015-10-05

Fix

v0.5.1 - 2015-09-28

Fix

  • Typo while loading helpers.js. Custom helpers did not load.

v0.5.0 - 2015-08-17

Add

  • The example helper now has an additional hash-argument snippet. It this is set to true, only contents within the lines containing ---<snip>--- and ---</snip>--- is included.

  • The exec helper now has the special lang-value inline which wraps the process output with single backquotes instead of fences.

v0.4.1 and v0.4.2 - 2015-08-15

Fix

  • Docs and formatting

v0.4.0 - 2015-08-15

Fix

  • Documentation cleanup, more documentation about customizing the documentation templates.

Change

  • The files to override helpers and the preprocessor are now .thought/helpers.js and .thought/preprocessor.js to consolidate with the structure of the handlebars/-directory in Thought.

v0.3.0 - 2015-08-15

Change

Fix

  • htmlId helper now always returns lowercase

v0.2.1 - 2015-08-06

Fix

  • If the jsdoc-helper did not create any docs, the whole output file was not written.

v0.2.0 - 2015-08-04

Change

  • rendertree is now a block-helper, the label of each node is determined by the block-contents
  • example-helper now also converts require('../file') into `require('package-name/file')
  • include-helper: Determines fence-type from file-extension if not explicitly provided
  • In order to run thought, thought run must be called.

... and many more changes

Add

  • Additional helper jsdoc to generate documentation for javscript-files. multilang-apidocs is by far not as powerful as jsdoc-to-markdown
  • npm-helper to link to the npm-page of a page

v0.0.1 - 2015-07-02

Initial version