Skip to content

Commit

Permalink
chore: fixup man-page generator (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
RedYetiDev authored Oct 21, 2024
1 parent 4dbfd05 commit a504264
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
10 changes: 10 additions & 0 deletions src/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ export const DOC_TYPES_MAPPING_PRIMITIVES = {
undefined: 'Undefined',
};

// https://github.com/nodejs/node/blob/main/doc/api/cli.md#options
// This slug should reference the section where the available
// options are defined.
export const DOC_SLUG_OPTIONS = '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.
export const DOC_SLUG_ENVIRONMENT = 'evironment-options-1';

// This is a mapping for types within the Markdown content and their respective
// JavaScript globals types within the MDN JavaScript docs
// @see DOC_MDN_BASE_URL_JS_GLOBALS
Expand Down
10 changes: 7 additions & 3 deletions src/generators/man-page/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
convertEnvVarToMandoc,
} from './utils/converter.mjs';

import { DOC_SLUG_ENVIRONMENT, DOC_SLUG_OPTIONS } from '../../constants.mjs';

/**
* 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 +31,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 === DOC_SLUG_OPTIONS
);
const environmentStart = components.findIndex(
({ slug }) => slug === 'environment-variables-1'
({ slug }) => slug === DOC_SLUG_ENVIRONMENT
);
// The first header that is <3 in depth after environmentStart
const environmentEnd = components.findIndex(
Expand Down
11 changes: 5 additions & 6 deletions src/generators/man-page/template.1
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
.\"
.\" 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, run `make doc/node.1`.
.\"
.\"======================================================================
.Dd $Mdocdate$
Expand Down Expand Up @@ -71,4 +70,4 @@ Documentation:
.
.Pp
GitHub repository and issue tracker:
.Sy https://github.com/nodejs/node
.Sy https://github.com/nodejs/node

0 comments on commit a504264

Please sign in to comment.