Skip to content

Commit

Permalink
chore: fixup man-page generator
Browse files Browse the repository at this point in the history
  • Loading branch information
RedYetiDev committed Oct 21, 2024
1 parent 4dbfd05 commit dbac699
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
18 changes: 15 additions & 3 deletions src/generators/man-page/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ import {
convertEnvVarToMandoc,
} from './utils/converter.mjs';

// https://github.com/nodejs/node/blob/main/doc/api/cli.md#options
// This slug should reference the section where the available
// options are defined.
const OPTIONS_SLUG = 'options';

// https://github.com/nodejs/node/blob/main/doc/api/cli.md#environment-variables-1
// This slug should reference the section where the available
// environment variables are defined.
const ENVIRONMENT_SLUG = 'evironment-options-1';

/**
* This generator generates a man page version of the CLI.md file.
* See https://man.openbsd.org/mdoc.7 for the formatting.
Expand All @@ -29,13 +39,15 @@ export default {
// Filter to only 'cli'.
const components = input.filter(({ api }) => api === 'cli');
if (!components.length) {
throw new Error('CLI.md not found');
throw new Error('Could not find any `cli` documentation.');
}

// Find the appropriate headers
const optionsStart = components.findIndex(({ slug }) => slug === 'options');
const optionsStart = components.findIndex(
({ slug }) => slug === OPTIONS_SLUG
);
const environmentStart = components.findIndex(
({ slug }) => slug === 'environment-variables-1'
({ slug }) => slug === ENVIRONMENT_SLUG
);
// The first header that is <3 in depth after environmentStart
const environmentEnd = components.findIndex(
Expand Down
14 changes: 9 additions & 5 deletions src/generators/man-page/template.1
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
.\"
.\" This file is automatically generated by api-docs-tooling.
.\" Do not edit this file directly. Please make changes to CLI.md
.\" and then regenerate this file.
.\" This file was generated automatically by the api-docs-tooling tool.
.\" Please do not edit this file manually. Make any updates to cli.md
.\" and regenerate the file afterward.
.\"
.\" For generation instructions using api-docs-tooling, see:
.\" https://github.com/nodejs/api-docs-tooling
.\" To regenerate this file, use the following command:
.\"
.\" npx https://github.com/nodejs/api-docs-tooling/tarball/main \
.\" -t man-page \
.\" -i doc/api/cli.md \
.\" -t doc/node.1
.\"
.\"======================================================================
.Dd $Mdocdate$
Expand Down

0 comments on commit dbac699

Please sign in to comment.