Skip to content

Commit

Permalink
fix(v2): fix i18n build logging. (#3941)
Browse files Browse the repository at this point in the history
* better i18n build logging

* better i18n build logging

* better i18n build logging
  • Loading branch information
slorber authored Dec 18, 2020
1 parent ef49c2b commit b133e2d
Showing 1 changed file with 48 additions and 23 deletions.
71 changes: 48 additions & 23 deletions packages/docusaurus/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,26 @@ import loadConfig from '../server/config';
export default async function build(
siteDir: string,
cliOptions: Partial<BuildCLIOptions> = {},

// TODO what's the purpose of this arg ?
forceTerminate: boolean = true,
): Promise<string> {
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}`);
Expand All @@ -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- ')}`,
),
);
}
Expand All @@ -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<BuildCLIOptions> = {},
forceTerminate: boolean = true,
): Promise<string> {
async function buildLocale({
siteDir,
locale,
cliOptions,
forceTerminate,
isLastLocale,
}: {
siteDir: string;
locale: string;
cliOptions: Partial<BuildCLIOptions>;
forceTerminate: boolean;
isLastLocale: boolean;
}): Promise<string> {
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, {
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit b133e2d

Please sign in to comment.