Skip to content

Commit 84f6dac

Browse files
authored
feat(metadata): new meta format (#651)
1 parent c4ad92c commit 84f6dac

60 files changed

Lines changed: 919 additions & 1371 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/generators.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export async function generate(input, worker) {
137137

138138
/**
139139
* Transform metadata entries to MyFormat
140-
* @param {Array<ApiDocMetadataEntry>} entries
140+
* @param {Array<MetadataEntry>} entries
141141
* @param {import('semver').SemVer} version
142142
* @returns {string}
143143
*/

src/__tests__/metadata.test.mjs

Lines changed: 0 additions & 97 deletions
This file was deleted.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import type { MetadataEntry } from '../metadata/types';
2+
13
export type Generator = GeneratorMetadata<
24
{},
3-
Generate<Array<ApiDocMetadataEntry>, Promise<Record<string, string>>>
5+
Generate<Array<MetadataEntry>, Promise<Record<string, string>>>
46
>;

src/generators/ast/constants.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const STABILITY_INDEX_URL = 'documentation.html#stability-index';

src/generators/ast/generate.mjs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ import { extname } from 'node:path';
66
import { globSync } from 'tinyglobby';
77
import { VFile } from 'vfile';
88

9+
import { STABILITY_INDEX_URL } from './constants.mjs';
910
import getConfig from '../../utils/configuration/index.mjs';
10-
import createQueries from '../../utils/queries/index.mjs';
11+
import { QUERIES } from '../../utils/queries/index.mjs';
1112
import { getRemark } from '../../utils/remark.mjs';
1213

13-
const { updateStabilityPrefixToLink } = createQueries();
14-
1514
const remarkProcessor = getRemark();
1615

1716
/**
@@ -26,9 +25,14 @@ export async function processChunk(inputSlice, itemIndices) {
2625
const results = [];
2726

2827
for (const path of filePaths) {
29-
const vfile = new VFile({ path, value: await readFile(path, 'utf-8') });
30-
31-
updateStabilityPrefixToLink(vfile);
28+
const content = await readFile(path, 'utf-8');
29+
const vfile = new VFile({
30+
path,
31+
value: content.replace(
32+
QUERIES.stabilityIndexPrefix,
33+
match => `[${match}](${STABILITY_INDEX_URL})`
34+
),
35+
});
3236

3337
results.push({
3438
tree: remarkProcessor.parse(vfile),

src/generators/json-simple/generate.mjs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { join } from 'node:path';
66
import { remove } from 'unist-util-remove';
77

88
import getConfig from '../../utils/configuration/index.mjs';
9-
import createQueries from '../../utils/queries/index.mjs';
9+
import { UNIST } from '../../utils/queries/index.mjs';
1010

1111
/**
1212
* Generates the simplified JSON version of the API docs
@@ -16,17 +16,14 @@ import createQueries from '../../utils/queries/index.mjs';
1616
export async function generate(input) {
1717
const config = getConfig('json-simple');
1818

19-
// Iterates the input (ApiDocMetadataEntry) and performs a few changes
19+
// Iterates the input (MetadataEntry) and performs a few changes
2020
const mappedInput = input.map(node => {
2121
// Deep clones the content nodes to avoid affecting upstream nodes
2222
const content = JSON.parse(JSON.stringify(node.content));
2323

2424
// Removes numerous nodes from the content that should not be on the "body"
2525
// of the JSON version of the API docs as they are already represented in the metadata
26-
remove(content, [
27-
createQueries.UNIST.isStabilityNode,
28-
createQueries.UNIST.isHeading,
29-
]);
26+
remove(content, [UNIST.isStabilityNode, UNIST.isHeading]);
3027

3128
return { ...node, content };
3229
});
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import type { MetadataEntry } from '../metadata/types';
2+
13
export type Generator = GeneratorMetadata<
24
{},
3-
Generate<Array<ApiDocMetadataEntry>, Promise<Array<ApiDocMetadataEntry>>>
5+
Generate<Array<MetadataEntry>, Promise<Array<MetadataEntry>>>
46
>;

src/generators/jsx-ast/constants.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ export const TAG_TRANSFORMS = {
4343
* API lifecycle change labels
4444
*/
4545
export const LIFECYCLE_LABELS = {
46-
added_in: 'Added in',
47-
deprecated_in: 'Deprecated in',
48-
removed_in: 'Removed in',
46+
added: 'Added in',
47+
deprecated: 'Deprecated in',
48+
removed: 'Removed in',
4949
introduced_in: 'Introduced in',
5050
};
5151

src/generators/jsx-ast/generate.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export async function* generate(input, worker) {
4646
const config = getConfig('jsx-ast');
4747

4848
const groupedModules = groupNodesByModule(input);
49+
4950
const headNodes = getSortedHeadNodes(input);
5051

5152
// Pre-compute docPages once in main thread

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import type { MetadataEntry } from '../metadata/types';
12
import type { JSXContent } from './utils/buildContent.mjs';
23

34
export type Generator = GeneratorMetadata<
45
{},
5-
Generate<Array<ApiDocMetadataEntry>, AsyncGenerator<JSXContent>>,
6+
Generate<Array<MetadataEntry>, AsyncGenerator<JSXContent>>,
67
ProcessChunk<
7-
{ head: ApiDocMetadataEntry; entries: Array<ApiDocMetadataEntry> },
8+
{ head: MetadataEntry; entries: Array<MetadataEntry> },
89
JSXContent,
910
Array<[string, string]>
1011
>

0 commit comments

Comments
 (0)