1.12.0 • Published 3 months ago

@twittwer/compodoc v1.12.0

Weekly downloads
881
License
MIT
Repository
github
Last release
3 months ago

Compodoc (Nx Plugin)

npm version commitizen friendly styled with prettier

Nx Plugin to generate documentation via Compodoc.
NOTE: The whole generation part is done by @compodoc/compodoc, this is just a wrapper plugin for Nx workspaces.

Getting Started

Add the plugin to your Nx workspace:

npm install --save-dev @twittwer/compodoc

Configure Compodoc for a project:

nx g @twittwer/compodoc:config <project>
# adds a `compodoc` target to the specified project
# ensures `@compodoc/compodoc` as devDependencies

Run nx run <project>:compodoc --serve and go to http://localhost:8080/

Generator

Add Compodoc target to a project:

nx g @twittwer/compodoc:config <project> [options]
OptionDefaultDescription
workspaceDocsfalseWill add a "tsconfig.compodoc.json" to the project that includes the whole workspace. Workspace Docs Recipe

Executor

Generate Compodoc documentation for a project:

# HTML Format
nx run <project>:compodoc
# JSON Format
nx run <project>:compodoc:json

The executor supports several configuration options that are passed to the Compodoc command.
Additional options (used exclusively by the executor) are indicated by an italic written option name.

For more details you may have a look at the original Compodoc documentation or the builder's schema.json

OptionDefaultDescription
tsConfig<projectRoot>/tsconfig.jsonPath to project's tsconfig file.
outputPathdist/compodoc/<projectName>The output path of the generated files.
exportFormathtmlFormat of generated documentation. (html, json - enables Compodoc's minimal mode as well)
workspaceDocsfalseUse readme of workspace root as entry and add the readme files of all project as additional documentation.
name<projectName>Title of the documentation. (workspaceDocs uses workspace name as default - defined in package.json)
includesPath to external markdown files, folder should contain a summary.json. (workspaceDocs will override this)
includesNameName of menu item containing external markdown files. (workspaceDocs uses "Projects" as default)
assetsFolderExternal assets folder to copy in generated documentation folder.
unitTestCoveragePath to unit test coverage in json-summary format.
disableCoveragetrueDo not add the documentation coverage report.
disableSourceCodefalseDo not add source code tab and links to source code.
disableDomTreefalseDo not add dom tree tab.
disableTemplateTabfalseDo not add template tab.
disableStyleTabfalseDo not add style tab.
disableGraphfalseDisable rendering of the dependency graph.
disablePrivatetrueDo not show private in generated documentation.
disableProtectedfalseDo not show protected in generated documentation.
disableInternaltrueDo not show @internal in generated documentation.
disableLifeCycleHookstrueDo not show Angular lifecycle hooks in generated documentation.
disableRoutesGraphfalseDo not add the routes graph.
disableSearchfalseDo not add the search input.
disableDependenciesfalseDo not add the dependencies list.
coverageTest0Threshold for global documentation coverage.
coverageMinimumPerFile0Threshold for documentation coverage of each file.
coverageTestThresholdFailtrueAbort compodoc with an error instead of a warn log, if coverage threshold (global or per file) is not reached (true: error, false: warn).
languageen-USLanguage used for generated documentation.
themegitbookTheme used for generated documentation.
extThemePath to external theme file.
templatesPath to directory of Handlebars templates to override built-in templates.
customLogoPath to custom logo.
customFaviconPath to custom favicon.
hideGeneratorfalseDo not print the Compodoc logo at the bottom of the page.
servefalse (true in watch mode)Serve generated documentation. (automatically enabled in watch mode)
port8080Port for serving of documentation.
watchfalseWatch for source files changes to automatically rebuild documentation.
silenttrue (false in watch/serve mode)Suppress verbose build output.
debugfalseLog resulting executor options & the final Compodoc command with all arguments.

All paths should be relative to workspace root

The target definition can be found in angular.json/workspace.json in the workspace root or project.json in the project directory:

{
  "targets": {
    "compodoc": {
      "executor": "@twittwer/compodoc:compodoc",
      "options": { /* Define your common options here */ },
      "configurations": {
        "<configuration name>": { /* and provide use case specific options via configurations. */ }
      }
    }
  }
}

Recipes

Workspace Docs

Documentation for the whole workspace incl. the README files of all projects (apps/libs) as additional documentation.

  • Create a library for shared/workspace wide tooling (e.g. workspace)
    nx g @nx/workspace:library workspace --unitTestRunner=none
  • Optionally you can delete some unused code (you should keep at least tsconfig.json & README.md).
  • Configure Compodoc for the created project
    nx g @twittwer/compodoc:config workspace --workspaceDocs
  • Generate your docs:
    nx run workspace:compodoc

Watch Mode

Rebuild your documentation on file changes during development.

The watch mode can be activated via argument:

nx run <project>:compodoc --watch # watch mode automatically enables serving
nx run <project>:compodoc:json --watch

or via explicit configuration:

{
  "targets": {
    "compodoc": {
      "executor": "@twittwer/compodoc:compodoc",
      "options": { /* Define your common options here */ },
      "configurations": {
        "serve": { "watch": true }, /* watch mode automatically enables serving */
        "json": { "exportFormat": "json" },
        "json.watch": { "exportFormat": "json", "watch": true }
      }
    }
  }
}

Integration with @nrwl/storybook

At first you have to configure @nrwl/storybook & @twittwer/compodoc for the project.
Wrap storybook & build-storybook targets with a @nx/workspace:run-commands executor:

{
  "targets": {
    "_storybook": { /* @nrwl/storybook */ },
    "_build-storybook": {  /* @nrwl/storybook */ },
    "compodoc": { /* @twittwer/compodoc */ },
    "storybook": {
      "executor": "@nx/workspace:run-commands",
      "options": {
        "commands": [
          "npx nx run <project>:compodoc:json --watch",
          "npx nx run <project>:_storybook"
        ],
        "parallel": true
      },
      "configurations": {
        "build": {
          "commands": [
            "npx nx run <project>:compodoc:json",
            "npx nx run <project>:_build-storybook"
          ],
          "parallel": false
        }
      }
    }
  }
}
{
  "targets": {
    "_storybook": { /* @nrwl/storybook */ },
    "_build-storybook": {  /* @nrwl/storybook */ },
    "compodoc": { /* @twittwer/compodoc */ },
    "storybook": {
      "executor": "@nx/workspace:run-commands",
      "options": {
        "commands": [
          "npx nx run <project>:compodoc:json --watch",
          "npx nx run <project>:_storybook"
        ],
        "parallel": true
      }
    },
    "build-storybook": {
      "executor": "@nx/workspace:run-commands",
      "options": {
        "commands": [
          "npx nx run <project>:compodoc:json",
          "npx nx run <project>:_build-storybook"
        ],
        "parallel": false
      }
    }
  }
}

Configure Storybook Docs in libs/<project>/.storybook/preview.js:

import { setCompodocJson } from '@storybook/addon-docs/angular';
import compodocJson from '../../../dist/compodoc/<project>/documentation.json';

setCompodocJson(compodocJson);

Serve or build it:

# Option 1
nx run <project>:storybook
nx run <project>:storybook:build
# Option 2
nx run <project>:storybook
nx run <project>:build-storybook
1.12.0

3 months ago

1.11.0

3 months ago

1.10.0

10 months ago

1.8.2

2 years ago

1.8.1

2 years ago

1.9.0

1 year ago

1.8.2-1

2 years ago

1.8.0

2 years ago

1.7.0

2 years ago

1.6.6

2 years ago

1.6.5

2 years ago

1.6.4

3 years ago

1.6.3

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.3

3 years ago

1.5.2

3 years ago

1.5.3-beta.1

3 years ago

1.5.2-beta.3

3 years ago

1.5.3-beta.2

3 years ago

1.5.2-beta.2

3 years ago

1.5.2-beta.1

3 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.3.1-alpha.1

4 years ago

1.2.0

4 years ago

1.2.0-beta.1

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.2

4 years ago

1.0.2-beta.4

4 years ago

1.0.2-beta.1

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.1.0

4 years ago

0.0.15

4 years ago

0.0.12

4 years ago

0.0.13

4 years ago

0.0.10

4 years ago

0.0.11

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.7-0

4 years ago

0.0.6-0

4 years ago

0.0.6

4 years ago

0.0.4-0

4 years ago

0.0.4-1

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago