Skip to content

Commit d9cc0b6

Browse files
authored
Merge branch 'next' into refactor/string/rename-special-to-symbol
2 parents adc3508 + cec7877 commit d9cc0b6

File tree

22 files changed

+82
-157
lines changed

22 files changed

+82
-157
lines changed

scripts/apidoc.ts

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,11 @@
1-
import { resolve } from 'path';
21
import { faker } from '../src';
3-
import {
4-
writeApiPagesIndex,
5-
writeApiSearchIndex,
6-
} from './apidoc/apiDocsWriter';
7-
import { processModuleMethods } from './apidoc/moduleMethods';
2+
import { generate } from './apidoc/generate';
83
import { initMarkdownRenderer } from './apidoc/signature';
9-
import { newTypeDocApp, patchProject } from './apidoc/typedoc';
10-
import type { PageIndex } from './apidoc/utils';
11-
import { pathOutputDir } from './apidoc/utils';
12-
13-
const pathOutputJson = resolve(pathOutputDir, 'typedoc.json');
144

155
async function build(): Promise<void> {
166
await initMarkdownRenderer();
177
faker.setDefaultRefDate(Date.UTC(2023, 0, 1));
18-
19-
const app = newTypeDocApp();
20-
21-
app.bootstrap({
22-
entryPoints: ['src/index.ts'],
23-
pretty: true,
24-
cleanOutputDir: true,
25-
});
26-
27-
const project = app.convert();
28-
29-
if (!project) {
30-
throw new Error('Failed to convert project');
31-
}
32-
33-
// Useful for manually analyzing the content
34-
await app.generateJson(project, pathOutputJson);
35-
36-
patchProject(project);
37-
38-
const modulesPages: PageIndex = [];
39-
modulesPages.push(...processModuleMethods(project));
40-
writeApiPagesIndex(modulesPages);
41-
42-
writeApiSearchIndex(project);
8+
await generate();
439
}
4410

4511
build().catch(console.error);

scripts/apidoc/generate.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { resolve } from 'path';
2+
import { writeApiPagesIndex, writeApiSearchIndex } from './apiDocsWriter';
3+
import { processModuleMethods } from './moduleMethods';
4+
import { loadProject } from './typedoc';
5+
import { pathOutputDir } from './utils';
6+
7+
const pathOutputJson = resolve(pathOutputDir, 'typedoc.json');
8+
9+
/**
10+
* Generates the API documentation.
11+
*/
12+
export async function generate(): Promise<void> {
13+
const [app, project] = loadProject();
14+
15+
// Useful for manually analyzing the content
16+
await app.generateJson(project, pathOutputJson);
17+
18+
const modules = processModuleMethods(project);
19+
writeApiPagesIndex(modules);
20+
21+
writeApiSearchIndex(project);
22+
}

scripts/apidoc/typedoc.ts

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
DeclarationReflection,
55
ProjectReflection,
66
SignatureReflection,
7+
TypeDocOptions,
78
} from 'typedoc';
89
import {
910
Application,
@@ -19,10 +20,38 @@ import {
1920
} from './parameterDefaults';
2021
import { mapByName } from './utils';
2122

23+
/**
24+
* Loads the project using TypeDoc.
25+
*
26+
* @param options The options to use for the project.
27+
* @returns The TypeDoc application and the project reflection.
28+
*/
29+
export function loadProject(
30+
options: Partial<TypeDocOptions> = {
31+
entryPoints: ['src/index.ts'],
32+
pretty: true,
33+
cleanOutputDir: true,
34+
}
35+
): [Application, ProjectReflection] {
36+
const app = newTypeDocApp();
37+
38+
app.bootstrap(options);
39+
40+
const project = app.convert();
41+
42+
if (!project) {
43+
throw new Error('Failed to convert project');
44+
}
45+
46+
patchProjectParameterDefaults(project);
47+
48+
return [app, project];
49+
}
50+
2251
/**
2352
* Creates and configures a new typedoc application.
2453
*/
25-
export function newTypeDocApp(): Application {
54+
function newTypeDocApp(): Application {
2655
const app = new Application();
2756

2857
app.options.addReader(new TSConfigReader());
@@ -37,17 +66,6 @@ export function newTypeDocApp(): Application {
3766
return app;
3867
}
3968

40-
/**
41-
* Apply our patches to the generated typedoc data.
42-
*
43-
* This is moved to a separate method to allow printing/saving the original content before patching it.
44-
*
45-
* @param project The project to patch.
46-
*/
47-
export function patchProject(project: ProjectReflection): void {
48-
patchProjectParameterDefaults(project);
49-
}
50-
5169
/**
5270
* Selects the modules from the project that needs to be documented.
5371
*

scripts/generateLocales.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function tryLoadLocalesMainIndexFile(pathModules: string): LocaleDefinition {
132132
let localeDef: LocaleDefinition;
133133
// This call might fail, if the module setup is broken.
134134
// Unfortunately, we try to fix it with this script
135-
// Thats why have a fallback logic here, we only need the title and separator anyway
135+
// Thats why have a fallback logic here, we only need the title anyway
136136
try {
137137
// eslint-disable-next-line @typescript-eslint/no-var-requires
138138
localeDef = require(pathModules).default;
@@ -147,7 +147,6 @@ function tryLoadLocalesMainIndexFile(pathModules: string): LocaleDefinition {
147147
);
148148
localeDef = {
149149
title: localeIndex.match(/title: '(.*)',/)[1],
150-
separator: localeIndex.match(/separator: '(.*)',/)?.[1],
151150
};
152151
} catch {
153152
console.error(`Failed to load ${pathModules} or manually parse it.`, e);
@@ -287,7 +286,6 @@ for (const locale of locales) {
287286
const localeDef = tryLoadLocalesMainIndexFile(pathModules);
288287
// We use a fallback here to at least generate a working file.
289288
const localeTitle = localeDef?.title ?? `TODO: Insert Title for ${locale}`;
290-
const localeSeparator = localeDef?.separator;
291289

292290
localeIndexImports += `import ${locale} from './${locale}';\n`;
293291
localeIndexType += ` | '${locale}'\n`;
@@ -298,14 +296,12 @@ for (const locale of locales) {
298296
generateLocaleFile(locale);
299297

300298
// src/locales/**/index.ts
301-
const separator = localeSeparator ? `\nseparator: '${localeSeparator}',` : '';
302-
303299
generateRecursiveModuleIndexes(
304300
pathModules,
305301
locale,
306302
'LocaleDefinition',
307303
1,
308-
`title: '${localeTitle}',${separator}`
304+
`title: '${localeTitle}',`
309305
);
310306
}
311307

src/definitions/definitions.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,4 @@ export type LocaleDefinition = {
5656
* The name of the language.
5757
*/
5858
title: string;
59-
separator?: string;
6059
} & LocaleEntry<Definitions>;

src/faker.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ export interface FakerOptions {
4242
localeFallback?: UsableLocale;
4343
}
4444

45-
const metadataKeys: ReadonlyArray<keyof LocaleDefinition> = [
46-
'title',
47-
'separator',
48-
];
45+
const metadataKeys: ReadonlyArray<keyof LocaleDefinition> = ['title'];
4946

5047
export class Faker {
5148
locales: UsedLocales;

src/locales/ar/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import vehicle from './vehicle';
1515

1616
const ar: LocaleDefinition = {
1717
title: 'Arabic',
18-
separator: ' & ',
1918
cell_phone,
2019
color,
2120
commerce,

src/locales/az/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import phone_number from './phone_number';
1414

1515
const az: LocaleDefinition = {
1616
title: 'Azerbaijani',
17-
separator: ' və ',
1817
color,
1918
commerce,
2019
company,

src/locales/el/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import team from './team';
2020

2121
const el: LocaleDefinition = {
2222
title: 'Greek',
23-
separator: ' & ',
2423
app,
2524
business,
2625
cell_phone,

src/locales/en/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import word from './word';
2828

2929
const en: LocaleDefinition = {
3030
title: 'English',
31-
separator: ' & ',
3231
animal,
3332
app,
3433
business,

src/locales/es_MX/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import team from './team';
1616

1717
const es_MX: LocaleDefinition = {
1818
title: 'Spanish (Mexico)',
19-
separator: ' & ',
2019
cell_phone,
2120
color,
2221
commerce,

src/locales/ge/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import phone_number from './phone_number';
1212

1313
const ge: LocaleDefinition = {
1414
title: 'Georgian',
15-
separator: ' და ',
1615
cell_phone,
1716
company,
1817
internet,

src/locales/he/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import phone_number from './phone_number';
1515

1616
const he: LocaleDefinition = {
1717
title: 'Hebrew',
18-
separator: 'ו ',
1918
cell_phone,
2019
color,
2120
commerce,

src/locales/hy/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import phone_number from './phone_number';
1313

1414
const hy: LocaleDefinition = {
1515
title: 'Armenian',
16-
separator: ' և ',
1716
color,
1817
date,
1918
internet,

src/locales/lv/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import phone_number from './phone_number';
1616

1717
const lv: LocaleDefinition = {
1818
title: 'Latvian',
19-
separator: ' un ',
2019
cell_phone,
2120
color,
2221
commerce,

src/locales/mk/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import phone_number from './phone_number';
1313

1414
const mk: LocaleDefinition = {
1515
title: 'Macedonian',
16-
separator: ' и ',
1716
cell_phone,
1817
company,
1918
date,

src/locales/ru/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import phone_number from './phone_number';
1616

1717
const ru: LocaleDefinition = {
1818
title: 'Russian',
19-
separator: ' и ',
2019
color,
2120
commerce,
2221
company,

src/locales/ur/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import vehicle from './vehicle';
2020

2121
const ur: LocaleDefinition = {
2222
title: 'Urdu',
23-
separator: ' اور ',
2423
animal,
2524
app,
2625
business,

src/modules/internet/user-agent.ts

Lines changed: 19 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,6 @@ type Browser = 'chrome' | 'iexplorer' | 'firefox' | 'safari' | 'opera';
5454
* @param faker An existing faker instance.
5555
*/
5656
export function generate(faker: Faker): string {
57-
const weightedKeyFromObject = <T extends Record<string, number>>(
58-
obj: T
59-
): keyof T => {
60-
//returns a random key from the passed object; keys are weighted by the decimal probability in their value
61-
const rand = faker.number.int(100) / 100;
62-
let min = 0;
63-
let max = 0;
64-
let return_val: string;
65-
66-
for (const key in obj) {
67-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
68-
max = obj[key] + min;
69-
return_val = key;
70-
if (rand >= min && rand <= max) {
71-
break;
72-
}
73-
74-
min = min + obj[key];
75-
}
76-
}
77-
78-
return return_val;
79-
};
80-
8157
const randomLang = (): string =>
8258
faker.helpers.arrayElement([
8359
'AB',
@@ -179,39 +155,29 @@ export function generate(faker: Faker): string {
179155
]);
180156

181157
const randomBrowserAndOS = (): [Browser, OS] => {
182-
const browser: Browser = weightedKeyFromObject({
183-
chrome: 0.45132810566,
184-
iexplorer: 0.27477061836,
185-
firefox: 0.19384170608,
186-
safari: 0.06186781118,
187-
opera: 0.01574236955,
188-
});
189-
const os: OS = weightedKeyFromObject(
190-
{
191-
chrome: { win: 0.89, mac: 0.09, lin: 0.02 },
192-
firefox: { win: 0.83, mac: 0.16, lin: 0.01 },
193-
opera: { win: 0.91, mac: 0.03, lin: 0.06 },
194-
safari: { win: 0.04, mac: 0.96 },
195-
iexplorer: { win: 1 },
196-
}[browser]
197-
);
158+
const browserToOsMap = {
159+
chrome: ['win', 'mac', 'lin'],
160+
firefox: ['win', 'mac', 'lin'],
161+
opera: ['win', 'mac', 'lin'],
162+
safari: ['win', 'mac'],
163+
iexplorer: ['win'],
164+
} satisfies Record<Browser, OS[]>;
165+
const browser: Browser = faker.helpers.objectKey(browserToOsMap);
166+
const os: OS = faker.helpers.arrayElement(browserToOsMap[browser]);
198167

199168
return [browser, os];
200169
};
201170

202-
const randomProc = (arch: OS): string => {
203-
const procs = {
204-
lin: ['i686', 'x86_64'],
205-
mac: { Intel: 0.48, PPC: 0.01, 'U; Intel': 0.48, 'U; PPC': 0.01 },
206-
win: ['', 'WOW64', 'Win64; x64'],
207-
};
208-
const archValue = procs[arch];
209-
const proc = Array.isArray(archValue)
210-
? faker.helpers.arrayElement(archValue)
211-
: weightedKeyFromObject(archValue);
212-
213-
return proc;
214-
};
171+
const randomProc = (arch: OS): string =>
172+
faker.helpers.arrayElement(
173+
(
174+
{
175+
lin: ['i686', 'x86_64'],
176+
mac: ['Intel', 'PPC', 'U; Intel', 'U; PPC'],
177+
win: ['', 'WOW64', 'Win64; x64'],
178+
} satisfies Record<OS, string[]>
179+
)[arch]
180+
);
215181

216182
const randomRevision = (dots: number): string => {
217183
let return_val = '';

0 commit comments

Comments
 (0)