aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/apidoc/apiDocsWriter.ts22
-rw-r--r--scripts/apidoc/fakerClass.ts18
-rw-r--r--scripts/apidoc/fakerUtilities.ts10
-rw-r--r--scripts/apidoc/format.ts6
-rw-r--r--scripts/apidoc/generate.ts12
-rw-r--r--scripts/apidoc/moduleMethods.ts25
-rw-r--r--scripts/apidoc/signature.ts113
-rw-r--r--scripts/generateLocales.ts151
8 files changed, 201 insertions, 156 deletions
diff --git a/scripts/apidoc/apiDocsWriter.ts b/scripts/apidoc/apiDocsWriter.ts
index 8bb9df5c..fe8f48c5 100644
--- a/scripts/apidoc/apiDocsWriter.ts
+++ b/scripts/apidoc/apiDocsWriter.ts
@@ -40,14 +40,14 @@ editLink: false
* @param deprecated The deprecation message.
* @param methods The methods of the module.
*/
-export function writeApiDocsModule(
+export async function writeApiDocsModule(
moduleName: string,
lowerModuleName: string,
comment: string,
deprecated: string | undefined,
methods: Method[]
-): ModuleSummary {
- writeApiDocsModulePage(
+): Promise<ModuleSummary> {
+ await writeApiDocsModulePage(
moduleName,
lowerModuleName,
comment,
@@ -85,13 +85,13 @@ export function writeApiDocsModule(
* @param comment The module comments.
* @param methods The methods of the module.
*/
-function writeApiDocsModulePage(
+async function writeApiDocsModulePage(
moduleName: string,
lowerModuleName: string,
comment: string,
deprecated: string | undefined,
methods: Method[]
-): void {
+): Promise<void> {
// Write api docs page
let content = `
<script setup>
@@ -131,7 +131,7 @@ function writeApiDocsModulePage(
.join('')}
`.replace(/\n +/g, '\n');
- content = vitePressInFileOptions + formatMarkdown(content);
+ content = vitePressInFileOptions + (await formatMarkdown(content));
writeFileSync(resolve(pathOutputDir, `${lowerModuleName}.md`), content);
}
@@ -164,7 +164,7 @@ function writeApiDocsModuleData(
*
* @param pages The pages to write into the index.
*/
-export function writeApiPagesIndex(pages: Page[]): void {
+export async function writeApiPagesIndex(pages: Page[]): Promise<void> {
// Write api-pages.ts
console.log('Updating api-pages.ts');
pages.splice(0, 0, { text: 'Overview', link: '/api/' });
@@ -174,7 +174,7 @@ export function writeApiPagesIndex(pages: Page[]): void {
export const apiPages = ${JSON.stringify(pages)};
`.replace(/\n +/, '\n');
- apiPagesContent = formatTypescript(apiPagesContent);
+ apiPagesContent = await formatTypescript(apiPagesContent);
writeFileSync(pathDocsApiPages, apiPagesContent);
}
@@ -217,7 +217,9 @@ export function writeApiSearchIndex(pages: ModuleSummary[]): void {
*
* @param project The typedoc project.
*/
-export function writeSourceBaseUrl(project: ProjectReflection): void {
+export async function writeSourceBaseUrl(
+ project: ProjectReflection
+): Promise<void> {
const baseUrl = extractSourceBaseUrl(
project.getChildrenByKind(ReflectionKind.Class)[0]
);
@@ -228,7 +230,7 @@ export function writeSourceBaseUrl(project: ProjectReflection): void {
export const sourceBaseUrl = '${baseUrl}';
`.replace(/\n +/, '\n');
- content = formatTypescript(content);
+ content = await formatTypescript(content);
writeFileSync(resolve(pathOutputDir, 'source-base-url.ts'), content);
}
diff --git a/scripts/apidoc/fakerClass.ts b/scripts/apidoc/fakerClass.ts
index f8de8653..1b322f36 100644
--- a/scripts/apidoc/fakerClass.ts
+++ b/scripts/apidoc/fakerClass.ts
@@ -7,7 +7,9 @@ import { analyzeSignature } from './signature';
import { selectApiSignature } from './typedoc';
import type { ModuleSummary } from './utils';
-export function processFakerClass(project: ProjectReflection): ModuleSummary {
+export async function processFakerClass(
+ project: ProjectReflection
+): Promise<ModuleSummary> {
const fakerClass = project
.getChildrenByKind(ReflectionKind.Class)
.filter((clazz) => clazz.name === 'Faker')[0];
@@ -19,27 +21,31 @@ export function processFakerClass(project: ProjectReflection): ModuleSummary {
return processClass(fakerClass);
}
-function processClass(fakerClass: DeclarationReflection): ModuleSummary {
+async function processClass(
+ fakerClass: DeclarationReflection
+): Promise<ModuleSummary> {
console.log(`Processing Faker class`);
const { comment, deprecated } = analyzeModule(fakerClass);
const methods: Method[] = [];
console.debug(`- constructor`);
- methods.push(processConstructor(fakerClass));
+ methods.push(await processConstructor(fakerClass));
- methods.push(...processModuleMethods(fakerClass, 'faker.'));
+ methods.push(...(await processModuleMethods(fakerClass, 'faker.')));
return writeApiDocsModule('Faker', 'faker', comment, deprecated, methods);
}
-function processConstructor(fakerClass: DeclarationReflection): Method {
+async function processConstructor(
+ fakerClass: DeclarationReflection
+): Promise<Method> {
const constructor = fakerClass.getChildrenByKind(
ReflectionKind.Constructor
)[0];
const signature = selectApiSignature(constructor);
- const method = analyzeSignature(signature, '', 'new Faker');
+ const method = await analyzeSignature(signature, '', 'new Faker');
return {
...method,
diff --git a/scripts/apidoc/fakerUtilities.ts b/scripts/apidoc/fakerUtilities.ts
index f033eadc..59dadeba 100644
--- a/scripts/apidoc/fakerUtilities.ts
+++ b/scripts/apidoc/fakerUtilities.ts
@@ -6,9 +6,9 @@ import { processMethods } from './moduleMethods';
import { selectApiSignature } from './typedoc';
import type { ModuleSummary } from './utils';
-export function processFakerUtilities(
+export async function processFakerUtilities(
project: ProjectReflection
-): ModuleSummary {
+): Promise<ModuleSummary> {
const fakerUtilities = project
.getChildrenByKind(ReflectionKind.Function)
.filter((method) => !method.flags.isPrivate);
@@ -16,13 +16,13 @@ export function processFakerUtilities(
return processUtilities(fakerUtilities);
}
-function processUtilities(
+async function processUtilities(
fakerUtilities: DeclarationReflection[]
-): ModuleSummary {
+): Promise<ModuleSummary> {
console.log(`Processing Faker Utilities`);
const comment = 'A list of all the utilities available in Faker.js.';
- const methods: Method[] = processMethods(
+ const methods: Method[] = await processMethods(
Object.fromEntries(
fakerUtilities.map((method) => [method.name, selectApiSignature(method)])
)
diff --git a/scripts/apidoc/format.ts b/scripts/apidoc/format.ts
index 0a502c5f..a8f63ac0 100644
--- a/scripts/apidoc/format.ts
+++ b/scripts/apidoc/format.ts
@@ -1,13 +1,13 @@
import type { Options } from 'prettier';
import { format } from 'prettier';
-import prettierConfig from '../../.prettierrc.cjs';
+import prettierConfig from '../../.prettierrc.js';
/**
* Formats markdown contents.
*
* @param text The text to format.
*/
-export function formatMarkdown(text: string): string {
+export async function formatMarkdown(text: string): Promise<string> {
return format(text, prettierMarkdown);
}
@@ -16,7 +16,7 @@ export function formatMarkdown(text: string): string {
*
* @param text The text to format.
*/
-export function formatTypescript(text: string): string {
+export async function formatTypescript(text: string): Promise<string> {
return format(text, prettierTypescript);
}
diff --git a/scripts/apidoc/generate.ts b/scripts/apidoc/generate.ts
index 408ab76a..8f45fa6f 100644
--- a/scripts/apidoc/generate.ts
+++ b/scripts/apidoc/generate.ts
@@ -22,16 +22,18 @@ export async function generate(): Promise<void> {
// Useful for manually analyzing the content
await app.generateJson(project, pathOutputJson);
- const pages = [
+ const pages = await Promise.all([
processFakerClass(project),
- ...processModules(project).sort((a, b) => a.text.localeCompare(b.text)),
+ ...(await processModules(project)).sort((a, b) =>
+ a.text.localeCompare(b.text)
+ ),
processFakerUtilities(project),
- ];
- writeApiPagesIndex(pages.map(({ text, link }) => ({ text, link })));
+ ]);
+ await writeApiPagesIndex(pages.map(({ text, link }) => ({ text, link })));
writeApiDiffIndex(
pages.reduce((data, { text, diff }) => ({ ...data, [text]: diff }), {})
);
writeApiSearchIndex(pages);
- writeSourceBaseUrl(project);
+ await writeSourceBaseUrl(project);
}
diff --git a/scripts/apidoc/moduleMethods.ts b/scripts/apidoc/moduleMethods.ts
index 65a62528..359282dc 100644
--- a/scripts/apidoc/moduleMethods.ts
+++ b/scripts/apidoc/moduleMethods.ts
@@ -23,8 +23,10 @@ import { adjustUrls } from './utils';
* @param project The project used to extract the modules.
* @returns The generated pages.
*/
-export function processModules(project: ProjectReflection): ModuleSummary[] {
- return selectApiModules(project).map(processModule);
+export async function processModules(
+ project: ProjectReflection
+): Promise<ModuleSummary[]> {
+ return Promise.all(selectApiModules(project).map(processModule));
}
/**
@@ -33,12 +35,17 @@ export function processModules(project: ProjectReflection): ModuleSummary[] {
* @param module The module to process.
* @returns The generated pages.
*/
-function processModule(module: DeclarationReflection): ModuleSummary {
+async function processModule(
+ module: DeclarationReflection
+): Promise<ModuleSummary> {
const moduleName = extractModuleName(module);
console.log(`Processing Module ${moduleName}`);
const moduleFieldName = extractModuleFieldName(module);
const { comment, deprecated } = analyzeModule(module);
- const methods = processModuleMethods(module, `faker.${moduleFieldName}.`);
+ const methods = await processModuleMethods(
+ module,
+ `faker.${moduleFieldName}.`
+ );
return writeApiDocsModule(
moduleName,
@@ -72,10 +79,10 @@ export function analyzeModule(module: DeclarationReflection): {
* @param accessor The code used to access the methods within the module.
* @returns A list containing the documentation for the api methods in the given module.
*/
-export function processModuleMethods(
+export async function processModuleMethods(
module: DeclarationReflection,
accessor: string
-): Method[] {
+): Promise<Method[]> {
return processMethods(selectApiMethodSignatures(module), accessor);
}
@@ -86,15 +93,15 @@ export function processModuleMethods(
* @param accessor The code used to access the methods.
* @returns A list containing the documentation for the api methods.
*/
-export function processMethods(
+export async function processMethods(
signatures: Record<string, SignatureReflection>,
accessor: string = ''
-): Method[] {
+): Promise<Method[]> {
const methods: Method[] = [];
for (const [methodName, signature] of Object.entries(signatures)) {
console.debug(`- ${methodName}`);
- methods.push(analyzeSignature(signature, accessor, methodName));
+ methods.push(await analyzeSignature(signature, accessor, methodName));
}
return methods;
diff --git a/scripts/apidoc/signature.ts b/scripts/apidoc/signature.ts
index c3be50e5..ea39f51b 100644
--- a/scripts/apidoc/signature.ts
+++ b/scripts/apidoc/signature.ts
@@ -30,11 +30,11 @@ import {
const code = '```';
-export function analyzeSignature(
+export async function analyzeSignature(
signature: SignatureReflection,
accessor: string,
methodName: string
-): Method {
+): Promise<Method> {
const parameters: MethodParameter[] = [];
// Collect Type Parameters
@@ -44,7 +44,7 @@ export function analyzeSignature(
signatureTypeParameters.push(parameter.name);
parameters.push({
name: `<${parameter.name}>`,
- type: parameter.type ? typeToText(parameter.type) : undefined,
+ type: parameter.type ? await typeToText(parameter.type) : undefined,
description: mdToHtml(extractDescription(parameter)),
});
}
@@ -58,7 +58,7 @@ export function analyzeSignature(
) {
const parameter = signature.parameters[index];
- const aParam = analyzeParameter(parameter);
+ const aParam = await analyzeParameter(parameter);
signatureParameters.push(aParam.signature);
parameters.push(...aParam.parameters);
}
@@ -96,17 +96,17 @@ export function analyzeSignature(
since: extractSince(signature),
sourcePath: extractSourcePath(signature),
throws,
- returns: typeToText(signature.type),
+ returns: await typeToText(signature.type),
examples: mdToHtml(`${code}ts\n${examples}${code}`),
deprecated,
seeAlsos,
};
}
-function analyzeParameter(parameter: ParameterReflection): {
+async function analyzeParameter(parameter: ParameterReflection): Promise<{
parameters: MethodParameter[];
signature: string;
-} {
+}> {
const name = parameter.name;
const declarationName = name + (isOptional(parameter) ? '?' : '');
const type = parameter.type;
@@ -118,17 +118,19 @@ function analyzeParameter(parameter: ParameterReflection): {
signatureText = ` = ${defaultValue}`;
}
- const signature = `${declarationName}: ${typeToText(type)}${signatureText}`;
+ const signature = `${declarationName}: ${await typeToText(
+ type
+ )}${signatureText}`;
const parameters: MethodParameter[] = [
{
name: declarationName,
- type: typeToText(type, true),
+ type: await typeToText(type, true),
default: defaultValue,
description: mdToHtml(extractDescription(parameter)),
},
];
- parameters.push(...analyzeParameterOptions(name, type));
+ parameters.push(...(await analyzeParameterOptions(name, type)));
return {
parameters,
@@ -136,10 +138,10 @@ function analyzeParameter(parameter: ParameterReflection): {
};
}
-function analyzeParameterOptions(
+async function analyzeParameterOptions(
name: string,
parameterType?: SomeType
-): MethodParameter[] {
+): Promise<MethodParameter[]> {
if (!parameterType) {
return [];
}
@@ -149,28 +151,30 @@ function analyzeParameterOptions(
return analyzeParameterOptions(`${name}[]`, parameterType.elementType);
case 'union':
- return parameterType.types.flatMap((type) =>
- analyzeParameterOptions(name, type)
- );
+ return Promise.all(
+ parameterType.types.map((type) => analyzeParameterOptions(name, type))
+ ).then((options) => options.flat());
case 'reflection': {
const properties = parameterType.declaration.children ?? [];
- return properties.map((property) => {
- const reflection = property.comment
- ? property
- : (property.type as ReflectionType)?.declaration?.signatures?.[0];
- const comment = reflection?.comment;
- const deprecated = extractDeprecated(reflection);
- return {
- name: `${name}.${property.name}${isOptional(property) ? '?' : ''}`,
- type: declarationTypeToText(property),
- default: extractDefaultFromComment(comment),
- description: mdToHtml(
- toBlock(comment) +
- (deprecated ? `\n\n**DEPRECATED:** ${deprecated}` : '')
- ),
- };
- });
+ return Promise.all(
+ properties.map(async (property) => {
+ const reflection = property.comment
+ ? property
+ : (property.type as ReflectionType)?.declaration?.signatures?.[0];
+ const comment = reflection?.comment;
+ const deprecated = extractDeprecated(reflection);
+ return {
+ name: `${name}.${property.name}${isOptional(property) ? '?' : ''}`,
+ type: await declarationTypeToText(property),
+ default: extractDefaultFromComment(comment),
+ description: mdToHtml(
+ toBlock(comment) +
+ (deprecated ? `\n\n**DEPRECATED:** ${deprecated}` : '')
+ ),
+ };
+ })
+ );
}
case 'typeOperator':
@@ -185,7 +189,7 @@ function isOptional(parameter: Reflection): boolean {
return parameter.flags.hasFlag(ReflectionFlag.Optional);
}
-function typeToText(type_?: Type, short = false): string {
+async function typeToText(type_?: Type, short = false): Promise<string> {
if (!type_) {
return '?';
}
@@ -193,14 +197,13 @@ function typeToText(type_?: Type, short = false): string {
const type = type_ as SomeType;
switch (type.type) {
case 'array': {
- const text = typeToText(type.elementType, short);
+ const text = await typeToText(type.elementType, short);
const isComplexType = text.includes('|') || text.includes('{');
return isComplexType ? `Array<${text}>` : `${text}[]`;
}
case 'union':
- return type.types
- .map((t) => typeToText(t, short))
+ return (await Promise.all(type.types.map((t) => typeToText(t, short))))
.map((t) => (t.includes('=>') ? `(${t})` : t))
.sort()
.join(' | ');
@@ -220,29 +223,29 @@ function typeToText(type_?: Type, short = false): string {
return type.name;
} else if (type.name === 'LiteralUnion') {
return [
- typeToText(type.typeArguments[0], short),
- typeToText(type.typeArguments[1], short),
+ await typeToText(type.typeArguments[0], short),
+ await typeToText(type.typeArguments[1], short),
].join(' | ');
}
return `${type.name}<${type.typeArguments
- .map((t) => typeToText(t, short))
+ .map(async (t) => await typeToText(t, short))
.join(', ')}>`;
case 'reflection':
return declarationTypeToText(type.declaration, short);
case 'indexedAccess':
- return `${typeToText(type.objectType, short)}[${typeToText(
+ return `${await typeToText(type.objectType, short)}[${await typeToText(
type.indexType,
short
)}]`;
case 'literal':
- return formatTypescript(type.toString()).replace(/;\n$/, '');
+ return (await formatTypescript(type.toString())).replace(/;\n$/, '');
case 'typeOperator': {
- const text = typeToText(type.target, short);
+ const text = await typeToText(type.target, short);
if (short && type.operator === 'readonly') {
return text;
}
@@ -255,10 +258,10 @@ function typeToText(type_?: Type, short = false): string {
}
}
-function declarationTypeToText(
+async function declarationTypeToText(
declaration: DeclarationReflection,
short = false
-): string {
+): Promise<string> {
switch (declaration.kind) {
case ReflectionKind.Method:
return signatureTypeToText(declaration.signatures?.[0]);
@@ -273,9 +276,13 @@ function declarationTypeToText(
return '{ ... }';
}
- const list = declaration.children
- .map((c) => ` ${c.name}: ${declarationTypeToText(c)}`)
- .join(',\n');
+ const list = (
+ await Promise.all(
+ declaration.children.map(
+ async (c) => ` ${c.name}: ${await declarationTypeToText(c)}`
+ )
+ )
+ ).join(',\n');
return `{\n${list}\n}`;
} else if (declaration.signatures?.length) {
@@ -289,14 +296,20 @@ function declarationTypeToText(
}
}
-function signatureTypeToText(signature?: SignatureReflection): string {
+async function signatureTypeToText(
+ signature?: SignatureReflection
+): Promise<string> {
if (!signature) {
return '(???) => ?';
}
- return `(${signature.parameters
- ?.map((p) => `${p.name}: ${typeToText(p.type)}`)
- .join(', ')}) => ${typeToText(signature.type)}`;
+ return `(${(
+ await Promise.all(
+ signature.parameters?.map(
+ async (p) => `${p.name}: ${await typeToText(p.type)}`
+ )
+ )
+ ).join(', ')}) => ${await typeToText(signature.type)}`;
}
/**
diff --git a/scripts/generateLocales.ts b/scripts/generateLocales.ts
index b1c4db0e..3c1cb8db 100644
--- a/scripts/generateLocales.ts
+++ b/scripts/generateLocales.ts
@@ -22,7 +22,7 @@ import {
import { resolve } from 'node:path';
import type { Options } from 'prettier';
import { format } from 'prettier';
-import options from '../.prettierrc.cjs';
+import options from '../.prettierrc.js';
import type { LocaleDefinition, MetadataDefinition } from '../src/definitions';
// Constants
@@ -116,7 +116,7 @@ function escapeField(parent: string, module: string): string {
return module;
}
-function generateLocaleFile(locale: string): void {
+async function generateLocaleFile(locale: string): Promise<void> {
const parts = locale.split('_');
const locales = [locale];
@@ -151,16 +151,16 @@ function generateLocaleFile(locale: string): void {
});
`;
- content = format(content, prettierTsOptions);
+ content = await format(content, prettierTsOptions);
writeFileSync(resolve(pathLocale, `${locale}.ts`), content);
}
-function generateLocalesIndexFile(
+async function generateLocalesIndexFile(
path: string,
name: string,
type: string,
depth: number
-): void {
+): Promise<void> {
let modules = readdirSync(path);
modules = removeIndexTs(modules);
modules = removeTsSuffix(modules);
@@ -191,17 +191,17 @@ function generateLocalesIndexFile(
writeFileSync(
resolve(path, 'index.ts'),
- format(content.join('\n'), prettierTsOptions)
+ await format(content.join('\n'), prettierTsOptions)
);
}
-function generateRecursiveModuleIndexes(
+async function generateRecursiveModuleIndexes(
path: string,
name: string,
definition: string,
depth: number
-): void {
- generateLocalesIndexFile(path, name, definition, depth);
+): Promise<void> {
+ await generateLocalesIndexFile(path, name, definition, depth);
let submodules = readdirSync(path);
submodules = removeIndexTs(submodules);
@@ -219,7 +219,7 @@ function generateRecursiveModuleIndexes(
}
// Recursive
- generateRecursiveModuleIndexes(
+ await generateRecursiveModuleIndexes(
pathModule,
submodule,
moduleDefinition,
@@ -266,56 +266,65 @@ function updateLocaleFileHook(
// Start of actual logic
-const locales = readdirSync(pathLocales);
-removeIndexTs(locales);
-
-let localeIndexImports = '';
-let localeIndexExportsIndividual = '';
-let localeIndexExportsGrouped = '';
-let localesIndexExports = '';
-
-let localizationLocales = '| Locale | Name | Faker |\n| :--- | :--- | :--- |\n';
-
-for (const locale of locales) {
- const pathModules = resolve(pathLocales, locale);
- const pathMetadata = resolve(pathModules, 'metadata.ts');
- let localeTitle = 'No title found';
- try {
- // eslint-disable-next-line @typescript-eslint/no-var-requires
- const metadata: MetadataDefinition = require(pathMetadata).default;
- const { title } = metadata;
- if (!title) {
- throw new Error(`No title property found on ${JSON.stringify(metadata)}`);
+async function main(): Promise<void> {
+ const locales = readdirSync(pathLocales);
+ removeIndexTs(locales);
+
+ let localeIndexImports = '';
+ let localeIndexExportsIndividual = '';
+ let localeIndexExportsGrouped = '';
+ let localesIndexExports = '';
+
+ let localizationLocales =
+ '| Locale | Name | Faker |\n| :--- | :--- | :--- |\n';
+
+ for (const locale of locales) {
+ const pathModules = resolve(pathLocales, locale);
+ const pathMetadata = resolve(pathModules, 'metadata.ts');
+ let localeTitle = 'No title found';
+ try {
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
+ const metadata: MetadataDefinition = require(pathMetadata).default;
+ const { title } = metadata;
+ if (!title) {
+ throw new Error(
+ `No title property found on ${JSON.stringify(metadata)}`
+ );
+ }
+
+ localeTitle = title;
+ } catch (e) {
+ console.error(
+ `Failed to load ${pathMetadata}. Please make sure the file exists and exports a MetadataDefinition.`
+ );
+ console.error(e);
}
- localeTitle = title;
- } catch (e) {
- console.error(
- `Failed to load ${pathMetadata}. Please make sure the file exists and exports a MetadataDefinition.`
+ const localizedFaker = `faker${locale.replace(/^([a-z]+)/, (part) =>
+ part.toUpperCase()
+ )}`;
+
+ localeIndexImports += `import { faker as ${localizedFaker} } from './${locale}';\n`;
+ localeIndexExportsIndividual += ` ${localizedFaker},\n`;
+ localeIndexExportsGrouped += ` ${locale}: ${localizedFaker},\n`;
+ localesIndexExports += `export { default as ${locale} } from './${locale}';\n`;
+ localizationLocales += `| \`${locale}\` | ${localeTitle} | \`${localizedFaker}\` |\n`;
+
+ // src/locale/<locale>.ts
+ await generateLocaleFile(locale);
+
+ // src/locales/**/index.ts
+ await generateRecursiveModuleIndexes(
+ pathModules,
+ locale,
+ 'LocaleDefinition',
+ 1
);
- console.error(e);
}
- const localizedFaker = `faker${locale.replace(/^([a-z]+)/, (part) =>
- part.toUpperCase()
- )}`;
-
- localeIndexImports += `import { faker as ${localizedFaker} } from './${locale}';\n`;
- localeIndexExportsIndividual += ` ${localizedFaker},\n`;
- localeIndexExportsGrouped += ` ${locale}: ${localizedFaker},\n`;
- localesIndexExports += `export { default as ${locale} } from './${locale}';\n`;
- localizationLocales += `| \`${locale}\` | ${localeTitle} | \`${localizedFaker}\` |\n`;
-
- // src/locale/<locale>.ts
- generateLocaleFile(locale);
+ // src/locale/index.ts
- // src/locales/**/index.ts
- generateRecursiveModuleIndexes(pathModules, locale, 'LocaleDefinition', 1);
-}
-
-// src/locale/index.ts
-
-let localeIndexContent = `
+ let localeIndexContent = `
${autoGeneratedCommentHeader}
${localeIndexImports}
@@ -329,27 +338,33 @@ let localeIndexContent = `
} as const;
`;
-localeIndexContent = format(localeIndexContent, prettierTsOptions);
-writeFileSync(pathLocaleIndex, localeIndexContent);
+ localeIndexContent = await format(localeIndexContent, prettierTsOptions);
+ writeFileSync(pathLocaleIndex, localeIndexContent);
-// src/locales/index.ts
+ // src/locales/index.ts
-let localesIndexContent = `
+ let localesIndexContent = `
${autoGeneratedCommentHeader}
${localesIndexExports}
`;
-localesIndexContent = format(localesIndexContent, prettierTsOptions);
-writeFileSync(pathLocalesIndex, localesIndexContent);
+ localesIndexContent = await format(localesIndexContent, prettierTsOptions);
+ writeFileSync(pathLocalesIndex, localesIndexContent);
-// docs/guide/localization.md
+ // docs/guide/localization.md
-localizationLocales = format(localizationLocales, prettierMdOptions);
+ localizationLocales = await format(localizationLocales, prettierMdOptions);
-let localizationContent = readFileSync(pathDocsGuideLocalization, 'utf-8');
-localizationContent = localizationContent.replace(
- /(^<!-- LOCALES-AUTO-GENERATED-START -->$).*(^<!-- LOCALES-AUTO-GENERATED-END -->$)/gms,
- `$1\n\n<!-- Run '${scriptCommand}' to update. -->\n\n${localizationLocales}\n$2`
-);
-writeFileSync(pathDocsGuideLocalization, localizationContent);
+ let localizationContent = readFileSync(pathDocsGuideLocalization, 'utf-8');
+ localizationContent = localizationContent.replace(
+ /(^<!-- LOCALES-AUTO-GENERATED-START -->$).*(^<!-- LOCALES-AUTO-GENERATED-END -->$)/gms,
+ `$1\n\n<!-- Run '${scriptCommand}' to update. -->\n\n${localizationLocales}\n$2`
+ );
+ writeFileSync(pathDocsGuideLocalization, localizationContent);
+}
+
+main().catch((e) => {
+ console.error(e);
+ process.exit(1);
+});