Skip to content

Commit 8cb94af

Browse files
committed
feat(config): more customization
1 parent 4295b29 commit 8cb94af

28 files changed

+133
-116
lines changed

src/generators/api-links/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ The `api-links` generator creates a mapping of publicly accessible functions to
66

77
The `api-links` generator accepts the following configuration options:
88

9-
| Name | Type | Default | Description |
10-
| -------- | --------- | ----------------------- | --------------------------------------------------- |
11-
| `output` | `string` | - | The directory where `apilinks.json` will be written |
12-
| `minify` | `boolean` | Inherited from `global` | Whether to minify the output JSON |
9+
| Name | Type | Default | Description |
10+
| ----------- | --------- | ------------------------------------ | --------------------------------------------------- |
11+
| `output` | `string` | - | The directory where `apilinks.json` will be written |
12+
| `sourceURL` | `string` | `'${GITHUB_BLOB_URL}lib/{fileName}'` | URL template for linking to source files |
13+
| `minify` | `boolean` | Inherited from `global` | Whether to minify the output JSON |

src/generators/api-links/generate.mjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ import { checkIndirectReferences } from './utils/checkIndirectReferences.mjs';
66
import { extractExports } from './utils/extractExports.mjs';
77
import { findDefinitions } from './utils/findDefinitions.mjs';
88
import getConfig from '../../utils/configuration/index.mjs';
9-
import {
10-
GITHUB_BLOB_URL,
11-
populate,
12-
} from '../../utils/configuration/templates.mjs';
13-
import { writeFile } from '../../utils/file.mjs';
9+
import { populate } from '../../utils/configuration/templates.mjs';
10+
import { withExt, writeFile } from '../../utils/file.mjs';
1411

1512
/**
1613
* Generates the `apilinks.json` file.
@@ -33,16 +30,19 @@ export async function generate(input) {
3330
*/
3431
const nameToLineNumberMap = {};
3532

36-
// `http.js` -> `http`
37-
const baseName = basename(program.path, '.js');
33+
const fileName = basename(program.path);
34+
const baseName = withExt(fileName);
3835

3936
const exports = extractExports(program, baseName, nameToLineNumberMap);
4037

4138
findDefinitions(program, baseName, nameToLineNumberMap, exports);
4239

4340
checkIndirectReferences(program, exports, nameToLineNumberMap);
4441

45-
const fullGitUrl = `${populate(GITHUB_BLOB_URL, config)}lib/${baseName}.js`;
42+
const fullGitUrl = populate(config.sourceURL, {
43+
...config,
44+
fileName,
45+
});
4646

4747
// Add the exports we found in this program to our output
4848
Object.keys(nameToLineNumberMap).forEach(key => {

src/generators/api-links/index.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
import { GITHUB_BLOB_URL } from '../../utils/configuration/templates.mjs';
34
import { createLazyGenerator } from '../../utils/generators.mjs';
45

56
/**
@@ -23,4 +24,8 @@ export default createLazyGenerator({
2324
// Unlike the rest of the generators, this utilizes Javascript sources being
2425
// passed into the input field rather than Markdown.
2526
dependsOn: 'ast-js',
27+
28+
defaultConfiguration: {
29+
sourceURL: `${GITHUB_BLOB_URL}lib/{fileName}`,
30+
},
2631
});

src/generators/api-links/types.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export interface ProgramExports {
55
}
66

77
export type Generator = GeneratorMetadata<
8-
{},
8+
{
9+
sourceURL: string;
10+
},
911
Generate<undefined, Promise<Record<string, string>>>
1012
>;

src/generators/jsx-ast/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ The `jsx-ast` generator converts MDAST (Markdown Abstract Syntax Tree) to JSX AS
66

77
The `jsx-ast` generator accepts the following configuration options:
88

9-
| Name | Type | Default | Description |
10-
| ------- | -------- | -------- | ------------------------------------------------------------------------ |
11-
| `ref` | `string` | `'main'` | Git reference/branch for linking to source files |
12-
| `index` | `array` | - | Array of `{ section, api }` objects defining the documentation structure |
9+
| Name | Type | Default | Description |
10+
| --------- | -------- | --------------------------------------------- | ------------------------------------------------------------------------ |
11+
| `ref` | `string` | `'main'` | Git reference/branch for linking to source files |
12+
| `pageURL` | `string` | `'{baseURL}/latest-{version}/api{path}.html'` | URL template for documentation page links |
13+
| `editURL` | `string` | `'${GITHUB_EDIT_URL}/doc/api{path}.md'` | URL template for "edit this page" links |
14+
| `index` | `array` | - | Array of `{ section, api }` objects defining the documentation structure |

src/generators/jsx-ast/index.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
import { GITHUB_EDIT_URL } from '../../utils/configuration/templates.mjs';
34
import { createLazyGenerator } from '../../utils/generators.mjs';
45

56
/**
@@ -18,6 +19,8 @@ export default createLazyGenerator({
1819

1920
defaultConfiguration: {
2021
ref: 'main',
22+
pageURL: '{baseURL}/latest-{version}/api{path}.html',
23+
editURL: `${GITHUB_EDIT_URL}/doc/api{path}.md`,
2124
},
2225

2326
hasParallelProcessor: true,

src/generators/jsx-ast/types.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import type { MetadataEntry } from '../metadata/types';
22
import type { JSXContent } from './utils/buildContent.mjs';
33

44
export type Generator = GeneratorMetadata<
5-
{},
5+
{
6+
pageURL: string;
7+
editURL: string;
8+
},
69
Generate<Array<MetadataEntry>, AsyncGenerator<JSXContent>>,
710
ProcessChunk<
811
{ head: MetadataEntry; entries: Array<MetadataEntry> },

src/generators/jsx-ast/utils/__tests__/buildBarProps.test.mjs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,22 +128,20 @@ describe('formatVersionOptions', () => {
128128
{ version: new SemVer('18.0.0'), isLts: false, isCurrent: false },
129129
];
130130

131-
const api = 'http';
132-
133-
const result = formatVersionOptions(versions, api);
131+
const result = formatVersionOptions(versions, '/http');
134132

135133
assert.deepStrictEqual(result, [
136134
{
135+
value: 'https://nodejs.org/docs/latest-v16.x/api/http.html',
137136
label: 'v16.x (LTS)',
138-
value: '/api/16.x/http',
139137
},
140138
{
139+
value: 'https://nodejs.org/docs/latest-v17.x/api/http.html',
141140
label: 'v17.x (Current)',
142-
value: '/api/17.x/http',
143141
},
144142
{
143+
value: 'https://nodejs.org/docs/latest-v18.x/api/http.html',
145144
label: 'v18.x',
146-
value: '/api/18.x/http',
147145
},
148146
]);
149147
});

src/generators/jsx-ast/utils/buildBarProps.mjs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@ import readingTime from 'reading-time';
44
import { visit } from 'unist-util-visit';
55

66
import getConfig from '../../../utils/configuration/index.mjs';
7-
import {
8-
GITHUB_EDIT_URL,
9-
populate,
10-
} from '../../../utils/configuration/templates.mjs';
7+
import { populate } from '../../../utils/configuration/templates.mjs';
118
import {
129
getCompatibleVersions,
1310
getVersionFromSemVer,
14-
getVersionURL,
1511
} from '../../../utils/generators.mjs';
1612
import { TOC_MAX_HEADING_DEPTH } from '../constants.mjs';
1713

@@ -93,7 +89,7 @@ export const buildMetaBarProps = (head, entries) => {
9389
['JSON', `${head.basename}.json`],
9490
['MD', `${head.basename}.md`],
9591
],
96-
editThisPage: `${populate(GITHUB_EDIT_URL, config)}${head.path}.md`,
92+
editThisPage: populate(config.editURL, { ...config, path: head.path }),
9793
};
9894
};
9995

@@ -107,10 +103,13 @@ export const formatVersionOptions = (compatibleVersions, path) => {
107103
const config = getConfig('jsx-ast');
108104

109105
return compatibleVersions.map(({ version, isLts, isCurrent }) => {
110-
const parsed = getVersionFromSemVer(version);
111-
const value = getVersionURL(parsed, path, config.baseURL);
106+
let label = `v${getVersionFromSemVer(version)}`;
112107

113-
let label = `v${parsed}`;
108+
const value = populate(config.pageURL, {
109+
...config,
110+
path,
111+
version: label,
112+
});
114113

115114
if (isLts) {
116115
label += ' (LTS)';

src/generators/legacy-html/README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ The `legacy-html` generator creates legacy HTML documentation pages for Node.js
66

77
The `legacy-html` generator accepts the following configuration options:
88

9-
| Name | Type | Default | Description |
10-
| ----------------------- | ---------- | ----------------------- | ------------------------------------------------------------------------ |
11-
| `output` | `string` | - | The directory where HTML files and assets will be written |
12-
| `templatePath` | `string` | `'template.html'` | Path to the HTML template file |
13-
| `additionalPathsToCopy` | `string[]` | `['assets']` | Array of paths to copy to the output directory |
14-
| `ref` | `string` | `'main'` | Git reference/branch for linking to source files |
15-
| `index` | `array` | - | Array of `{ api, section }` objects defining the documentation structure |
16-
| `minify` | `boolean` | Inherited from `global` | Whether to minify the output HTML |
9+
| Name | Type | Default | Description |
10+
| ----------------------- | ---------- | --------------------------------------------- | ------------------------------------------------------------------------ |
11+
| `output` | `string` | - | The directory where HTML files and assets will be written |
12+
| `templatePath` | `string` | `'template.html'` | Path to the HTML template file |
13+
| `additionalPathsToCopy` | `string[]` | `['assets']` | Array of paths to copy to the output directory |
14+
| `ref` | `string` | `'main'` | Git reference/branch for linking to source files |
15+
| `pageURL` | `string` | `'{baseURL}/latest-{version}/api{path}.html'` | URL template for documentation page links |
16+
| `editURL` | `string` | `'${GITHUB_EDIT_URL}/doc/api{path}.md'` | URL template for "edit this page" links |
17+
| `index` | `array` | - | Array of `{ api, section }` objects defining the documentation structure |
18+
| `minify` | `boolean` | Inherited from `global` | Whether to minify the output HTML |

0 commit comments

Comments
 (0)