GithubHelp home page GithubHelp logo

typedoc-plugin-external-module-map's Introduction

typedoc-plugin-external-module-map

What

A plugin for Typedoc

When trying to unify documentation for multiple modules residing inside a shared source repository, the default way Typedoc assignes top-level module names might not satisfy.

This plugin allows you to specify a regular expression with a capture group. This is then used to collect related items into one module.

This plugin is inspired by, and based on, https://github.com/christopherthielen/typedoc-plugin-external-module-name , but does not require you to add additional annotations to each .ts file in your project.

Suppose you have

module/@mycompany/thing1/index.ts
module/@mycompany/thing1/src/otherfiles.ts
module/@mycompany/thing2/index.ts
module/@mycompany/thing2/src/otherfiles.ts

Typedoc will create four "External Modules", named for each .ts file.

  • "@mycompany/thing1/index"
  • "@mycompany/thing1/src/otherfiles"
  • "@mycompany/thing2/index"
  • "@mycompany/thing1/src/otherfiles"

This plugin allows each file to specify the Typedoc External Module its code should belong to. If multiple files belong to the same module, they are merged.

This allows more control over the modules that Typedoc generates. Instead of the four modules above, we could group them into two:

  • thing1
  • thing2

Installing

Typedoc 0.4 has the ability to discover and load typedoc plugins found in node_modules. Simply install the plugin and run typedoc.

However, Typedoc 0.24 did away with that, so now you have to specify it explicitly every time.

npm install --save typedoc-plugin-external-module-map
typedoc --plugin typedoc-plugin-external-module-map

Usage

This plugin adds a new input option

--external-modulemap  ".*\/modules\/@mycompany\/([\\w\\-_]+)\/"

If you specify it from the command line, be sure to escape the input string so bash doesn't expand it.

It is probably easier to create a typedoc options file (typedoc.json) and add it there:

{
  "name": "My Library",
  "mode": "modules",
  "out": "doc",
  "theme": "default",
  "ignoreCompilerErrors": "false",
  "preserveConstEnums": "true",
  "exclude": "*.spec.ts",
  "external-modulemap": ".*\/modules\/@mycompany\/([\\w\\-_]+)\/",
  "stripInternal": "false"
}

If your pattern is not expressable in a single regexp, you can provide an array of regexps in the .json file. First to match will return the value.

Example:

{
  "name": "My Library",
  "mode": "modules",
  "out": "doc",
  "theme": "default",
  "ignoreCompilerErrors": "false",
  "preserveConstEnums": "true",
  "exclude": "*.spec.ts",
  "external-modulemap": [
	   ".*/(types/[\\w\\-_]+)/",
	   ".*/(core/decorators/[\\w\\-_]+)/",
	   ".*/subfolder/(core/[\\w\\-_]+)/",
   ],
  "stripInternal": "false"
}

Entrypoint Strategy "Packages"

The new features in Typedoc of "entryPointStrategy": "packages", or using @group or @category with the appropriate base plugins have mostly superseeded this plugin, but there are still a few cases in which it makes sense. Ie if you have sub-packages, or multiple entry points.

In these cases, you use the entrypoint strategy for the top level navigation, and then in the individual projects, place a typedoc.json with the external-modulemap configuration specific to the package.

The configuration will not be picked up from the top-level typedoc.json

typedoc-plugin-external-module-map's People

Contributors

amiller-gh avatar asgerjensen avatar danbalarin avatar haraldf avatar jduhls avatar xdan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

typedoc-plugin-external-module-map's Issues

Support typedoc 0.22.x

Hi @asgerjensen, thanks for a great plugin. Typedoc 0.22 has been released for a while. I'm willing to help adapt the new typedoc API for the plugin if you don't mind.

TypeError: Cannot read property 'Prefetch' of undefined

typedoc src
Loaded plugin /Users/stereodenis/work/busfor-app/node_modules/typedoc-plugin-external-module-map

Using TypeScript 3.7.5 from /Users/stereodenis/work/busfor-app/node_modules/typedoc/node_modules/typescript/lib
/Users/stereodenis/work/busfor-app/node_modules/typedoc-plugin-external-module-map/plugin.js:46
            this.options.read({}, options_1.OptionsReadMode.Prefetch);
                                                            ^

TypeError: Cannot read property 'Prefetch' of undefined
    at ExternalModuleMapPlugin.onBegin (/Users/stereodenis/work/busfor-app/node_modules/typedoc-plugin-external-module-map/plugin.js:46:61)
    at triggerEvents (/Users/stereodenis/work/busfor-app/node_modules/typedoc/dist/lib/utils/events.js:128:43)
    at triggerApi (/Users/stereodenis/work/busfor-app/node_modules/typedoc/dist/lib/utils/events.js:110:13)
    at eventsApi (/Users/stereodenis/work/busfor-app/node_modules/typedoc/dist/lib/utils/events.js:21:18)
    at Converter.trigger (/Users/stereodenis/work/busfor-app/node_modules/typedoc/dist/lib/utils/events.js:264:13)
    at Converter.convert (/Users/stereodenis/work/busfor-app/node_modules/typedoc/dist/lib/converter/converter.js:89:14)
    at CliApplication.convert (/Users/stereodenis/work/busfor-app/node_modules/typedoc/dist/lib/application.js:72:39)
    at CliApplication.bootstrap (/Users/stereodenis/work/busfor-app/node_modules/typedoc/dist/lib/cli.js:45:34)
    at Object.<anonymous> (/Users/stereodenis/work/busfor-app/node_modules/typedoc/bin/typedoc:5:5)

TypeError: Class constructor ConverterComponent cannot be invoked without 'new'

Recently upgraded typedoc-related modules.

From package.json

{
    "typedoc": "0.14.2",
    "typedoc-plugin-external-module-map": "0.1.0",
    "typedoc-plugin-markdown": "1.1.26",
    "typescript": "~3.2.2"
}
Error: The plugin D:\Projects\my-project\node_modules\typedoc-plugin-external-module-map could not be loaded.

TypeError: Class constructor ConverterComponent cannot be invoked without 'new'
    at new ExternalModuleMapPlugin (D:\Projects\my-project\node_modules\typedoc-plugin-external-module-map\plugin.js:43:46)
    at Converter.addComponent (D:\Projects\my-project\node_modules\typedoc\dist\lib\utils\component.js:123:19)
    at Converter.addComponent (D:\Projects\my-project\node_modules\typedoc\dist\lib\converter\converter.js:28:33)
    at module.exports (D:\Projects\my-project\node_modules\typedoc-plugin-external-module-map\index.js:8:17)
    at PluginHost.load (D:\Projects\my-project\node_modules\typedoc\dist\lib\utils\plugins.js:36:21)
    at CliApplication.bootstrap (D:\Projects\my-project\node_modules\typedoc\dist\lib\application.js:42:22)
    at CliApplication.bootstrap (D:\Projects\my-project\node_modules\typedoc\dist\lib\cli.js:24:30)
    at new Application (D:\Projects\my-project\node_modules\typedoc\dist\lib\application.js:31:14)
    at new CliApplication (D:\Projects\my-project\node_modules\typedoc\dist\lib\cli.js:22:1)
    at Object.<anonymous> (D:\Projects\my-project\node_modules\typedoc\bin\typedoc:4:1)

Using TypeScript 3.2.4 from D:\Projects\my-project\node_modules\typescript\lib

1.2.x crashes with `context.project.removeReflection is not a function`

After updating plugin to 1.2.x our last docs build crashed with the following error:

17:12:41 /var/lib/jenkins/workspace/project/node_modules/typedoc-plugin-external-module-map/plugin.js:107
17:12:41                 context.project.removeReflection(renaming, true);
17:12:41                                 ^
17:12:41 
17:12:41 TypeError: context.project.removeReflection is not a function
17:12:41     at moduleRenames.forEach.item (/var/lib/jenkins/workspace/project/node_modules/typedoc-plugin-external-module-map/plugin.js:107:33)
17:12:41     at Array.forEach (<anonymous>)
17:12:41     at ExternalModuleMapPlugin.onBeginResolve (/var/lib/jenkins/workspace/project/node_modules/typedoc-plugin-external-module-map/plugin.js:83:32)
17:12:41     at triggerEvents (/var/lib/jenkins/workspace/project/node_modules/typedoc/dist/lib/utils/events.js:128:43)
17:12:41     at triggerApi (/var/lib/jenkins/workspace/project/node_modules/typedoc/dist/lib/utils/events.js:110:13)
17:12:41     at eventsApi (/var/lib/jenkins/workspace/project/node_modules/typedoc/dist/lib/utils/events.js:21:18)
17:12:41     at Converter.trigger (/var/lib/jenkins/workspace/project/node_modules/typedoc/dist/lib/utils/events.js:264:13)
17:12:41     at Converter.resolve (/var/lib/jenkins/workspace/project/node_modules/typedoc/dist/lib/converter/converter.js:171:14)
17:12:41     at Converter.convert (/var/lib/jenkins/workspace/project/node_modules/typedoc/dist/lib/converter/converter.js:91:30)
17:12:41     at CliApplication.convert (/var/lib/jenkins/workspace/project/node_modules/typedoc/dist/lib/application.js:61:39)

I cannot provide sample TS code to run against because it is not open-sourced.

1.1.0 works fine.
We use typedoc version 0.15.8.

Plugin installation doesn't seem to work

After installing the plugin in the way described in the docs typedoc failes to build any documentation. It just throws this error:

> typedoc --out ./doc ./src --module commonjs --mode modules

Error: The plugin typedoc-plugin-external-module-name could not be loaded.

Error: Cannot find module 'typedoc-plugin-external-module-name'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at PluginHost.load (/usr/lib/node_modules/typedoc/dist/lib/utils/plugins.js:46:32)
    at CliApplication.Application.bootstrap (/usr/lib/node_modules/typedoc/dist/lib/application.js:51:22)
    at CliApplication.bootstrap (/usr/lib/node_modules/typedoc/dist/lib/cli.js:38:49)
    at CliApplication.Application (/usr/lib/node_modules/typedoc/dist/lib/application.js:39:15)
    at new CliApplication (/usr/lib/node_modules/typedoc/dist/lib/cli.js:35:42)
    at Object.<anonymous> (/usr/lib/node_modules/typedoc/bin/typedoc:4:1)

The only way I can figure out how to get it working again is by deinstalling the plugin.

possible to specify multiple maps?

Great plugin! I'd like to specify multiple mapping expressions for the extension to use, such as:

./src/components/([\w\-]+)/
./src/extensions/([\w\-
]+)/
....

Is there a way to do this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.