diff --git a/packages/docusaurus/bin/docusaurus.mjs b/packages/docusaurus/bin/docusaurus.mjs index 6f03172bad9d..0344eea45b13 100755 --- a/packages/docusaurus/bin/docusaurus.mjs +++ b/packages/docusaurus/bin/docusaurus.mjs @@ -54,14 +54,8 @@ cli '--no-minify', 'build website without minimizing JS bundles (default: false)', ) - .action(async (siteDir, {bundleAnalyzer, config, outDir, locale, minify}) => { - build(await resolveDir(siteDir), { - bundleAnalyzer, - outDir, - config, - locale, - minify, - }); + .action(async (siteDir, options) => { + build(await resolveDir(siteDir), options); }); cli @@ -86,9 +80,9 @@ cli 'copy TypeScript theme files when possible (default: false)', ) .option('--danger', 'enable swizzle for unsafe component of themes') - .action(async (themeName, componentName, siteDir, options) => { - swizzle(await resolveDir(siteDir), themeName, componentName, options); - }); + .action(async (themeName, componentName, siteDir, options) => + swizzle(await resolveDir(siteDir), themeName, componentName, options), + ); cli .command('deploy [siteDir]') @@ -109,13 +103,9 @@ cli '--skip-build', 'skip building website before deploy it (default: false)', ) - .action(async (siteDir, {outDir, skipBuild, config}) => { - deploy(await resolveDir(siteDir), { - outDir, - config, - skipBuild, - }); - }); + .action(async (siteDir, options) => + deploy(await resolveDir(siteDir), options), + ); cli .command('start [siteDir]') @@ -136,18 +126,8 @@ cli '--poll [interval]', 'use polling rather than watching for reload (default: false). Can specify a poll interval in milliseconds', ) - .action( - async (siteDir, {port, host, locale, config, hotOnly, open, poll}) => { - start(await resolveDir(siteDir), { - port, - host, - locale, - config, - hotOnly, - open, - poll, - }); - }, + .action(async (siteDir, options) => + start(await resolveDir(siteDir), options), ); cli @@ -164,33 +144,14 @@ cli .option('-p, --port ', 'use specified port (default: 3000)') .option('--build', 'build website before serving (default: false)') .option('-h, --host ', 'use specified host (default: localhost)') - .action( - async ( - siteDir, - { - dir = 'build', - port = 3000, - host = 'localhost', - build: buildSite = false, - config, - }, - ) => { - serve(await resolveDir(siteDir), { - dir, - port, - build: buildSite, - config, - host, - }); - }, + .action(async (siteDir, options) => + serve(await resolveDir(siteDir), options), ); cli .command('clear [siteDir]') .description('Remove build artifacts.') - .action(async (siteDir) => { - clear(await resolveDir(siteDir)); - }); + .action(async (siteDir) => clear(await resolveDir(siteDir))); cli .command('write-translations [siteDir]') @@ -211,18 +172,8 @@ cli '--messagePrefix ', 'allows to init new written messages with a given prefix. This might help you to highlight untranslated message to make them stand out in the UI', ) - .action( - async ( - siteDir, - {locale = undefined, override = false, messagePrefix = '', config}, - ) => { - writeTranslations(await resolveDir(siteDir), { - locale, - override, - config, - messagePrefix, - }); - }, + .action(async (siteDir, options) => + writeTranslations(await resolveDir(siteDir), options), ); cli diff --git a/packages/docusaurus/src/commands/build.ts b/packages/docusaurus/src/commands/build.ts index 8c211c225fba..69a35f758bb3 100644 --- a/packages/docusaurus/src/commands/build.ts +++ b/packages/docusaurus/src/commands/build.ts @@ -31,7 +31,7 @@ import type {HelmetServerState} from 'react-helmet-async'; export async function build( siteDir: string, - cliOptions: Partial = {}, + cliOptions: Partial, // When running build, we force terminate the process to prevent async // operations from never returning. However, if run as part of docusaurus // deploy, we have to let deploy finish. diff --git a/packages/docusaurus/src/commands/clear.ts b/packages/docusaurus/src/commands/clear.ts index 600ab0703472..450b2f9e8751 100644 --- a/packages/docusaurus/src/commands/clear.ts +++ b/packages/docusaurus/src/commands/clear.ts @@ -26,7 +26,7 @@ async function removePath(entry: {path: string; description: string}) { } } -export async function clear(siteDir: string): Promise { +export async function clear(siteDir: string): Promise { const generatedFolder = { path: path.join(siteDir, GENERATED_FILES_DIR_NAME), description: 'generated folder', @@ -40,7 +40,7 @@ export async function clear(siteDir: string): Promise { path: path.join(siteDir, p, '.cache'), description: 'Webpack persistent cache folder', })); - return Promise.all( + await Promise.all( [generatedFolder, buildFolder, ...cacheFolders].map(removePath), ); } diff --git a/packages/docusaurus/src/commands/deploy.ts b/packages/docusaurus/src/commands/deploy.ts index 2382c696a889..2e0fbb504767 100644 --- a/packages/docusaurus/src/commands/deploy.ts +++ b/packages/docusaurus/src/commands/deploy.ts @@ -36,7 +36,7 @@ function shellExecLog(cmd: string) { export async function deploy( siteDir: string, - cliOptions: Partial = {}, + cliOptions: Partial, ): Promise { const {outDir, siteConfig, siteConfigPath} = await loadContext({ siteDir, diff --git a/packages/docusaurus/src/commands/serve.ts b/packages/docusaurus/src/commands/serve.ts index c1ef7e9e6e00..35ba82fd5a01 100644 --- a/packages/docusaurus/src/commands/serve.ts +++ b/packages/docusaurus/src/commands/serve.ts @@ -12,13 +12,15 @@ import path from 'path'; import {loadSiteConfig} from '../server/config'; import {build} from './build'; import {getCLIOptionHost, getCLIOptionPort} from './commandUtils'; +import {DEFAULT_BUILD_DIR_NAME} from '@docusaurus/utils'; import type {ServeCLIOptions} from '@docusaurus/types'; export async function serve( siteDir: string, - cliOptions: ServeCLIOptions, + cliOptions: Partial, ): Promise { - let dir = path.resolve(siteDir, cliOptions.dir); + const buildDir = cliOptions.dir ?? DEFAULT_BUILD_DIR_NAME; + let dir = path.resolve(siteDir, buildDir); if (cliOptions.build) { dir = await build( @@ -69,7 +71,7 @@ export async function serve( }); }); - logger.success`Serving path=${cliOptions.dir} directory at url=${ + logger.success`Serving path=${buildDir} directory at url=${ servingUrl + baseUrl }.`; server.listen(port); diff --git a/packages/docusaurus/src/commands/writeHeadingIds.ts b/packages/docusaurus/src/commands/writeHeadingIds.ts index 83481a8f0708..fe15c0b1f3ef 100644 --- a/packages/docusaurus/src/commands/writeHeadingIds.ts +++ b/packages/docusaurus/src/commands/writeHeadingIds.ts @@ -42,8 +42,8 @@ async function getPathsToWatch(siteDir: string): Promise { export async function writeHeadingIds( siteDir: string, - files?: string[], - options?: WriteHeadingIDOptions, + files: string[], + options: WriteHeadingIDOptions, ): Promise { const markdownFiles = await safeGlobby( files ?? (await getPathsToWatch(siteDir)), diff --git a/packages/docusaurus/src/commands/writeTranslations.ts b/packages/docusaurus/src/commands/writeTranslations.ts index 1e8a7f13637e..43acf9c5fab0 100644 --- a/packages/docusaurus/src/commands/writeTranslations.ts +++ b/packages/docusaurus/src/commands/writeTranslations.ts @@ -74,7 +74,9 @@ async function writePluginTranslationFiles({ export async function writeTranslations( siteDir: string, - options: WriteTranslationsOptions & ConfigOptions & {locale?: string}, + options: Partial< + WriteTranslationsOptions & ConfigOptions & {locale?: string} + >, ): Promise { const context = await loadContext({ siteDir,