diff --git a/packages/docusaurus/src/commands/build.ts b/packages/docusaurus/src/commands/build.ts index f410e11aa4b1..d4edea5f8b8a 100644 --- a/packages/docusaurus/src/commands/build.ts +++ b/packages/docusaurus/src/commands/build.ts @@ -29,12 +29,26 @@ import loadConfig from '../server/config'; export default async function build( siteDir: string, cliOptions: Partial = {}, + + // TODO what's the purpose of this arg ? forceTerminate: boolean = true, ): Promise { - async function tryToBuildLocale(locale: string, forceTerm) { + async function tryToBuildLocale({ + locale, + isLastLocale, + }: { + locale: string; + isLastLocale: boolean; + }) { try { - const result = await buildLocale(siteDir, locale, cliOptions, forceTerm); - console.log(chalk.green(`Site successfully built in locale=${locale}`)); + const result = await buildLocale({ + siteDir, + locale, + cliOptions, + forceTerminate, + isLastLocale, + }); + // console.log(chalk.green(`Site successfully built in locale=${locale}`)); return result; } catch (e) { console.error(`error building locale=${locale}`); @@ -46,13 +60,13 @@ export default async function build( locale: cliOptions.locale, }); if (cliOptions.locale) { - return tryToBuildLocale(cliOptions.locale, forceTerminate); + return tryToBuildLocale({locale: cliOptions.locale, isLastLocale: true}); } else { if (i18n.locales.length > 1) { console.log( chalk.yellow( - `\nSite will be built with all these locales: -- ${i18n.locales.join('\n- ')}\n`, + `\nSite will be built for all these locales: +- ${i18n.locales.join('\n- ')}`, ), ); } @@ -67,24 +81,29 @@ export default async function build( const results = await mapAsyncSequencial(orderedLocales, (locale) => { const isLastLocale = i18n.locales.indexOf(locale) === i18n.locales.length - 1; - // TODO check why we need forceTerminate - const forceTerm = isLastLocale && forceTerminate; - return tryToBuildLocale(locale, forceTerm); + return tryToBuildLocale({locale, isLastLocale}); }); return results[0]!; } } -async function buildLocale( - siteDir: string, - locale: string, - cliOptions: Partial = {}, - forceTerminate: boolean = true, -): Promise { +async function buildLocale({ + siteDir, + locale, + cliOptions, + forceTerminate, + isLastLocale, +}: { + siteDir: string; + locale: string; + cliOptions: Partial; + forceTerminate: boolean; + isLastLocale: boolean; +}): Promise { process.env.BABEL_ENV = 'production'; process.env.NODE_ENV = 'production'; console.log( - chalk.blue(`[${locale}] Creating an optimized production build...`), + chalk.blue(`\n[${locale}] Creating an optimized production build...`), ); const props: Props = await load(siteDir, { @@ -208,15 +227,21 @@ async function buildLocale( baseUrl, }); - const relativeDir = path.relative(process.cwd(), outDir); console.log( - `\n${chalk.green('Success!')} Generated static files in ${chalk.cyan( - relativeDir, - )}. Use ${chalk.greenBright( - '`npm run serve`', - )} to test your build locally.\n`, + `${chalk.green(`Success!`)} Generated static files in ${chalk.cyan( + path.relative(process.cwd(), outDir), + )}.`, ); - if (forceTerminate && !cliOptions.bundleAnalyzer) { + + if (isLastLocale) { + console.log( + `\nUse ${chalk.greenBright( + '`npm run serve`', + )} to test your build locally.\n`, + ); + } + + if (forceTerminate && isLastLocale && !cliOptions.bundleAnalyzer) { process.exit(0); }