Skip to content

Commit 0f970de

Browse files
committed
Refactor scripts
1 parent 88c9c12 commit 0f970de

File tree

2 files changed

+43
-93
lines changed

2 files changed

+43
-93
lines changed

scripts/generate-api-docs/index.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,24 @@ async function generateSidebarFile(inputDir, outDir) {
113113
}
114114

115115
async function generateMarkdownFiles(inputDir, outDir) {
116-
return new Promise((resolve, reject) => {
117-
exec(
116+
try {
117+
const { stdout } = await execPromise(
118118
`api-documenter markdown --input-folder ${inputDir} --output-folder ${outDir}`,
119-
(err, stdout) => {
120-
if (err) {
121-
return reject(err);
122-
}
123-
124-
return resolve(stdout);
125-
},
126119
);
120+
return stdout;
121+
} catch (err) {
122+
throw new Error(`Error generating markdown files: ${err.message}`);
123+
}
124+
}
125+
126+
function execPromise(command) {
127+
return new Promise((resolve, reject) => {
128+
exec(command, (err, stdout, stderr) => {
129+
if (err) {
130+
return reject(err);
131+
}
132+
resolve({ stdout, stderr });
133+
});
127134
});
128135
}
129136

scripts/generate-api-docs/sidebar-visitor.js

Lines changed: 27 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,35 @@
11
const { ApiItemKind } = require('@microsoft/api-extractor-model');
22

33
/**
4-
* This is taken from the docusaurus-plugin-api-extractor codebase as specified in the
5-
* [standard-markdown-documenter README](https://github.com/gabrielcsapo/docusaurus-plugin-api-extractor/tree/main/plugin/standard-markdown-documenter#custom-sidebar-visitor).
6-
* @see https://github.com/gabrielcsapo/docusaurus-plugin-api-extractor/tree/main/plugin/standard-markdown-documenter#custom-sidebar-visitor
7-
*
8-
* @dkozma: We had to change this code because the API model parsed an `IndexSignature` from `c2pa.manifestresolvers`
9-
* which gets picked up by the sidebar but a file doesn't get generated. I'm not sure why this is the case or how to
10-
* fix it, so I put a hack in here to just strip the `._indexer_` suffix since standard-markdown-documenter doesn't
11-
* seem to let me return an empty node or node that returns a valid `html` or `link` type.
4+
* @dkozma: We had to change this code because the API model parsed an `IndexSignature` from `c2pa.manifestresolvers` which gets picked up by the sidebar but a file doesn't get generated.
5+
* HACK: Strip the `._indexer_` suffix since standard-markdown-documenter doesn't seem to let
6+
* you return an empty node or node that returns a valid `html` or `link` type.
127
*/
138
exports.SIDEBAR_VISITOR = {
14-
[ApiItemKind.Package](apiItem, meta) {
15-
return containerNode(apiItem, meta);
16-
},
17-
[ApiItemKind.Namespace](apiItem, meta) {
18-
return containerNode(apiItem, meta);
19-
},
20-
[ApiItemKind.Interface](apiItem, meta) {
21-
return containerNode(apiItem, meta);
22-
},
23-
[ApiItemKind.Class](apiItem, meta) {
24-
return containerNode(apiItem, meta);
25-
},
26-
[ApiItemKind.CallSignature](apiItem, meta) {
27-
return terminalNode(apiItem.displayName, meta.id);
28-
},
29-
[ApiItemKind.ConstructSignature](apiItem, meta) {
30-
return terminalNode(apiItem.displayName, meta.id);
31-
},
32-
[ApiItemKind.Constructor](apiItem, meta) {
33-
return terminalNode(apiItem.displayName, meta.id);
34-
},
35-
[ApiItemKind.Enum](apiItem, meta) {
36-
return terminalNode(apiItem.displayName, meta.id);
37-
},
38-
39-
[ApiItemKind.EnumMember](apiItem, meta) {
40-
return terminalNode(apiItem.displayName, meta.id);
41-
},
42-
43-
[ApiItemKind.Function](apiItem, meta) {
44-
return terminalNode(apiItem.displayName, meta.id);
45-
},
46-
47-
[ApiItemKind.IndexSignature](apiItem, meta) {
48-
return terminalNode(
49-
apiItem.displayName,
50-
meta.id.replace(/._indexer_$/, ''),
51-
);
52-
},
53-
54-
[ApiItemKind.Method](apiItem, meta) {
55-
return terminalNode(apiItem.displayName, meta.id);
56-
},
57-
58-
[ApiItemKind.Method](apiItem, meta) {
59-
return terminalNode(apiItem.displayName, meta.id);
60-
},
61-
62-
[ApiItemKind.MethodSignature](apiItem, meta) {
63-
return terminalNode(apiItem.displayName, meta.id);
64-
},
65-
66-
[ApiItemKind.Property](apiItem, meta) {
67-
return terminalNode(apiItem.displayName, meta.id);
68-
},
69-
70-
[ApiItemKind.PropertySignature](apiItem, meta) {
71-
return terminalNode(apiItem.displayName, meta.id);
72-
},
73-
74-
[ApiItemKind.TypeAlias](apiItem, meta) {
75-
return terminalNode(apiItem.displayName, meta.id);
76-
},
77-
78-
[ApiItemKind.Variable](apiItem, meta) {
79-
return terminalNode(apiItem.displayName, meta.id);
80-
},
81-
82-
[ApiItemKind.Model]() {
83-
return {
84-
type: 'category',
85-
label: 'Packages',
86-
items: [terminalNode('Overview', 'index')],
87-
collapsed: false,
88-
};
89-
},
9+
[ApiItemKind.Package]: containerNode,
10+
[ApiItemKind.Namespace]: containerNode,
11+
[ApiItemKind.Interface]: containerNode,
12+
[ApiItemKind.Class]: containerNode,
13+
[ApiItemKind.CallSignature]: terminalNode,
14+
[ApiItemKind.ConstructSignature]: terminalNode,
15+
[ApiItemKind.Constructor]: terminalNode,
16+
[ApiItemKind.Enum]: terminalNode,
17+
[ApiItemKind.EnumMember]: terminalNode,
18+
[ApiItemKind.Function]: terminalNode,
19+
[ApiItemKind.IndexSignature]: (apiItem, meta) =>
20+
terminalNode(apiItem.displayName, meta.id.replace(/._indexer_$/, '')),
21+
[ApiItemKind.Method]: terminalNode,
22+
[ApiItemKind.MethodSignature]: terminalNode,
23+
[ApiItemKind.Property]: terminalNode,
24+
[ApiItemKind.PropertySignature]: terminalNode,
25+
[ApiItemKind.TypeAlias]: terminalNode,
26+
[ApiItemKind.Variable]: terminalNode,
27+
[ApiItemKind.Model]: () => ({
28+
type: 'category',
29+
label: 'Packages',
30+
items: [terminalNode('Overview', 'index')],
31+
collapsed: false,
32+
}),
9033
};
9134

9235
function containerNode(apiItem, meta) {

0 commit comments

Comments
 (0)