Skip to content

Commit 1d2f992

Browse files
authored
Merge branch 'next' into person-fr_SN
2 parents 48b2f63 + 26f298c commit 1d2f992

File tree

7 files changed

+61
-36
lines changed

7 files changed

+61
-36
lines changed

docs/.vitepress/api-pages.ts

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,37 @@ export const apiPages = [
44
{ text: 'Overview', link: '/api/' },
55
{ text: 'Faker', link: '/api/faker.html' },
66
{ text: 'SimpleFaker', link: '/api/simpleFaker.html' },
7-
{ text: 'Airline', link: '/api/airline.html' },
8-
{ text: 'Animal', link: '/api/animal.html' },
9-
{ text: 'Color', link: '/api/color.html' },
10-
{ text: 'Commerce', link: '/api/commerce.html' },
11-
{ text: 'Company', link: '/api/company.html' },
12-
{ text: 'Database', link: '/api/database.html' },
13-
{ text: 'Datatype', link: '/api/datatype.html' },
14-
{ text: 'Date', link: '/api/date.html' },
15-
{ text: 'Finance', link: '/api/finance.html' },
16-
{ text: 'Git', link: '/api/git.html' },
17-
{ text: 'Hacker', link: '/api/hacker.html' },
18-
{ text: 'Helpers', link: '/api/helpers.html' },
19-
{ text: 'Image', link: '/api/image.html' },
20-
{ text: 'Internet', link: '/api/internet.html' },
21-
{ text: 'Location', link: '/api/location.html' },
22-
{ text: 'Lorem', link: '/api/lorem.html' },
23-
{ text: 'Music', link: '/api/music.html' },
24-
{ text: 'Number', link: '/api/number.html' },
25-
{ text: 'Person', link: '/api/person.html' },
26-
{ text: 'Phone', link: '/api/phone.html' },
27-
{ text: 'Random', link: '/api/random.html' },
28-
{ text: 'Science', link: '/api/science.html' },
29-
{ text: 'String', link: '/api/string.html' },
30-
{ text: 'System', link: '/api/system.html' },
31-
{ text: 'Vehicle', link: '/api/vehicle.html' },
32-
{ text: 'Word', link: '/api/word.html' },
337
{ text: 'Randomizer', link: '/api/randomizer.html' },
348
{ text: 'Utilities', link: '/api/utils.html' },
9+
{
10+
text: 'Modules',
11+
items: [
12+
{ text: 'Airline', link: '/api/airline.html' },
13+
{ text: 'Animal', link: '/api/animal.html' },
14+
{ text: 'Color', link: '/api/color.html' },
15+
{ text: 'Commerce', link: '/api/commerce.html' },
16+
{ text: 'Company', link: '/api/company.html' },
17+
{ text: 'Database', link: '/api/database.html' },
18+
{ text: 'Datatype', link: '/api/datatype.html' },
19+
{ text: 'Date', link: '/api/date.html' },
20+
{ text: 'Finance', link: '/api/finance.html' },
21+
{ text: 'Git', link: '/api/git.html' },
22+
{ text: 'Hacker', link: '/api/hacker.html' },
23+
{ text: 'Helpers', link: '/api/helpers.html' },
24+
{ text: 'Image', link: '/api/image.html' },
25+
{ text: 'Internet', link: '/api/internet.html' },
26+
{ text: 'Location', link: '/api/location.html' },
27+
{ text: 'Lorem', link: '/api/lorem.html' },
28+
{ text: 'Music', link: '/api/music.html' },
29+
{ text: 'Number', link: '/api/number.html' },
30+
{ text: 'Person', link: '/api/person.html' },
31+
{ text: 'Phone', link: '/api/phone.html' },
32+
{ text: 'Random', link: '/api/random.html' },
33+
{ text: 'Science', link: '/api/science.html' },
34+
{ text: 'String', link: '/api/string.html' },
35+
{ text: 'System', link: '/api/system.html' },
36+
{ text: 'Vehicle', link: '/api/vehicle.html' },
37+
{ text: 'Word', link: '/api/word.html' },
38+
],
39+
},
3540
];

scripts/apidoc/faker-class.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ async function processClass(
5555
comment,
5656
examples,
5757
deprecated,
58-
methods
58+
methods,
59+
''
5960
);
6061
}
6162

scripts/apidoc/faker-utilities.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ async function processUtilities(
3434
comment,
3535
undefined,
3636
undefined,
37-
methods
37+
methods,
38+
''
3839
);
3940
}

scripts/apidoc/generate.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ export async function generate(): Promise<void> {
2424

2525
const pages = [
2626
...(await processFakerClasses(project)),
27+
await processFakerRandomizer(project),
28+
await processFakerUtilities(project),
2729
...(await processModules(project)).sort((a, b) =>
2830
a.text.localeCompare(b.text)
2931
),
30-
await processFakerRandomizer(project),
31-
await processFakerUtilities(project),
3232
];
33-
await writeApiPagesIndex(pages.map(({ text, link }) => ({ text, link })));
33+
await writeApiPagesIndex(
34+
pages.map(({ text, link, category }) => ({ text, link, category }))
35+
);
3436
writeApiDiffIndex(
3537
Object.fromEntries(pages.map(({ text, diff }) => [text, diff]))
3638
);

scripts/apidoc/module-methods.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ async function processModule(
5757
comment,
5858
examples,
5959
deprecated,
60-
methods
60+
methods,
61+
'Modules'
6162
);
6263
}
6364

scripts/apidoc/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Method } from '../../docs/.vitepress/components/api-docs/method';
44

55
// Types
66

7-
export type Page = { text: string; link: string };
7+
export type Page = { text: string; link: string; category: string };
88

99
export type ModuleSummary = Page & {
1010
methods: Method[];

scripts/apidoc/writer.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { writeFileSync } from 'node:fs';
22
import { resolve } from 'node:path';
33
import type { ProjectReflection } from 'typedoc';
44
import { ReflectionKind } from 'typedoc';
5+
import type { DefaultTheme } from 'vitepress';
56
import type { Method } from '../../docs/.vitepress/components/api-docs/method';
67
import type { APIGroup } from '../../docs/api/api-types';
8+
import { groupBy } from '../../src/internal/group-by';
79
import { formatMarkdown, formatTypescript } from './format';
810
import { extractSourceBaseUrl } from './typedoc';
911
import type { DocsApiDiffIndex, ModuleSummary, Page } from './utils';
@@ -40,14 +42,16 @@ editLink: false
4042
* @param examples The example code.
4143
* @param deprecated The deprecation message.
4244
* @param methods The methods of the module.
45+
* @param category The category of the module.
4346
*/
4447
export async function writeApiDocsModule(
4548
moduleName: string,
4649
lowerModuleName: string,
4750
comment: string,
4851
examples: string | undefined,
4952
deprecated: string | undefined,
50-
methods: Method[]
53+
methods: Method[],
54+
category: string
5155
): Promise<ModuleSummary> {
5256
await writeApiDocsModulePage(
5357
moduleName,
@@ -63,6 +67,7 @@ export async function writeApiDocsModule(
6367
text: moduleName,
6468
link: `/api/${lowerModuleName}.html`,
6569
methods,
70+
category,
6671
diff: {
6772
moduleHash: diffHash({
6873
name: moduleName,
@@ -164,13 +169,23 @@ function writeApiDocsModuleData(
164169
* @param pages The pages to write into the index.
165170
*/
166171
export async function writeApiPagesIndex(pages: Page[]): Promise<void> {
172+
const pagesByCategory = groupBy(pages, (page) => page.category);
173+
const pageTree = Object.entries(pagesByCategory).flatMap(
174+
([category, items]): DefaultTheme.SidebarItem[] => {
175+
const cleanedItems = items.map(({ text, link }) => ({ text, link }));
176+
return category
177+
? [{ text: category, items: cleanedItems }]
178+
: cleanedItems;
179+
}
180+
);
181+
167182
// Write api-pages.ts
168183
console.log('Updating api-pages.ts');
169-
pages.splice(0, 0, { text: 'Overview', link: '/api/' });
184+
pageTree.splice(0, 0, { text: 'Overview', link: '/api/' });
170185
let apiPagesContent = `
171186
// This file is automatically generated.
172187
// Run '${scriptCommand}' to update
173-
export const apiPages = ${JSON.stringify(pages)};
188+
export const apiPages = ${JSON.stringify(pageTree)};
174189
`.replace(/\n +/, '\n');
175190

176191
apiPagesContent = await formatTypescript(apiPagesContent);

0 commit comments

Comments
 (0)