krisztianb / typedoc-plugin-merge-modules

Plugin for TypeDoc that merges the content of modules
ISC License
22 stars 4 forks source link

Namespaces and Interfaces are not merged. #10

Closed jackens closed 2 years ago

jackens commented 2 years ago

package.json:

{
  "devDependencies": {
    "typedoc": "0.22.13",
    "typedoc-plugin-markdown": "3.11.14",
    "typedoc-plugin-merge-modules": "3.1.0",
    "typescript": "4.6.3"
  },
  "name": "issue",
  "type": "module"
}

typedoc.json:

{
  "cleanOutputDir": true,
  "entryPointStrategy": "expand",
  "entryPoints": [
    "src"
  ],
  "gitRevision": "master",
  "hideBreadcrumbs": true,
  "hideInPageTOC": true,
  "hideLegend": true,
  "out": "_doc",
  "readme": "none"
}

tsconfig.json:

{
  "compilerOptions": {
    "allowJs": true,
    "declaration": true,
    "emitDeclarationOnly": true
  },
  "include": [
    "src/**/*.js"
  ]
}

src/file.js:

/**
 * Some module.
 *
 * @module
 */

/**
 * This description is not in the documentation!
 *
 * @callback Type1 This description is not in the documentation!
 *
 * @param {number} one This description is not in the documentation!
 * @param {number} two This description is not in the documentation!
 *
 * @returns {number} This description is not in the documentation!
 */

/**
 * @typedef {{(one: number, two: number) => number}} Type2
 *
 * Some type 2.
 */

/**
 * This block will be placed in the `interfaces/Type3.md` file
 * instead of the `README.md` file.
 *
 * @typedef Type3 Some type 3.
 *
 * @property {number} one property #1
 * @property {number} two property #2
 */

/**
 * @typedef {{
 *   one: number;
 *   two: number;
 * }} Type4
 *
 * Some type 4.
 */

/**
 * Some type 5.
 *
 * This block will be placed in the `modules/Type5.md` file
 * instead of the `README.md` file.
 */
export const Type5 = {}

/**
 * @param {number} n
 *
 * @returns {number}
 */
Type5.id = n => n

Type5.answer = 42

After running

npx typedoc

and

ls -R _doc

we got

README.md       interfaces      modules

_doc/interfaces:
Type3.md

_doc/modules:
Type5.md
krisztianb commented 2 years ago

Hi. This plugin merges modules. I haven't used TypeDoc to document JS files yet. Didn't know that works.

I'm a bit confused by your example. Where is your namespace and interface? What would be your expected output?

jackens commented 2 years ago

TypeScript works quite well with JavaScript files, and if they have JSDoc blocks in addition, it generates .d.ts files that TypeDoc can turn into quite nice documentation :)

I would expect Type3 to be in README.md, just like Type4 (they're actually the same definitions). Likewise with Type5, which should be merged into README.md.

The plugin should merge the contents of modules and interfaces directories.

jackens commented 2 years ago

README.md:

# issue

Some module.

## Namespaces

- [Type5](modules/Type5.md)

## Interfaces

- [Type3](interfaces/Type3.md)

## Type aliases

### Type1

Ƭ **Type1**<\>: <\>(`one`: `number`, `two`: `number`) => `number`

#### Type declaration

▸ <\>(`one`, `two`): `number`

##### Parameters

| Name  | Type     |
|:------|:---------|
| `one` | `number` |
| `two` | `number` |

##### Returns

`number`

___

### Type2

Ƭ **Type2**<\>: (`one`: `number`, `two`: `number`) => `number`

#### Type declaration

▸ (`one`, `two`): `number`

Some type 2.

##### Parameters

| Name  | Type     |
|:------|:---------|
| `one` | `number` |
| `two` | `number` |

##### Returns

`number`

#### Defined in

file.js:19

___

### Type4

Ƭ **Type4**<\>: `Object`

Some type 4.

#### Type declaration

| Name  | Type     |
|:------|:---------|
| `one` | `number` |
| `two` | `number` |

#### Defined in

file.js:38

## Variables

### Type5

• `Const` **Type5**: typeof [`Type5`](README.md#type5) = `{}`

Some type 5.

This block will be placed in the `modules/Type5.md` file
instead of the `README.md` file.

#### Defined in

file.js:49

interfaces/Type3.md:

# Interface: Type3<\>

Some type 3.

## Properties

### one

• **one**: `number`

property #1

#### Defined in

file.js:30

___

### two

• **two**: `number`

property #2

#### Defined in

file.js:31

modules/Type5.md:

# Namespace: Type5

## Variables

### answer

• **answer**: `number`

## Functions

### id

▸ **id**(`n`): `number`

#### Parameters

| Name | Type     |
|:-----|:---------|
| `n`  | `number` |

#### Returns

`number`

#### Defined in

file.js:56
krisztianb commented 2 years ago

I'm not sure I can follow you there.

This plugin is meant to remove the extra module layer that TypeDoc creates. A module is normally a file which contains something that you want to have documented. The plugin moves all the documented things into the project but doesn't move all documented things into one file which you seem to be looking for here.

jackens commented 2 years ago

I assumed that the plugin that merges the content of modules should also merge the content of a single module/file (src/file.js from my example). Feel free to close the issue if I am wrong. Thank you for your replies!

krisztianb commented 2 years ago

So you want the documentation of several types to be in one file and not one file per type, right? If so then this is not the goal of this plugin.