forked from cybersemics/em
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.typedoc-plugin-external-module-name.js
32 lines (30 loc) · 1.48 KB
/
.typedoc-plugin-external-module-name.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* Custom module name mapping function for typedoc-plugin-external-module-name
* https://github.com/christopherthielen/typedoc-plugin-external-module-name#custom-module-name-generation
* This function defines all module names and creates the module hierarchy.
* Created hierarchy is displayed in the right navbar of the generated TypeDoc documentation.
*
* @param explicit - Value, if the module has an explicit annotation, i.e., @module explicit
* @param implicit - The plugin's default mapping
* @param path - The path to the file
*/
module.exports = (explicit, implicit, path) => {
// make index.js files root modules (e.g. action-creators.index.js => action-creators)
if (path.includes('index.js') || path.includes('index.ts')) return implicit
// ignore native modules otherwise typedoc crashes
// https://github.com/christopherthielen/typedoc-plugin-external-module-name/issues/682
if (path.includes('.native.')) return
// check for files which are placed in subdirectories of src
if (implicit !== '.') {
const matches = path.match(RegExp(`${implicit}/.*`))
if (!matches) return
const endIndex = matches[0].lastIndexOf('.')
// return directoryName.fileName (e.g. "action-creators.alert")
return matches[0].slice(0, endIndex).replace(/\//g, '.')
} else {
const matches = path.match(/src\/.*\./)[0]
if (!matches) return
// return app.fileName (e.g. "app.browser")
return matches[0].replace(/src/, 'app').replace('.', '').replace(/\//g, '.')
}
}