-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f2c125
commit f3b0ae1
Showing
6 changed files
with
79 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { resolve } from 'node:path'; | ||
import { coerce } from 'semver'; | ||
import { DOC_NODE_CHANGELOG_URL, DOC_NODE_VERSION } from './constants.mjs'; | ||
import createGenerator from './generators.mjs'; | ||
import generators from './generators/index.mjs'; | ||
import createLoader from './loader.mjs'; | ||
import createParser from './parser.mjs'; | ||
import createNodeReleases from './releases.mjs'; | ||
|
||
const availableGenerators = Object.keys(generators); | ||
const { loadFiles } = createLoader(); | ||
const { parseApiDocs } = createParser(); | ||
|
||
/** | ||
* Function to generate API documentation programmatically. | ||
* | ||
* @param {Object} options - The options for generating API documentation. | ||
* @param {Array<string>|string} options.input - Input file patterns using glob syntax. | ||
* @param {string} options.output - The relative or absolute output directory. | ||
* @param {string} [options.version=DOC_NODE_VERSION] - The target version of Node.js, semver compliant. | ||
* @param {string} [options.changelog=DOC_NODE_CHANGELOG_URL] - Path to the CHANGELOG.md file. | ||
* @param {Array<string>|string} [options.target=[]] - Processing target modes. | ||
*/ | ||
export async function generateApiDocs({ | ||
input, | ||
output, | ||
version = DOC_NODE_VERSION, | ||
changelog = DOC_NODE_CHANGELOG_URL, | ||
target = [], | ||
}) { | ||
if (!Array.isArray(target)) { | ||
target = [target]; | ||
} | ||
|
||
if (!input) { | ||
throw new Error('options.input is required.'); | ||
} | ||
|
||
// Validate the target generators | ||
const validTargets = target.filter(t => availableGenerators.includes(t)); | ||
|
||
// Load and parse the API documentation files | ||
const apiDocFiles = loadFiles(input); | ||
const parsedApiDocs = await parseApiDocs(apiDocFiles); | ||
|
||
const { runGenerators } = createGenerator(parsedApiDocs); | ||
|
||
// Retrieves Node.js release metadata from a given Node.js version and CHANGELOG.md file | ||
const { getAllMajors } = createNodeReleases(changelog); | ||
|
||
return await runGenerators({ | ||
generators: validTargets, | ||
output: output && resolve(output), | ||
version: coerce(version), | ||
releases: await getAllMajors(), | ||
}); | ||
} |