Skip to content

Add API Documenter and generate API documentation for shared libs #1216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
80 changes: 39 additions & 41 deletions .github/bin/generate-docs/api-documenter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,53 @@ import { spawn } from 'child_process';
import { platform } from 'process';
import path from 'path';
import fs from 'fs';
import { getFiles } from '../util/get-files.mjs';

import { listWorkspaces } from "../list-workspaces/list-workspaces.mjs";
const packageJSONInfo = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
if (packageJSONInfo.private) {
process.exit(0);
}

const workspaces = await listWorkspaces();
const unscopedName = packageJSONInfo.name.replace(/^@[^/]+\//, '');

for (const workspace of workspaces) {
await runApiDocumenter(workspace);
const docsExist = fs.existsSync(path.join('docs', unscopedName + '.api.json'));
if (!docsExist) {
process.exit(0);
}

async function runApiDocumenter(workspace) {
await new Promise((resolve, reject) => {
if (workspace.private) {
resolve(true);

return;
const docsContents = fs.readFileSync(path.join('docs', unscopedName + '.api.json'), 'utf8');

await new Promise((resolve, reject) => {
const publishCmd = spawn(
'npm',
[
'exec',
'--',
'api-documenter',
'markdown',
'--input-folder',
'docs',
'--output-folder',
'docs',
],
{
stdio: 'inherit',
shell: platform === 'win32'
}
);

const docsExist = fs.existsSync(path.join(workspace.path, 'docs', workspace.unscopedName + '.api.json'));
if (!docsExist) {
resolve(true);

return;
publishCmd.on('close', (code) => {
if (0 !== code) {
reject(new Error(`'api-documenter' exited with code ${code}`));
}

const publishCmd = spawn(
'npm',
[
'exec',
'--',
'api-documenter',
'markdown',
'--input-folder',
path.join(workspace.path, 'docs'),
'--output-folder',
path.join(workspace.path, 'api-reference'),
],
{
stdio: 'inherit',
shell: platform === 'win32'
}
);

publishCmd.on('close', (code) => {
if (0 !== code) {
reject(new Error(`'npm publish' exited with code ${code} for ${packageName}`));
return;
}

resolve(true);
});
fs.writeFileSync(path.join('docs', unscopedName + '.api.json'), docsContents);
resolve();
});
});

for (const file of await getFiles('docs', true)) {
const fileContents = fs.readFileSync(file, 'utf8').toString();
const cleanFileContents = fileContents.replace(/\r\n/g, "\n");
fs.writeFileSync(file, cleanFileContents);
}
4 changes: 4 additions & 0 deletions api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@

"ae-forgotten-export": {
"logLevel": "error"
},

"ae-internal-missing-underscore": {
"logLevel": "none"
}
//
// . . .
Expand Down
1 change: 1 addition & 0 deletions knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
"ignoreDependencies": [
"@babel/core",
"@babel/preset-env",
"@microsoft/api-documenter",
"@stryker-mutator/command-runner",
"tslib"
]
Expand Down
Loading