Skip to content

Commit 4433fc9

Browse files
Eric Jimenezkara
authored andcommitted
docs: use typedoc to generate a json file documentation dump of all components (#1887)
1 parent 1d60573 commit 4433fc9

File tree

6 files changed

+66
-3
lines changed

6 files changed

+66
-3
lines changed

GENERATING_API_DOCS.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Generating API Docs with Typedoc
2+
[Typedoc](http://typedoc.org/) is a documentation generator for TypeScript projects.
3+
4+
Refer to `typedoc.json` for build configuration.
5+
6+
1. `npm install`
7+
2. `npm run api`
8+
9+
TypeDoc will leverage the typings file to generate docs. The output will be located in `/dist/api/api.json`.
10+
11+
## FAQ
12+
13+
### How do I stop HTML generation and focus only on JSON?
14+
Currently not possible, submitted a feature request: https://github.com/TypeStrong/typedoc/issues/337
15+
16+
### How do I prevent `Cannot find name` errors?
17+
When typedoc is invoked tsconfig and typings file must be in the path.
18+
19+
### How do we omit constructors or other methods from the components?
20+
You can either ignore them from the output file, or use the `@hidden` tag in the source code to omit a method or
21+
property from being generated as docs. The recommended approach is to ignore them since adding the hidden tag will
22+
create a lot of noise
23+
24+
### Can we detect Inputs and Outputs from Angular components?
25+
Yes, check the decorators key-value on the json file for that particular component.
26+
27+
### Can we generate a json file for a specific component?
28+
Yes, if we were to invoke `./node_modules/.bin/typedoc --options ./src/lib/typedoc.json --ignoreCompilerErrors ./src/lib/button`
29+
We could theoretically generate a json file just for button, but we would ignore compiler errors because button does
30+
not have a tsconfig or typings file local to its implementation.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
"stylelint": "gulp lint",
1616
"e2e": "gulp e2e",
1717
"deploy": "firebase deploy",
18-
"webdriver-manager": "webdriver-manager"
18+
"webdriver-manager": "webdriver-manager",
19+
"docs": "gulp docs",
20+
"api": "gulp api"
1921
},
2022
"version": "2.0.0-alpha.10",
2123
"license": "MIT",
@@ -88,6 +90,7 @@
8890
"symlink-or-copy": "^1.0.1",
8991
"ts-node": "^0.7.3",
9092
"tslint": "^3.13.0",
93+
"typedoc": "^0.5.1",
9194
"typescript": "^2.0.2",
9295
"typings": "^1.3.1",
9396
"which": "^1.2.4"

src/lib/button/button.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ export class MdAnchor extends MdButton {
140140
return this.disabled ? -1 : 0;
141141
}
142142

143-
@HostBinding('attr.aria-disabled')
144143
/** Gets the aria-disabled value for the component, which must be a string for Dart. */
144+
@HostBinding('attr.aria-disabled')
145145
get isAriaDisabled(): string {
146146
return this.disabled ? 'true' : 'false';
147147
}

src/lib/typedoc.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"mode": "modules",
3+
"out": "./dist/api",
4+
"json": "./dist/api/api.json",
5+
"theme": "default",
6+
"experimentalDecorators": "true",
7+
"emitDecoratorMetadata": "true",
8+
"excludePrivate": "true",
9+
"excludeExternals": "true",
10+
"includeDeclarations": "true",
11+
"target": "ES6",
12+
"exclude": "**/+(*.spec.ts|*.scss|*.html)",
13+
"name": "Angular Material",
14+
"moduleResolution": "node",
15+
"preserveConstEnums": "true",
16+
"stripInternal": "true",
17+
"suppressExcessPropertyErrors": "true",
18+
"suppressImplicitAnyIndexErrors": "true",
19+
"module": "commonjs"
20+
}

tools/gulp/gulpfile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ import './tasks/lint';
99
import './tasks/release';
1010
import './tasks/serve';
1111
import './tasks/unit-test';
12+
import './tasks/docs';

tools/gulp/tasks/docs.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
import gulp = require('gulp');
22
const markdown = require('gulp-markdown');
33
const transform = require('gulp-transform');
4+
import {task} from 'gulp';
5+
import * as path from 'path';
46

7+
import {SOURCE_ROOT, PROJECT_ROOT} from '../constants';
8+
import {
9+
execNodeTask
10+
} from '../task_helpers';
11+
12+
const typedocPath = path.relative(PROJECT_ROOT, path.join(SOURCE_ROOT, 'lib/typedoc.json'));
513

614
// Our docs contain comments of the form `<!-- example(...) -->` which serve as placeholders where
715
// example code should be inserted. We replace these comments with divs that have a
816
// `material-docs-example` attribute which can be used to locate the divs and initialize the example
917
// viewer.
1018
const EXAMPLE_PATTERN = /<!--\W*example\(([^)]+)\)\W*-->/g;
1119

12-
1320
gulp.task('docs', () => {
1421
return gulp.src(['src/lib/**/*.md'])
1522
.pipe(markdown())
@@ -18,3 +25,5 @@ gulp.task('docs', () => {
1825
`<div material-docs-example="${name}"></div>`)))
1926
.pipe(gulp.dest('dist/docs'));
2027
});
28+
29+
task('api', execNodeTask('typedoc', ['--options', typedocPath, './src/lib']));

0 commit comments

Comments
 (0)