Giter Club home page Giter Club logo

ngx-doc-gen's Introduction

Warning

v2.4.0 is the last version as I do not have the time to maintain this lib any longer. If anyone might want to take the maintenance please feel free to reach out to me.

ngx-doc-gen ๐Ÿ“š npm version

Automatically generate your library's API docs using Angular CLI or NX.

Credits

The initial spark was given by the folks from the Angular team (angular/components) who are using a perfectly working base implementation on documentation generation utilizing Dgeni.

Props to those who deserve it ๐Ÿป

Most of the code as well as the templates and styles originate from their repository.

๐Ÿ“• Installation / Configuration

Using NX:

npm install --save-dev ngx-doc gen
nx generate ngx-doc-gen:configure

Using Angular CLI

ng add ngx-doc-gen

Those calls will add a doc-gen target similiar to the build one to all touched library projects.

๐Ÿค– Generation

Using NX:

nx run <project>:doc-gen

Using Angular CLI:

ng doc-gen <project>

While generation is running ngx-doc-gen will scan the given library for its entrypoints - or entrypoint if there is just one - and extract the public API. The heavy lifting is done by Dgeni.

After extraction it categorizes your API in like modules, services, etc. - just like its done when looking at the Angular Material docs - and processes specific templates.

After everything is done ngx-doc-gen will output an HTML file per entrypoint into the output directory (read on for configuration).

๐Ÿ“– Configuration options (configure / ng add)

--projects

  • Type: string[]
  • Defines the libraries which should get configured for documentation generation
  • Will throw an error if a project is listed which does not exist in the workspace
  • Default: []
  • Example:
    • NX: ng generate ngx-doc-gen:configure --projects lib-a,lib-b
    • Angular CLI: ng add ngx-doc-gen --projects lib-a,lib-b
    • Both examples will only configure the given library projects

If not provided or left empty - the default - configure (Generator) and ng add (Angular CLI) will scan your workspace for all buildable library projects and condigures them for documentation generation.

โš™๏ธ Generation options

Per CLI

--log-level

  • Type: 'error' | 'warn' | 'debug' | 'verbose'
  • Defines the log level Dgeni uses while generation
  • Default: 'warn'

--output-path

  • Type: Path
  • Defines the output path for the generated files (relative to working directory)
  • Default: 'docs'

--exclude-base

  • Type: string[]
  • Defines base clases to exclude from generation
  • Default: []
  • Example:
    • Your API contains a service extending Observable which would include members like subscribe() in your documentation. This could be prevented as follows:
    • --exclude-base Observable

--docs-public

  • Type: string
  • Tag to enforce documentation of usually private symbols. Only applies to symbols at least exported.
  • Default: docs-public

--docs-private

  • Type: string,
  • Tag to explicitly hide symbols from documentation.
  • Default: docs-private

--breaking-change

  • Type: string,
  • Tag indicating the version with which a deprecated symbol will get removed.
  • Default: breaking-change

Per workspace config (angular.json / workspace.json / project.json)

Every CLI parameter can also be bound to the doc-gen target in your workspace configuration so you don't have to pass them on every CLI call - see example below.

Some parameters can be passed by configuration only.

customTags

  • Type: TagDefinition[]
  • Configures tag definition for the Dgeni JSDoc processor not supported by JSDoc.
  • Default: []
Property Type Description
name string Name of the tag (excluding the @)
docProperty? string Property where the tag information should be attached to.
multi? boolean Whether multiple instances of the tag can be used in the same comment.
required? boolean Whether this tag is required for all API documents.
// Example given for a project.json
...
"<project>": {
  "targets": {
    "doc-gen": {
      "executor": "ngx-doc-gen:generate",
      "options": {
        "logLevel": "verbose",
        "outputPath": "./docs/libs/<project>",
        "excludeBase": [
          "Observable"
        ],
        "customTags": [
          {
            "name": "example"
          }
        ]
      }
    }
  }
}
...

๐ŸŽจ Styling

As the generated docs are just plain HTML files you apply whatever styling you want. For convinience ngx-doc-gen comes with two SCSS mixins.

core

Applies some general styles for font, spacing, borders, etc. Just include the mixing in your root stylesheet.

@use 'ngx-doc-gen/styles' as ngx-doc-gen;

@include ngx-doc-gen.core();

docs-theme

Applies some Angular Material touch. Just pass your Angular Material theme into the mixin.

@use 'ngx-doc-gen/styles/theming' as ngx-doc-gen;

@include ngx-doc-gen.docs-theme($theme);

ngx-doc-gen's People

Contributors

bohoffi avatar

Stargazers

 avatar

Watchers

 avatar  avatar

ngx-doc-gen's Issues

[BUG] Tag `docs-public`, `docs-private`, `breaking-change` are not recognized correctly

Describe the bug
Using the default configuration for the above mentioned tags throws an error when used.

Expected behavior
Using the default tags (as mentioned above) should work as described in README

Error log

error:   Error running processor "error-unknown-tags":
Found errors for processed JSDoc comments in src/NgxLocalStorageFeatures:

  * Tag "docs-private": Unknown tag.

Versions (please complete the following information):

  • ngx-doc-gen 2.1.0

Configure known tags

There's a limited set of extra tags configured using Dgenis parseTagsProcessor.

If a library contain its own set of tags deviating from the JSDoc standard the documentation generation will fail with the Tag "TAGNAME": Unknown tag. error message.

Generation options should be extended to give the possibility to define a set of known non JSDoc standard tags.

Provide styles

Generating an HTML document containing the public API of a library is only half the work when it looks aweful.

ngx-doc-gen should provide defaults styles (as used by the Angular Material documentation).

ng-add support

ng-add support

Integration into existing projects should be as smooth as possible so providing a way to install and setup in just one step ist the way to go

[BUG] `customTags` ist undefined

Describe the bug
If a project does not define any custom tags the options property does not get initialized:

To Reproduce
Steps to reproduce the behavior:

  1. doc-gen options used
  • default options like:
"doc-gen": {
  "executor": "ngx-doc-gen:generate"
}

Expected behavior
Even with the default set of options a generation should process successfully.

Error log

โŒ An error occurred while generating the documentation:
TypeError: options.customTags is not iterable
at /node_modules/ngx-doc-gen/src/generate/dgeni-engine.js:119:24
    at Injector.invoke (/node_modules/di/lib/injector.js:75:15)
    at /node_modules/dgeni/lib/Dgeni.js:123:116
    at Array.forEach (<anonymous>)
    at /node_modules/dgeni/lib/Dgeni.js:123:68
    at Array.forEach (<anonymous>)
    at Dgeni.configureInjector (/node_modules/dgeni/lib/Dgeni.js:123:22)
    at Dgeni.generate (/node_modules/dgeni/lib/Dgeni.js:159:29)
    at /node_modules/ngx-doc-gen/src/generate/dgeni-engine.js:42:10
    at Generator.next (<anonymous>)

Versions (please complete the following information):

  • ngx-doc-gen: 2.0.0
  • @angular/cli: 15.2.0

Alternative templates + Template Builder

Is your feature request related to a problem? Please describe.
The generator comes with a set of predefined HTML templates. Those may or may not be fitting for anyone.
Adding the possibility to provide your own custom templates would be a nice feature.

Describe the solution you'd like

  • add support for an alternative template directory
  • add a Drag&Drop builder for templates

[BUG] Does not work with secondary entrypoints without a `package.json`

Describe the bug
When scanning for entrypoints there's no chance on grabbing a package.json in secondary entrypoint as they were removed during the migration to Angular v14.

To Reproduce
Steps to reproduce the behavior:

  1. doc-gen options: default
  2. Angular v14 workspace

Expected behavior
Entrypoint scanning should work on Angular versions 10+.

Error log

Error: ENOENT: no such file or directory, open '.../secondary/package.json'
    at Object.openSync (node:fs:585:3)
    at readFileSync (node:fs:453:35)
    at fsReadFile (...\node_modules\ngx-doc-gen\src\utils\file-utils.js:17:40)
    at readFile (...\node_modules\ngx-doc-gen\src\utils\file-utils.js:7:23)
    at parseJson (...\node_modules\ngx-doc-gen\src\utils\json-utils.js:7:51)
    at resolveEntrypoint (...\node_modules\ngx-doc-gen\src\utils\discovery.js:44:52)
    at ...\node_modules\ngx-doc-gen\src\utils\discovery.js:19:34
    at Generator.next (<anonymous>)
    at fulfilled (...\node_modules\tslib\tslib.js:115:62)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  errno: -4058,
  syscall: 'open',
  code: 'ENOENT',
  path: '.../secondary/package.json'
}

Versions (please complete the following information):

  • ngx-doc-gen: 1.0.0-next.2
  • @angular/cli: ^14.2.0
  • @nrwl/...: 14.6.5

Refactor generators; proper ng-add setup

Right now there are 2 generators:

  • init
    • installs ngx-doc-gen as devDependency
  • install
    • configures library projects for documentation generation
      and 1 schematic:
  • ng-add
    • installs ngx-doc-gen as devDependency
    • configures library projects for documentation generation

Which leads to the following tasks:

  • remove the init generator as it literally does nothing
    • ngx-doc-gen has to be installed locally before any generators can be executed
  • rename install generator to configure
    • as the install generator actually alters the libraries configuration instead of installing something
  • add ng-add configuration to package.json

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.