Skip to content

Commit 0e5df0a

Browse files
committed
feat(api): Add package markdown index file processor
1 parent ff8aa70 commit 0e5df0a

File tree

5 files changed

+86
-13
lines changed

5 files changed

+86
-13
lines changed

compiler/api/index.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,21 @@ function typeScriptConfiguration(readTypeScriptModules: any, tsParser: any) {
1616
// API files are typescript
1717
readTypeScriptModules.basePath = PROJECT_ROOT;
1818
readTypeScriptModules.sourceFiles = PACKAGES_PATH;
19+
readTypeScriptModules.hidePrivateMembers = true;
1920
}
2021

21-
function readFilesConfiguration(readFilesProcessor: any) {
22-
readFilesProcessor.$enabled = false;
22+
function readFilesConfiguration(readFilesProcessor: any, packageContentFileReader: any) {
2323
readFilesProcessor.basePath = PROJECT_ROOT;
24+
25+
readFilesProcessor.fileReaders.push(packageContentFileReader);
26+
27+
readFilesProcessor.sourceFiles = [
28+
{
29+
basePath: PROJECT_ROOT,
30+
include: PROJECT_ROOT + '/**/PACKAGE.md',
31+
fileReader: 'packageContentFileReader'
32+
}
33+
];
2434
}
2535

2636
function jsDocConfiguration(

compiler/api/processors/processPackages.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { byId } from '../util/byId';
2+
import { dirname } from 'canonical-path';
23

34
function getPackageName(packageDoc) {
45
const idParts = packageDoc.id.split('/').filter(p => p !== 'lib' && p !== 'src');
@@ -11,6 +12,18 @@ module.exports = function processPackages() {
1112
$runAfter: ['parseTagsProcessor', 'extractDecoratedClasses'],
1213
$runBefore: ['rendering-docs'],
1314
$process(docs: any[]) {
15+
const packageContentFiles = {};
16+
17+
docs = docs.filter(doc => {
18+
if (doc.docType === 'package-content') {
19+
packageContentFiles[dirname(doc.fileInfo.filePath)] = doc;
20+
return false;
21+
} else {
22+
return true;
23+
}
24+
});
25+
26+
1427
docs.forEach((doc, index) => {
1528
if (doc.docType === 'module') {
1629
// Convert the doc type from 'module' to 'package'
@@ -19,7 +32,7 @@ module.exports = function processPackages() {
1932

2033
if (doc.exports) {
2134
const publicExports = doc.exports.filter(doc => !doc.privateExport);
22-
doc.modules = publicExports.filter(doc => doc.docType === 'decorator').sort(byId);
35+
doc.decorators = publicExports.filter(doc => doc.docType === 'decorator').sort(byId);
2336
doc.modules = publicExports.filter(doc => doc.docType === 'nestmodule').sort(byId);
2437
doc.classes = publicExports.filter(doc => doc.docType === 'class').sort(byId);
2538
doc.injectables = publicExports.filter(doc => doc.docType === 'injectable').sort(byId);
@@ -29,6 +42,15 @@ module.exports = function processPackages() {
2942
doc.pipes = publicExports.filter(doc => doc.docType === 'pipe').sort(byId);
3043
doc.types = publicExports.filter(doc => doc.docType === 'type-alias' || doc.docType === 'const').sort(byId);
3144
}
45+
46+
const readmeDoc = packageContentFiles[dirname(doc.fileInfo.filePath)];
47+
if (readmeDoc) {
48+
doc.shortDescription = readmeDoc.shortDescription;
49+
doc.description = readmeDoc.description;
50+
doc.see = readmeDoc.see;
51+
doc.fileInfo = readmeDoc.fileInfo;
52+
}
53+
3254
}
3355
});
3456
}

compiler/api/readers/package-content.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
module.exports = function packageContentFileReader() {
1616
return {
1717
name: 'packageContentFileReader',
18-
defaultPattern: /PACKAGE\.md$/,
19-
getDocs: function(fileInfo) {
20-
21-
// We return a single element array because content files only contain one document
22-
return [{docType: 'package-content', content: fileInfo.content, startingLine: 1}];
23-
}
18+
// defaultPattern: /PACKAGE\.md$/,
19+
getDocs: fileInfo => [
20+
{ docType: 'package-content', content: fileInfo.content, startingLine: 1 }
21+
]
2422
};
25-
};
23+
};
+45-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,46 @@
1-
<h2>{$ doc.name $}</h2>
1+
{% extends 'base.template.html' -%}
22

3-
A package
3+
{% macro listItems(items, title, overridePath) %}
4+
{% set filteredItems = items | filterByPropertyValue('internal', undefined) %}
5+
{% if filteredItems.length %}
6+
<section class="export-list">
7+
<h3>{$ title $}</h3>
8+
<table class="is-full-width list-table">
9+
{% for item in filteredItems %}
10+
<tr>
11+
<td><code><a href="{$ overridePath or item.path $}"{%- if item.deprecated != undefined %} class="deprecated-api-item"{% endif %}>{$ item.name $}</a></code></td>
12+
<td>
13+
{% if item.deprecated !== undefined %}{$ ('**Deprecated:** ' + item.deprecated) | marked $}{% endif %}
14+
{% if item.shortDescription %}{$ item.shortDescription | marked $}{% endif %}
15+
</td>
16+
</tr>
17+
{% endfor %}
18+
</table>
19+
</section>
20+
{% endif %}
21+
{% endmacro %}
22+
23+
{% block header %}
24+
<header class="api-header">
25+
<h1>{$ doc.name $}</h1>
26+
<label class="api-type-label {$ doc.docType $}">{$ doc.docType $}</label>
27+
{% if doc.packageDeprecated or (not doc.isPrimaryPackage and doc.deprecated !== undefined) %}<label class="api-status-label deprecated">deprecated</label>{% endif %}
28+
{% if doc.security !== undefined %}<label class="api-status-label security">security</label>{% endif %}
29+
{% if doc.pipeOptions.pure === 'false' %}<label class="api-status-label impure-pipe">impure</label>{% endif %}
30+
</header>
31+
{% endblock %}
32+
33+
{% block body -%}
34+
{$ doc.shortDescription | marked $}
35+
{% if doc.description %}{$ doc.description | marked $}{% endif %}
36+
37+
{% include "includes/see-also.html" %}
38+
39+
<h2>{% if doc.isPrimaryPackage %}Primary entry{% else %}Entry{% endif %} point exports</h2>
40+
{$ listItems(doc.modules, 'Modules') $}
41+
{$ listItems(doc.classes, 'Classes') $}
42+
{$ listItems(doc.decorators, 'Decorators') $}
43+
{$ listItems(doc.functions, 'Functions') $}
44+
{$ listItems(doc.structures, 'Structures') $}
45+
{$ listItems(doc.types, 'Types') $}
46+
{%- endblock %}

sources/nest

Submodule nest updated 268 files

0 commit comments

Comments
 (0)