Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[WIP] API Docs #413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 55 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
fe1513b
feat(api): Add basic generate api doc script
BrunnerLivio May 12, 2019
8321fd0
feat(api): Add api component and display api list
BrunnerLivio May 12, 2019
3bf2094
feat(api): Add api item icons
BrunnerLivio May 12, 2019
56416c1
feat(api): Add properties to detail page
BrunnerLivio May 12, 2019
372af01
feat(api): Filter out private documents
BrunnerLivio May 28, 2019
19607ce
feat(api): Add method docs for classes
BrunnerLivio May 28, 2019
18963c2
feat(api): Add code block to method examples
BrunnerLivio May 28, 2019
795766c
feat(api): Add enum template
BrunnerLivio May 31, 2019
b42b800
feat(api): Add api type label to detail page
BrunnerLivio Jun 5, 2019
ac4d039
feat(api): Add injectable documentation page
BrunnerLivio Jun 5, 2019
4d3672a
fix(api): Display correct package name
BrunnerLivio Jun 5, 2019
6414dc5
feat(api): Add usageNotes as valid tag-def
BrunnerLivio Jun 9, 2019
dcef185
feat(api): Remove injectable constructors
BrunnerLivio Jun 18, 2019
0425458
feat(api): Render the correct type of param
BrunnerLivio Jun 18, 2019
48af19b
feat(api): Add interface and type alias template
BrunnerLivio Jun 18, 2019
aefb7ad
fix(api): Class overview method parameters
BrunnerLivio Jun 18, 2019
6ef8f15
feat(api): Add menu component
BrunnerLivio Jun 24, 2019
1122995
feat(api): Interlink Modules with Injecatbles
BrunnerLivio Jun 24, 2019
2941d7c
feat(api): Display api type label as module instead nestmodule
BrunnerLivio Jun 24, 2019
6a427fd
fix(api): Output path resolution
BrunnerLivio Jun 24, 2019
60967fa
feat(api): Add passport module
BrunnerLivio Jun 24, 2019
81ba10e
feat(api): Add elasticsearch module
BrunnerLivio Jun 24, 2019
e7c0f9d
feat(api): Add cqrs module
BrunnerLivio Jun 24, 2019
93ec584
feat(api): Add throws and examples to method overview
BrunnerLivio Jun 25, 2019
4959586
feat(api): Small clean ups
BrunnerLivio Jun 25, 2019
8fb0a60
feat(api): Add query filter
BrunnerLivio Jun 25, 2019
ffc4537
feat(api): Add support for automatic cross references
BrunnerLivio Jun 25, 2019
ab42ea1
feat(api): Add header links
BrunnerLivio Jun 25, 2019
61fb6f1
feat(api): Add decorator processor
BrunnerLivio Jun 29, 2019
05b03c3
feat(api): Add see also
BrunnerLivio Jun 29, 2019
564d5ef
feat(api): Add remaining nest packages
BrunnerLivio Jun 29, 2019
4b22ee2
feat(api): Add README description of the API docs
BrunnerLivio Jul 2, 2019
007d380
readme.md: Update README.md
johnbiundo Jul 3, 2019
3616f8d
chore(api): Add nest-factory explicitely to packages path
BrunnerLivio Jul 3, 2019
529c4ac
fix(api): Copy over usageNotes from overloads
BrunnerLivio Jul 3, 2019
40ccb64
fix(api): remove overflow hidden from a tag
BrunnerLivio Jul 3, 2019
c086a6f
feat(api): Display decorator functions
BrunnerLivio Jul 3, 2019
294c6cf
feat(api): Add missing nest packages
BrunnerLivio Jul 3, 2019
f669131
feat(api): Use post-process-html from dgeni-packages
BrunnerLivio Jul 8, 2019
108c75e
feat(api): Add package markdown index file processor
BrunnerLivio Jul 10, 2019
e38bfeb
fix(api): Angular 8 ViewChild 2nd parameter
BrunnerLivio Jul 10, 2019
d9375d7
feat(api): Add breadcrumbs
BrunnerLivio Jul 10, 2019
332620d
feat(api): Show links in code
BrunnerLivio Jul 10, 2019
7c8022a
feat(api): Fixup compiler warnings
BrunnerLivio Jul 10, 2019
347c4c3
fix(api): Should append explicit subpackages to parent packages
BrunnerLivio Jul 17, 2019
4ae17f4
refactor(api): Use classes for processors
BrunnerLivio Jul 19, 2019
901eab6
fix(api): Display examples of overloads
BrunnerLivio Jul 22, 2019
969e906
chore(): Get latest changes from master
BrunnerLivio Jul 27, 2019
0fe1c06
fix(api): Link code even if multiple instances
BrunnerLivio Jul 28, 2019
be85245
feat(api): Support pipes processing
BrunnerLivio Jul 28, 2019
54cd606
fix(api): Pipes not showing up in package doc
BrunnerLivio Jul 29, 2019
f3d74b5
fix(api): Wrong parameter rendering
BrunnerLivio Jul 29, 2019
57352b3
feat(api): Add setup-docs.sh
BrunnerLivio Jul 31, 2019
38a1811
fix(api): Add code linking again
BrunnerLivio Jul 31, 2019
1acf579
feat(api): Render code links nicely
BrunnerLivio Jul 31, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dist/*

/tmp
/out-tsc
/src/generated/*

# dependencies
/node_modules
Expand Down
36 changes: 36 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[submodule "sources/nest"]
path = sources/nest
url = https://github.com/BrunnerLivio/nest
branch=feature/api-docs
[submodule "sources/terminus"]
path = sources/terminus
url = https://github.com/nestjs/terminus
branch = feature/api-docs
[submodule "sources/passport"]
path = sources/passport
url = https://github.com/BrunnerLivio/passport.git
branch = feature/api-docs
[submodule "sources/elasticsearch"]
path = sources/elasticsearch
url = https://github.com/BrunnerLivio/elasticsearch.git
branch = feature/api-docs
[submodule "sources/cqrs"]
path = sources/cqrs
url = https://github.com/BrunnerLivio/cqrs.git
branch = feature/api-docs
[submodule "sources/jwt"]
path = sources/jwt
url = https://github.com/BrunnerLivio/jwt.git
branch = feature/api-docs
[submodule "sources/mongoose"]
path = sources/mongoose
url = https://github.com/BrunnerLivio/mongoose.git
branch = feature/api-docs
[submodule "sources/ng-universal"]
path = sources/ng-universal
url = https://github.com/BrunnerLivio/ng-universal.git
branch = feature/api-docs
[submodule "sources/graphql"]
path = sources/graphql
url = https://github.com/BrunnerLivio/graphql.git
branch = feature/api-docs
8 changes: 5 additions & 3 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
"main": "src/main.ts",
"tsConfig": "src/tsconfig.app.json",
"polyfills": "src/polyfills.ts",
"assets": ["src/assets", "src/favicon.ico", "src/_redirects"],
"assets": ["src/assets", "src/favicon.ico", "src/_redirects", "src/generated"],
"styles": ["src/styles.scss"],
"scripts": ["src/assets/js/prism.js"]
"scripts": [
"src/assets/js/prism.js"
]
},
"configurations": {
"production": {
Expand Down Expand Up @@ -68,7 +70,7 @@
"tsConfig": "src/tsconfig.spec.json",
"scripts": ["src/assets/js/prism.js"],
"styles": ["src/styles.scss"],
"assets": ["src/assets", "src/favicon.ico"]
"assets": ["src/assets", "src/favicon.ico", "src/generated",]
}
},
"lint": {
Expand Down
2 changes: 2 additions & 0 deletions bin/setup-docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
git submodule update --init --recursive
for D in sources/*/; do sh -c "cd ${D} && npm i"; done
266 changes: 266 additions & 0 deletions compiler/api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
# API Documentation Compiler

The API compiler is a script which generates HTML documentation directly from the nestjs source code.
The script takes advantage of [Dgeni](https://github.com/angular/dgeni), a documentation framework used by
AngularJS, Angular 2-x and Angular Material.

## <a name='GettingStarted'></a>Getting Started

First you need to clone the `docs.nestjs.com` repository with all its submodules.

```bash

git clone --recurse-submodules -j8 [email protected]:BrunnerLivio/docs.nestjs.com.git -b feature/api-docs
cd docs.nestjs.com
npm i

```

Then you can simply run this command to start the API

```bash

npm run api

```

You can find the compiled assets in the `src/generated` folder.

### <a name='DebugwithVSCode'></a>Debug with VSCode

Debugging the API script can be hard without a development tool, because the `DocCollection`
is not type-secure. Therefore this `.vscode/launch.json` configuration can help massively while
developing

```json
{
"version": "0.2.0",
"configurations": [
{
"name": "Start API compiler",
"type": "node",
"request": "launch",
"args": ["${workspaceRoot}/compiler/api/index.ts"],
"runtimeArgs": ["-r", "ts-node/register"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart",
"env": {
"TS_NODE_PROJECT": "${workspaceRoot}/compiler/tsconfig.json"
}
}
]
}
```

## <a name='TagDefinitions'></a>Tag Definitions

This API documentation tool reads its human-readable information from JSDoc tags.
A useful resource to get started with JSDoc is the devhints.io [JSDoc cheatsheet](https://devhints.io/jsdoc).

> **HINT**
> Some tags which are part of the JSDoc specs are not supported with this generation tool.
> The tool will throw an error in case you use an unsupported tag.
> On the other hand this documentation tool introduces new tags which are not part
> of the JSDoc specs, e.g. `@publicApi`

### Table of contents

* [@publicApi](#publicApi)
* [@description](#description)
* [@param](#param)
* [@see](#see)
* [@usageNotes](#usageNotes)
* [@module](#module)
* [@throws](#throws)
* [@example](#example)
* [@returns](#returns)

### <a name='publicApi'></a>@publicApi

Exposes a document to the public api. If this tag is not set, the `docs.nestjs.com` user interface
will **NOT** display it.


```ts
@publicApi
```

```ts
/**
* @publicApi
*/
class MyClass { }
```

### <a name='description'></a>@description

The `@description` is an optional tag for describing a document.
If tag is given, it will automatically assume it is a description.

```ts
@description [description]
```

#### <a name='Parameters'></a>Parameters

- `description`: The description of the document, written in `Markdown`.

#### <a name='UsageNotes'></a>Usage Notes

Important to note is that, a `description` is always split in **two parts**:
`description` and `shortDescription`. They are separated by the first line break.
The `shortDescription` should be a quick summary about the document. The `description` is
a longer, more in-depth description.

```ts
/**
* This is the short description it can be written in
* multiple lines.
*
* This is the way longer in-depth description.
*/
export const myVariable: string;
```

### <a name='param'></a>@param

The `@param` is used to describe a `parameter` of a `function`.

```ts
@param [parameterName] [description]
```

#### <a name='Parameters-1'></a>Parameters

- `parameterName`: The exact name of the parameter.
- `description`: The description of the the parameter, written in `Markdown`.


```ts
/**
* @param style Sets AnimationStyles for the parent animation.
*/
function animate(style: string)
```

### <a name='see'></a>@see

`@see` generates a chapter which lists additional links.

```ts
@see [description]
```

#### <a name='Parameters-1'></a>Parameters

- `description`: The description of the parameter, written in `Markdown`.

```ts
/**
* @see [Forms Guide](/guide/forms)
* @see [Reactive Forms Guide](/guide/reactive-forms)
* @see [Dynamic Forms Guide](/guide/dynamic-form)
*/
```

### <a name='usageNotes'></a>@usageNotes

`@usageNotes` generates a chapter which gives more information how to use
the documentation.


```ts
@usageNotes [description]
```

#### <a name='Parameters-1'></a>Parameters

- `description`: The usage notes, written in `Markdown`.

```ts
/**
* @usageNotes
* #### Awesome title
* A description
*/
```

### <a name='module'></a>@module

Associates an NestJS `@Injectable` with a `@Module`.

```ts
@module [moduleName]
```

#### <a name='Parameters-1'></a>Parameters

- `moduleName`: The exact name of the Nest module.

```ts
/**
* @module CommonModule
*/
@Injectable()
export class HttpClient { }
```

### <a name='throws'></a>@throws

A possible errors which can be thrown by the `function`.

```ts
@throws {Type} [description]
```

#### <a name='Parameters-1'></a>Parameters

- `type`: The type of the `Error` written inside curly braces
- `description`: When the error is thrown

```ts
/**
* @throws {TimeoutError} Gets thrown in case a health check exceeded the given timeout
*/
```

### <a name='example'></a>@example

Adds a chapter with code examples on how to use the `function`.

```ts
@example [code]
```

#### <a name='Description'></a>Description

- `code` The code written in TypeScript

```ts
/**
* @example
* grpc.checkService('hero_service', 'hero.health.v1')
* @example
* grpc.checkService('hero_service', 'hero.health.v1', { option: true })
*/
```

### <a name='returns'></a>@returns

Describes what will be returned in a `function`

```ts
@returns [description]
```

#### <a name='Parameters-1'></a>Parameters

- `description`: The description of what gets returned written in `Markdown`.

```ts
/**
* @returns A promise to the info about the build
*/
function getBuild: Promise<BuildInfo> { }
```
43 changes: 43 additions & 0 deletions compiler/api/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { resolve } from 'path';

export const DOC_PATH_PREFIX = '/api';
export const PROJECT_ROOT = resolve(__dirname, '../../sources/');
export const OUTPUT_PATH = resolve(__dirname, '../../src/generated/docs/api');

export const PACKAGES_PATH: string[] = [
'./nest/packages/core/index.ts',
// Explicit imports, because the following files are mandatory for
// the public API documentation, but are in some way or another not
// part of the public api
'./nest/packages/core/nest-factory.ts',
'./nest/packages/common/interfaces/nest-application-options.interface.ts',
'./nest/packages/common/interfaces/nest-application.interface.ts',
'./nest/packages/common/interfaces/nest-application-context.interface.ts',
'./nest/packages/common/interfaces/scope-options.interface.ts',
'./nest/packages/common/interfaces/modules/module-metadata.interface.ts',
'./nest/packages/common/interfaces/modules/dynamic-module.interface.ts',
'./nest/packages/common/interfaces/features/can-activate.interface.ts',
'./nest/packages/common/interfaces/features/execution-context.interface.ts',
'./nest/packages/common/interfaces/features/arguments-host.interface.ts',
'./nest/packages/common/interfaces/external/cors-options.interface.ts',
'./nest/packages/platform-express/interfaces/nest-express-application.interface.ts',
'./nest/packages/platform-express/interfaces/serve-static-options.interface.ts',

'./nest/packages/common/index.ts',
'./nest/packages/microservices/index.ts',
'./nest/packages/platform-express/index.ts',
'./nest/packages/platform-fastify/index.ts',
'./nest/packages/platform-socket.io/index.ts',
'./nest/packages/platform-ws/index.ts',
'./nest/packages/testing/index.ts',
'./nest/packages/websockets/index.ts',

'./terminus/lib/index.ts',
'./passport/lib/index.ts',
'./elasticsearch/lib/index.ts',
'./cqrs/src/index.ts',
'./jwt/lib/index.ts',
'./graphql/lib/index.ts',
'./mongoose/lib/index.ts',
'./ng-universal/lib/index.ts',
];
Loading