# Setup Ts Doc and Angular Doc and bundle size analyser

If required from the client we need to be able to generate a documentation for the project.\
To do this we should be able to provide TypeScript and Angular documentation through in code annotations/comments.

### TypeScript documentation

TypeScript documentation should be generated using Typedoc (<http://typedoc.org/>). Just install it as a dev dependency to your project:

```
npm i --save-dev typedoc
```

Add a 'typedoc.js' script under the 'scripts' folder of your project, where you invoke the Typedoc task (you can find more info on the available options here <http://typedoc.org/guides/usage/>):

```
const fs = require('fs');
const typedoc = require('typedoc');

const options = {
  emitDecoratorMetadata: true,
  exclude: '**/+(*.spec.ts)',
  excludePrivate: true,
  experimentalDecorators: true,
  ignoreCompilerErrors: true,
  mode: 'modules',
  module: 'commonjs',
  moduleResolution: 'node',
  out: 'docs/js',
  preserveConstEnums: true,
  stripInternal: true,
  suppressExcessPropertyErrors: true,
  suppressImplicitAnyIndexErrors: true,
  target: 'ES5',
};

const inputDirs = ['./src'];

const typedocApp = new typedoc.Application(options);
const src = typedocApp.expandInputFiles(inputDirs);
const project = typedocApp.convert(src);

console.log('Generating HTML typedocs');
typedocApp.generateDocs(project, options.out);
```

Then add an npm script to 'package.json' to invoke the script above (directly invoking typedoc binary never worked for me):

```
"doc:js": "node scripts/typedoc.js"
```

Documentation is generated according to doc comments as described here <http://typedoc.org/guides/doccomments/>.

## Angular documentation

Angular documentation should be generated using Compodoc (<https://github.com/compodoc/compodoc>). Just install it as a dev dependency to your project:

```
npm i --save-dev @compodoc/compodoc
```

and add an npm script to 'package.json' to invoke it:

```
"doc:angular": "compodoc [--disablePrivate] [--disableInternal] -p tsconfig.json -d docs/angular/"
```

* '--disablePrivate' and '--disableInternal' are optional and are needed to exclude private members/functions.
* '-p' points to the typescrypt configuration files (usually 'tsconfig.json' in the project root dir).
* '-d' points to the directory where docs will be created.

Moreover, you can add another script which will check for documentation coverage and will fail if some thresholds are not met:

```
"doc:angular-cov": "npm run doc:angular -- --coverageTest <min-overall-coverage> --coverageMinimumPerFile <min-coverage-per-file>"
```

Documentation is generated according to doc comments already present for the TypeScript documentation.
