diff --git a/.eslintrc.cjs b/.eslintrc.cjs index e2a3731f1d0..eb5c3e2318b 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -44,9 +44,6 @@ module.exports = defineConfig({ 'unicorn/number-literal-case': 'off', // incompatible with prettier 'unicorn/prefer-ternary': 'off', // ternaries aren't always better - // TODO @ST-DDT 2023-10-28: The following rule should be turned on when we switch to esm. - 'unicorn/prefer-top-level-await': 'off', - // TODO @Shinigami92 2023-09-23: The following rules currently conflict with our code. // Each rule should be checked whether it should be enabled/configured and the problems fixed, or stay disabled permanently. 'unicorn/better-regex': 'off', diff --git a/scripts/apidoc.ts b/scripts/apidoc.ts index d7c965aeded..42eee5c3fbf 100644 --- a/scripts/apidoc.ts +++ b/scripts/apidoc.ts @@ -3,13 +3,5 @@ import { generate } from './apidoc/generate'; import { initMarkdownRenderer } from './apidoc/markdown'; -async function build(): Promise { - await initMarkdownRenderer(); - await generate(); -} - -build().catch((error) => { - // Workaround until top level await is available - console.error(error); - process.exit(1); -}); +await initMarkdownRenderer(); +await generate(); diff --git a/scripts/diff.ts b/scripts/diff.ts index a420a66c9f8..813154f2401 100644 --- a/scripts/diff.ts +++ b/scripts/diff.ts @@ -14,19 +14,17 @@ if (!source && !existsSync(pathDocsDiffIndexFile)) { ); } -diff(target, source) - .then((delta) => { - if (Object.keys(delta).length === 0) { - console.log('No documentation changes detected'); - return; - } +await diff(target, source).then((delta) => { + if (Object.keys(delta).length === 0) { + console.log('No documentation changes detected'); + return; + } - console.log('Documentation changes detected:'); - for (const [module, methods] of Object.entries(delta)) { - console.log(`- ${module}`); - for (const method of methods) { - console.log(` - ${method}`); - } + console.log('Documentation changes detected:'); + for (const [module, methods] of Object.entries(delta)) { + console.log(`- ${module}`); + for (const method of methods) { + console.log(` - ${method}`); } - }) - .catch(console.error); + } +}); diff --git a/scripts/generate-locales.ts b/scripts/generate-locales.ts index 4f35828ff24..90ea9a34bf9 100644 --- a/scripts/generate-locales.ts +++ b/scripts/generate-locales.ts @@ -369,65 +369,61 @@ async function normalizeLocaleFile(filePath: string, definitionKey: string) { // Start of actual logic -async function main(): Promise { - 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 { - const metadataImport = await import(`file:${pathMetadata}`); - const metadata: MetadataDefinition = metadataImport.default; - const { title } = metadata; - if (!title) { - throw new Error( - `No title property found on ${JSON.stringify(metadata)}` - ); - } - - localeTitle = title; - } catch (error) { - console.error( - `Failed to load ${pathMetadata}. Please make sure the file exists and exports a MetadataDefinition.` - ); - console.error(error); +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 { + const metadataImport = await import(`file:${pathMetadata}`); + const metadata: MetadataDefinition = metadataImport.default; + const { title } = metadata; + if (!title) { + throw new Error(`No title property found on ${JSON.stringify(metadata)}`); } - 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/.ts - await generateLocaleFile(locale); - - // src/locales/**/index.ts - await generateRecursiveModuleIndexes( - pathModules, - locale, - 'LocaleDefinition', - 1 + localeTitle = title; + } catch (error) { + console.error( + `Failed to load ${pathMetadata}. Please make sure the file exists and exports a MetadataDefinition.` ); + console.error(error); } - // src/locale/index.ts + 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/.ts + await generateLocaleFile(locale); + + // src/locales/**/index.ts + await generateRecursiveModuleIndexes( + pathModules, + locale, + 'LocaleDefinition', + 1 + ); +} + +// src/locale/index.ts - let localeIndexContent = ` +let localeIndexContent = ` ${autoGeneratedCommentHeader} ${localeIndexImports} @@ -441,34 +437,27 @@ async function main(): Promise { } as const; `; - localeIndexContent = await formatTypescript(localeIndexContent); - writeFileSync(pathLocaleIndex, localeIndexContent); +localeIndexContent = await formatTypescript(localeIndexContent); +writeFileSync(pathLocaleIndex, localeIndexContent); - // src/locales/index.ts +// src/locales/index.ts - let localesIndexContent = ` +let localesIndexContent = ` ${autoGeneratedCommentHeader} ${localesIndexExports} `; - localesIndexContent = await formatTypescript(localesIndexContent); - writeFileSync(pathLocalesIndex, localesIndexContent); +localesIndexContent = await formatTypescript(localesIndexContent); +writeFileSync(pathLocalesIndex, localesIndexContent); - // docs/guide/localization.md +// docs/guide/localization.md - localizationLocales = await formatMarkdown(localizationLocales); +localizationLocales = await formatMarkdown(localizationLocales); - let localizationContent = readFileSync(pathDocsGuideLocalization, 'utf8'); - localizationContent = localizationContent.replaceAll( - /(^$).*(^$)/gms, - `$1\n\n\n\n${localizationLocales}\n$2` - ); - writeFileSync(pathDocsGuideLocalization, localizationContent); -} - -main().catch((error) => { - // Workaround until top level await is available - console.error(error); - process.exit(1); -}); +let localizationContent = readFileSync(pathDocsGuideLocalization, 'utf8'); +localizationContent = localizationContent.replaceAll( + /(^$).*(^$)/gms, + `$1\n\n\n\n${localizationLocales}\n$2` +); +writeFileSync(pathDocsGuideLocalization, localizationContent); diff --git a/test/scripts/apidoc/signature.debug.ts b/test/scripts/apidoc/signature.debug.ts index 9e99e8c6f93..704b629cda6 100644 --- a/test/scripts/apidoc/signature.debug.ts +++ b/test/scripts/apidoc/signature.debug.ts @@ -8,13 +8,10 @@ import { loadExampleMethods } from './utils'; /* Run with `pnpm tsx test/scripts/apidoc/signature.debug.ts` */ -initMarkdownRenderer() - .then(async () => { - const methods = await loadExampleMethods(); - for (const [name, method] of Object.entries(methods)) { - console.log('Analyzing:', name); - const result = await analyzeSignature(method, '', method.name); - console.log('Result:', result); - } - }) - .catch(console.error); +await initMarkdownRenderer(); +const methods = await loadExampleMethods(); +for (const [name, method] of Object.entries(methods)) { + console.log('Analyzing:', name); + const result = await analyzeSignature(method, '', method.name); + console.log('Result:', result); +}