How to generate documentation for TypeScript project or module


Example: generate documentation for module @nestjs/core

Step 1: Install the global CLI
npm install -g typedoc

Result:

D:\TS-doc>npm install -g typedoc
C:\Program Files\nodejs\typedoc -> C:\Program Files\nodejs\node_modules\typedoc\
bin\typedoc
npm WARN typedoc@0.19.2 requires a peer of typescript@3.9.x || 4.0.x but none is
 installed. You must install peer dependencies yourself.

+ typedoc@0.19.2
added 39 packages from 358 contributors in 28.626s

Step 2: prepare source code TypeScript of your project or module
Example: clone repo nestjs

$ git clone https://github.com/nestjs/nest
Cloning into 'nest'...
remote: Enumerating objects: 87797, done.
Receiving objects: 100% (87797/87797), 123.87 MiB | 1.43 MiB/s, done.
remote: Total 87797 (delta 0), reused 0 (delta 0), pack-reused 87797
Resolving deltas: 100% (73228/73228), done.

Step 2.a: Install requirements:

D:\TS-doc\nest>npm i

> bufferutil@4.0.2 install D:\TS-doc\nest\node_modules\bufferutil
> node-gyp-build


> utf-8-validate@5.0.3 install D:\TS-doc\nest\node_modules\utf-8-validate
> node-gyp-build


> grpc@1.24.4 install D:\TS-doc\nest\node_modules\grpc
> node-pre-gyp install --fallback-to-build --library=static_library

node-pre-gyp WARN Using request for node-pre-gyp https download
[grpc] Success: "D:\TS-doc\nest\node_modules\grpc\src\node\extension_binary\node
-v83-win32-x64-unknown\grpc_node.node" is installed via remote

> husky@4.3.0 install D:\TS-doc\nest\node_modules\husky
> node husky install

husky > Setting up git hooks
Husky requires Git >=2.13.0. Got v2.10.0.
husky > Failed to install

> command-join@2.0.1 postinstall D:\TS-doc\nest\node_modules\command-join
> npx -p @seangenabe/tnx tnx || exit 0

npx: installed 1 in 4.322s

    Thanks for installing command-join!

    If you like this package, be sure to star its repo,
    and please consider donating:

        https://seangenabe.netlify.com/donate


> core-js@3.8.0 postinstall D:\TS-doc\nest\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfill
ing JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Colle
ctive or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a goo
d job -)


> @apollo/protobufjs@1.0.4 postinstall D:\TS-doc\nest\node_modules\@apollo\proto
bufjs
> node scripts/postinstall


> protobufjs@6.10.1 postinstall D:\TS-doc\nest\node_modules\protobufjs
> node scripts/postinstall


> jsonpath@1.0.2 postinstall D:\TS-doc\nest\node_modules\jsonpath
> node lib/aesprim.js > generated/aesprim-browser.js


> husky@4.3.0 postinstall D:\TS-doc\nest\node_modules\husky
> opencollective-postinstall || exit 0

Thank you for using husky!
If you rely on this package, please consider supporting our open collective:
> https://opencollective.com/husky/donate


> nodemon@2.0.6 postinstall D:\TS-doc\nest\node_modules\nodemon
> node bin/postinstall || exit 0


> @nestjs/core@7.5.3 postinstall D:\TS-doc\nest
> opencollective

                           Thanks for installing nest
                 Please consider donating to our open collective
                        to help us maintain this package.

                            Number of contributors: 0
                              Number of backers: 465
                              Annual budget: $44,498
                             Current balance: $2,348

         Become a partner: https://opencollective.com/nest/donate

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules\nod
emon\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@
2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}
)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\fse
vents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@
1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}
)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules\moc
ha\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@
2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}
)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules\@ty
pes\gulp\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@
2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}
)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules\@ne
stjs\graphql\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@
2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}
)

added 2951 packages from 1915 contributors and audited 3033 packages in 593.779s


109 packages are looking for funding
  run `npm fund` for details

found 635 vulnerabilities (537 low, 98 high)
  run `npm audit fix` to fix them, or `npm audit` for details

Step 2.b: Build modules

D:\TS-doc\nest>npm run build

> @nestjs/core@7.5.3 build D:\TS-doc\nest
> gulp build --dist node_modules/@nestjs

[22:05:42] Using gulpfile D:\TS-doc\nest\gulpfile.js
[22:05:42] Starting 'build'...
[22:05:42] Starting 'common'...
[22:05:47] Finished 'common' after 5.44 s
[22:05:47] Starting 'core'...
[22:05:53] Finished 'core' after 6.28 s
[22:05:53] Starting 'microservices'...
[22:05:59] Finished 'microservices' after 6.02 s
[22:05:59] Starting 'websockets'...
[22:06:03] Finished 'websockets' after 3.22 s
[22:06:03] Starting 'testing'...
[22:06:05] Finished 'testing' after 2.28 s
[22:06:05] Starting 'platform-express'...
[22:06:07] Finished 'platform-express' after 2.21 s
[22:06:07] Starting 'platform-fastify'...
[22:06:10] Finished 'platform-fastify' after 2.95 s
[22:06:10] Starting 'platform-socket.io'...
[22:06:12] Finished 'platform-socket.io' after 2.12 s
[22:06:12] Starting 'platform-ws'...
[22:06:14] Finished 'platform-ws' after 2.15 s
[22:06:14] Finished 'build' after 33 s

> @nestjs/core@7.5.3 postbuild D:\TS-doc\nest
> gulp move

[22:06:19] Using gulpfile D:\TS-doc\nest\gulpfile.js
[22:06:19] Starting 'move'...
[22:07:30] Finished 'move' after 1.17 min

Step 2.c: Some fixes
How to fix error: Namespace ‘serveStatic’ has no exported member ‘RequestHandlerConstructor’

Step 2.d: install requirements for packages/core

D:\TS-doc\nest\packages\core>npm i

> @nestjs/core@7.5.5 postinstall D:\TS-doc\nest\packages\core
> opencollective || exit 0

                           Thanks for installing nest
                 Please consider donating to our open collective
                        to help us maintain this package.

                            Number of contributors: 0
                              Number of backers: 465
                              Annual budget: $44,498
                             Current balance: $2,348

         Become a partner: https://opencollective.com/nest/donate

npm notice created a lockfile as package-lock.json. You should commit this file.

npm WARN @nestjs/core@7.5.5 requires a peer of reflect-metadata@^0.1.12 but none
 is installed. You must install peer dependencies yourself.
npm WARN @nestjs/core@7.5.5 requires a peer of rxjs@^6.0.0 but none is installed
. You must install peer dependencies yourself.
npm WARN @nestjs/common@7.5.5 requires a peer of reflect-metadata@^0.1.12 but no
ne is installed. You must install peer dependencies yourself.
npm WARN @nestjs/common@7.5.5 requires a peer of rxjs@^6.0.0 but none is install
ed. You must install peer dependencies yourself.

added 18 packages from 24 contributors and audited 18 packages in 4.236s

4 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

Step 3: Execute typedoc on your project
typedoc --out docs src

Example:

D:\TS-doc\nest>typedoc --mode file --out ../doc/@nestjs/core packages/core --rea
dme packages/core/Readme.md --target ES2015

Using TypeScript 3.9.7 from C:\Users\Administrator\AppData\Roaming\nvm\v14.7.0\n
ode_modules\typescript\lib
Rendering [========================================] 100%

Documentation generated at D:\TS-doc\doc\@nestjs\core

Done!

Recent search terms:

  • pale9ev

Leave a Reply