Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(v2): fix i18n build logging. #3941

Merged
merged 3 commits into from
Dec 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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