Skip to content

Commit

Permalink
Add API Documenter and generate API documentation for shared libs (#1216
Browse files Browse the repository at this point in the history
)
  • Loading branch information
romainmenke authored Dec 26, 2023
1 parent 4a25af0 commit 1569895
Show file tree
Hide file tree
Showing 607 changed files with 41,525 additions and 227 deletions.
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

0 comments on commit 1569895

Please sign in to comment.