-
Notifications
You must be signed in to change notification settings - Fork 4
/
buildDocumentation.js
40 lines (34 loc) · 1.01 KB
/
buildDocumentation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import documentation from 'documentation';
import { codeFrameColumns } from '@babel/code-frame';
import buildDocumentationSource from './buildDocumentationSource';
import buildMarkdown from './buildMarkdown';
function buildDocumentation({ title, entry, source, pattern, tag, visitor }) {
const documentationSource = buildDocumentationSource({
entry,
source,
pattern,
tag,
visitor,
});
return documentation
.build([{ source: documentationSource || ' ' }], { shallow: true })
.then(
comments =>
buildMarkdown(comments, {
title: title,
}),
error => {
if (error.loc) {
error.codeFrame = codeFrameColumns(documentationSource, {
start: error.loc,
});
error.message += `\n${error.codeFrame}`;
}
error.message = `"${title}" documentation source${
source ? '' : ` (${entry || pattern})`
} - ${error.message}`;
throw error;
},
);
}
export default buildDocumentation;