diff --git a/packages/docusaurus/bin/docusaurus.mjs b/packages/docusaurus/bin/docusaurus.mjs index f67687371257..4ebc2a151784 100755 --- a/packages/docusaurus/bin/docusaurus.mjs +++ b/packages/docusaurus/bin/docusaurus.mjs @@ -10,19 +10,8 @@ import {inspect} from 'node:util'; import {logger} from '@docusaurus/logger'; -import cli from 'commander'; import {DOCUSAURUS_VERSION} from '@docusaurus/utils'; -import { - build, - swizzle, - deploy, - start, - externalCommand, - serve, - clear, - writeTranslations, - writeHeadingIds, -} from '../lib/index.js'; +import {runCLI} from '../lib/index.js'; import beforeCli from './beforeCli.mjs'; // Env variables are initialized to dev, but can be overridden by each command @@ -31,270 +20,28 @@ import beforeCli from './beforeCli.mjs'; process.env.BABEL_ENV ??= 'development'; process.env.NODE_ENV ??= 'development'; -await beforeCli(); - -/** - * @param {string} locale - * @param {string[]} locales - * @returns {string[]} - */ -function concatLocaleOptions(locale, locales = []) { - return locales.concat(locale); -} - -cli.version(DOCUSAURUS_VERSION).usage(' [options]'); - -cli - .command('build [siteDir]') - .description('Build website.') - .option( - '--dev', - 'Builds the website in dev mode, including full React error messages.', - ) - .option( - '--bundle-analyzer', - 'visualize size of webpack output files with an interactive zoomable tree map (default: false)', - ) - .option( - '--out-dir ', - 'the full path for the new output directory, relative to the current workspace (default: build)', - ) - .option( - '--config ', - 'path to docusaurus config file (default: `[siteDir]/docusaurus.config.js`)', - ) - .option( - '-l, --locale ', - 'build the site in the specified locale(s). Build all known locales otherwise', - concatLocaleOptions, - ) - .option( - '--no-minify', - 'build website without minimizing JS bundles (default: false)', - ) - .action(build); - -cli - .command('swizzle [themeName] [componentName] [siteDir]') - .description( - 'Wraps or ejects the original theme files into website folder for customization.', - ) - .option( - '-w, --wrap', - 'Creates a wrapper around the original theme component.\nAllows rendering other components before/after the original theme component.', - ) - .option( - '-e, --eject', - 'Ejects the full source code of the original theme component.\nAllows overriding the original component entirely with your own UI and logic.', - ) - .option( - '-l, --list', - 'only list the available themes/components without further prompting (default: false)', - ) - .option( - '-t, --typescript', - 'copy TypeScript theme files when possible (default: false)', - ) - .option( - '-j, --javascript', - 'copy JavaScript theme files when possible (default: false)', - ) - .option('--danger', 'enable swizzle for unsafe component of themes') - .option( - '--config ', - 'path to Docusaurus config file (default: `[siteDir]/docusaurus.config.js`)', - ) - .action(swizzle); - -cli - .command('deploy [siteDir]') - .description('Deploy website to GitHub pages.') - .option( - '-l, --locale ', - 'deploy the site in the specified locale(s). Deploy all known locales otherwise', - concatLocaleOptions, - ) - .option( - '--out-dir ', - 'the full path for the new output directory, relative to the current workspace (default: build)', - ) - .option( - '--config ', - 'path to Docusaurus config file (default: `[siteDir]/docusaurus.config.js`)', - ) - .option( - '--skip-build', - 'skip building website before deploy it (default: false)', - ) - .option( - '--target-dir ', - 'path to the target directory to deploy to (default: `.`)', - ) - .action(deploy); - /** - * @param {string | undefined} value - * @returns {boolean | number} + * @param {unknown} error */ -function normalizePollValue(value) { - if (value === undefined || value === '') { - return false; - } - - const parsedIntValue = Number.parseInt(value, 10); - if (!Number.isNaN(parsedIntValue)) { - return parsedIntValue; - } - - return value === 'true'; -} - -cli - .command('start [siteDir]') - .description('Start the development server.') - .option('-p, --port ', 'use specified port (default: 3000)') - .option('-h, --host ', 'use specified host (default: localhost)') - .option('-l, --locale ', 'use specified site locale') - .option( - '--hot-only', - 'do not fallback to page refresh if hot reload fails (default: false)', - ) - .option( - '--config ', - 'path to Docusaurus config file (default: `[siteDir]/docusaurus.config.js`)', - ) - .option('--no-open', 'do not open page in the browser (default: false)') - .option( - '--poll [interval]', - 'use polling rather than watching for reload (default: false). Can specify a poll interval in milliseconds', - normalizePollValue, - ) - .option( - '--no-minify', - 'build website without minimizing JS bundles (default: false)', - ) - .action(start); - -cli - .command('serve [siteDir]') - .description('Serve website locally.') - .option( - '--dir ', - 'the full path for the new output directory, relative to the current workspace (default: build)', - ) - .option( - '--config ', - 'path to Docusaurus config file (default: `[siteDir]/docusaurus.config.js`)', - ) - .option('-p, --port ', 'use specified port (default: 3000)') - .option('--build', 'build website before serving (default: false)') - .option('-h, --host ', 'use specified host (default: localhost)') - .option( - '--no-open', - 'do not open page in the browser (default: false, or true in CI)', - ) - .action(serve); - -cli - .command('clear [siteDir]') - .description('Remove build artifacts.') - .action(clear); - -cli - .command('write-translations [siteDir]') - .description('Extract required translations of your site.') - .option( - '-l, --locale ', - 'the locale folder to write the translations.\n"--locale fr" will write translations in the ./i18n/fr folder.', - ) - .option( - '--override', - 'By default, we only append missing translation messages to existing translation files. This option allows to override existing translation messages. Make sure to commit or backup your existing translations, as they may be overridden. (default: false)', - ) - .option( - '--config ', - 'path to Docusaurus config file (default:`[siteDir]/docusaurus.config.js`)', - ) - .option( - '--messagePrefix ', - 'Allows to init new written messages with a given prefix. This might help you to highlight untranslated message by making them stand out in the UI (default: "")', - ) - .action(writeTranslations); - -cli - .command('write-heading-ids [siteDir] [files...]') - .description('Generate heading ids in Markdown content.') - .option( - '--maintain-case', - "keep the headings' casing, otherwise make all lowercase (default: false)", - ) - .option('--overwrite', 'overwrite existing heading IDs (default: false)') - .action(writeHeadingIds); - -cli.arguments('').action((cmd) => { - cli.outputHelp(); - logger.error`Unknown Docusaurus CLI command name=${cmd}.`; - process.exit(1); -}); - -// === The above is the commander configuration === -// They don't start any code execution yet until cli.parse() is called below - -/** - * @param {string | undefined} command - */ -function isInternalCommand(command) { - return ( - command && - [ - 'start', - 'build', - 'swizzle', - 'deploy', - 'serve', - 'clear', - 'write-translations', - 'write-heading-ids', - ].includes(command) - ); -} - -/** - * @param {string | undefined} command - */ -function isExternalCommand(command) { - return !!(command && !isInternalCommand(command) && !command.startsWith('-')); -} - -// No command? We print the help message because Commander doesn't -// Note argv looks like this: ['../node','../docusaurus.mjs','',...rest] -if (process.argv.length < 3) { - cli.outputHelp(); - logger.error`Please provide a Docusaurus CLI command.`; - process.exit(1); -} - -// There is an unrecognized subcommand -// Let plugins extend the CLI before parsing -if (isExternalCommand(process.argv[2])) { - // TODO: in this step, we must assume default site structure because there's - // no way to know the siteDir/config yet. Maybe the root cli should be - // responsible for parsing these arguments? - // https://github.com/facebook/docusaurus/issues/8903 - await externalCommand(cli); -} - -cli.parse(process.argv); - -process.on('unhandledRejection', (err) => { +function handleError(error) { console.log(''); // We need to use inspect with increased depth to log the full causal chain // By default Node logging has depth=2 // see also https://github.com/nodejs/node/issues/51637 - logger.error(inspect(err, {depth: Infinity})); + logger.error(inspect(error, {depth: Infinity})); logger.info`Docusaurus version: number=${DOCUSAURUS_VERSION} Node version: number=${process.version}`; process.exit(1); -}); +} + +process.on('unhandledRejection', handleError); + +try { + await beforeCli(); + // @ts-expect-error: we know it has at least 2 args + await runCLI(process.argv); +} catch (e) { + handleError(e); +} diff --git a/packages/docusaurus/src/commands/__tests__/__fixtures__/site/docusaurus.config.js b/packages/docusaurus/src/commands/__tests__/__fixtures__/site/docusaurus.config.js new file mode 100644 index 000000000000..a530fd22cee3 --- /dev/null +++ b/packages/docusaurus/src/commands/__tests__/__fixtures__/site/docusaurus.config.js @@ -0,0 +1,21 @@ +function myCLIPlugin(context, options) { + return { + name: 'docusaurus-plugin', + extendCli(cli) { + cli + .command('cliPlugin:test') + .description('Run test cli command') + .option('-to, --test-option', 'Test option') + .action(() => { + console.log('TEST ACTION'); + }); + }, + }; +} + +export default { + title: 'My Site', + url: 'https://example.com', + baseUrl: '/', + plugins: [myCLIPlugin], +}; diff --git a/packages/docusaurus/src/commands/__tests__/cli.test.ts b/packages/docusaurus/src/commands/__tests__/cli.test.ts new file mode 100644 index 000000000000..bf5562fe6783 --- /dev/null +++ b/packages/docusaurus/src/commands/__tests__/cli.test.ts @@ -0,0 +1,227 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import path from 'path'; +import {Command, type CommanderStatic} from 'commander'; +import {createCLIProgram} from '../cli'; + +const ExitOverrideError = new Error('exitOverride'); + +async function testCommand(args: string[]) { + const cliArgs: [string, string, ...string[]] = [ + 'node', + 'docusaurus', + ...args, + ]; + const siteDir = path.resolve(__dirname, '__fixtures__', 'site'); + + // TODO Docusaurus v4: upgrade Commander + // new versions make it easier to intercept logs + // see https://github.com/tj/commander.js#override-exit-and-output-handling + let stdout = ''; + let stderr = ''; + jest.spyOn(console, 'log').mockImplementation((msg: string) => { + stdout += msg; + }); + // @ts-expect-error: only used with strings + jest.spyOn(process.stdout, 'write').mockImplementation((msg: string) => { + stdout += String(msg); + }); + jest.spyOn(console, 'error').mockImplementation((msg: string) => { + stderr += msg; + }); + + const cli = await createCLIProgram({ + cli: new Command() as CommanderStatic, + cliArgs, + siteDir, + config: undefined, + }); + + let exit: undefined | {code: string; exitCode: number}; + cli.exitOverride((err) => { + exit = {code: err.code, exitCode: err.exitCode}; + // If you don't throw here, commander will still exit :/ + throw ExitOverrideError; + }); + + try { + await cli.parseAsync(cliArgs); + } catch (e) { + if (e !== ExitOverrideError) { + throw e; + } + } + + jest.restoreAllMocks(); + + return { + exit, + stdout, + stderr, + }; +} + +describe('CLI', () => { + describe('general', () => { + describe('help', () => { + it('docusaurus --help', async () => { + const result = await testCommand(['--help']); + + expect(result).toMatchInlineSnapshot(` + { + "exit": { + "code": "commander.helpDisplayed", + "exitCode": 0, + }, + "stderr": "", + "stdout": "Usage: docusaurus [options] + + Options: + -V, --version output the version number + -h, --help display help for command + + Commands: + build [options] [siteDir] Build website. + swizzle [options] [themeName] [componentName] [siteDir] Wraps or ejects the original theme files into website folder for customization. + deploy [options] [siteDir] Deploy website to GitHub pages. + start [options] [siteDir] Start the development server. + serve [options] [siteDir] Serve website locally. + clear [siteDir] Remove build artifacts. + write-translations [options] [siteDir] Extract required translations of your site. + write-heading-ids [options] [siteDir] [files...] Generate heading ids in Markdown content. + cliPlugin:test [options] Run test cli command + ", + } + `); + }); + + it('docusaurus -h', async () => { + const result = await testCommand(['-h']); + + expect(result).toMatchInlineSnapshot(` + { + "exit": { + "code": "commander.helpDisplayed", + "exitCode": 0, + }, + "stderr": "", + "stdout": "Usage: docusaurus [options] + + Options: + -V, --version output the version number + -h, --help display help for command + + Commands: + build [options] [siteDir] Build website. + swizzle [options] [themeName] [componentName] [siteDir] Wraps or ejects the original theme files into website folder for customization. + deploy [options] [siteDir] Deploy website to GitHub pages. + start [options] [siteDir] Start the development server. + serve [options] [siteDir] Serve website locally. + clear [siteDir] Remove build artifacts. + write-translations [options] [siteDir] Extract required translations of your site. + write-heading-ids [options] [siteDir] [files...] Generate heading ids in Markdown content. + cliPlugin:test [options] Run test cli command + ", + } + `); + }); + }); + + describe('version', () => { + it('docusaurus --version', async () => { + const result = await testCommand(['--version']); + + expect(result).toMatchInlineSnapshot(` + { + "exit": { + "code": "commander.version", + "exitCode": 0, + }, + "stderr": "", + "stdout": " + ", + } + `); + }); + + it('docusaurus -V', async () => { + const result = await testCommand(['-V']); + + expect(result).toMatchInlineSnapshot(` + { + "exit": { + "code": "commander.version", + "exitCode": 0, + }, + "stderr": "", + "stdout": " + ", + } + `); + }); + }); + + describe('errors', () => { + it('docusaurus', async () => { + await expect( + testCommand(['']), + ).rejects.toThrowErrorMatchingInlineSnapshot( + `"Missing Docusaurus CLI command."`, + ); + }); + + it('docusaurus unknown', async () => { + await expect( + testCommand(['unknown']), + ).rejects.toThrowErrorMatchingInlineSnapshot( + `"Unknown Docusaurus CLI command \`unknown\`"`, + ); + }); + + it('docusaurus --unknown', async () => { + const result = await testCommand(['--unknown']); + expect(result).toMatchInlineSnapshot(` + { + "exit": { + "code": "commander.unknownOption", + "exitCode": 1, + }, + "stderr": "error: unknown option '--unknown'", + "stdout": "", + } + `); + }); + }); + }); + + describe('extendCLI', () => { + it('docusaurus cliPlugin:test', async () => { + const result = await testCommand(['cliPlugin:test']); + expect(result).toMatchInlineSnapshot(` + { + "exit": undefined, + "stderr": "", + "stdout": "TEST ACTION + ", + } + `); + }); + + it('docusaurus cliPlugin:test --test-option', async () => { + const result = await testCommand(['cliPlugin:test', '--test-option']); + expect(result).toMatchInlineSnapshot(` + { + "exit": undefined, + "stderr": "", + "stdout": "TEST ACTION + ", + } + `); + }); + }); +}); diff --git a/packages/docusaurus/src/commands/cli.ts b/packages/docusaurus/src/commands/cli.ts new file mode 100755 index 000000000000..60a634810fe6 --- /dev/null +++ b/packages/docusaurus/src/commands/cli.ts @@ -0,0 +1,281 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import {logger} from '@docusaurus/logger'; +import Commander, {type CommanderStatic} from 'commander'; +import {DOCUSAURUS_VERSION} from '@docusaurus/utils'; + +import {build} from './build/build'; +import {clear} from './clear'; +import {deploy} from './deploy'; +import {externalCommand} from './external'; +import {serve} from './serve'; +import {start} from './start/start'; +import {swizzle} from './swizzle'; +import {writeHeadingIds} from './writeHeadingIds'; +import {writeTranslations} from './writeTranslations'; + +function concatLocaleOptions(locale: string, locales: string[] = []): string[] { + return locales.concat(locale); +} + +function isInternalCommand(command: string | undefined) { + return ( + command && + [ + 'start', + 'build', + 'swizzle', + 'deploy', + 'serve', + 'clear', + 'write-translations', + 'write-heading-ids', + ].includes(command) + ); +} + +// TODO Docusaurus v4: use Command instead of CommanderStatic here +type CLIProgram = CommanderStatic; + +// Something like ['../node','../docusaurus.mjs','',...rest] +type CLIArgs = [string, string, ...string[]]; + +// TODO: Annoying, we must assume default site dir is '.' because there's +// no way to know the siteDir/config yet. +// The individual CLI commands can declare/read siteDir on their own +// The env variable is an escape hatch +// See https://github.com/facebook/docusaurus/issues/8903 +const DEFAULT_SITE_DIR = process.env.DOCUSAURUS_CLI_SITE_DIR ?? '.'; +// Similarly we give an env escape hatch for config +// See https://github.com/facebook/docusaurus/issues/8903 +const DEFAULT_CONFIG = process.env.DOCUSAURUS_CLI_CONFIG ?? undefined; + +export async function runCLI(cliArgs: CLIArgs): Promise { + const program = await createCLIProgram({ + cli: Commander, + cliArgs, + siteDir: DEFAULT_SITE_DIR, + config: DEFAULT_CONFIG, + }); + await program.parseAsync(cliArgs); +} + +export async function createCLIProgram({ + cli, + cliArgs, + siteDir, + config, +}: { + cli: CLIProgram; + cliArgs: CLIArgs; + siteDir: string; + config: string | undefined; +}): Promise { + const command = cliArgs[2]; + + cli.version(DOCUSAURUS_VERSION).usage(' [options]'); + + cli + .command('build [siteDir]') + .description('Build website.') + .option( + '--dev', + 'Builds the website in dev mode, including full React error messages.', + ) + .option( + '--bundle-analyzer', + 'visualize size of webpack output files with an interactive zoomable tree map (default: false)', + ) + .option( + '--out-dir ', + 'the full path for the new output directory, relative to the current workspace (default: build)', + ) + .option( + '--config ', + 'path to docusaurus config file (default: `[siteDir]/docusaurus.config.js`)', + ) + .option( + '-l, --locale ', + 'build the site in the specified locale(s). Build all known locales otherwise', + concatLocaleOptions, + ) + .option( + '--no-minify', + 'build website without minimizing JS bundles (default: false)', + ) + .action(build); + + cli + .command('swizzle [themeName] [componentName] [siteDir]') + .description( + 'Wraps or ejects the original theme files into website folder for customization.', + ) + .option( + '-w, --wrap', + 'Creates a wrapper around the original theme component.\nAllows rendering other components before/after the original theme component.', + ) + .option( + '-e, --eject', + 'Ejects the full source code of the original theme component.\nAllows overriding the original component entirely with your own UI and logic.', + ) + .option( + '-l, --list', + 'only list the available themes/components without further prompting (default: false)', + ) + .option( + '-t, --typescript', + 'copy TypeScript theme files when possible (default: false)', + ) + .option( + '-j, --javascript', + 'copy JavaScript theme files when possible (default: false)', + ) + .option('--danger', 'enable swizzle for unsafe component of themes') + .option( + '--config ', + 'path to Docusaurus config file (default: `[siteDir]/docusaurus.config.js`)', + ) + .action(swizzle); + + cli + .command('deploy [siteDir]') + .description('Deploy website to GitHub pages.') + .option( + '-l, --locale ', + 'deploy the site in the specified locale(s). Deploy all known locales otherwise', + concatLocaleOptions, + ) + .option( + '--out-dir ', + 'the full path for the new output directory, relative to the current workspace (default: build)', + ) + .option( + '--config ', + 'path to Docusaurus config file (default: `[siteDir]/docusaurus.config.js`)', + ) + .option( + '--skip-build', + 'skip building website before deploy it (default: false)', + ) + .option( + '--target-dir ', + 'path to the target directory to deploy to (default: `.`)', + ) + .action(deploy); + + function normalizePollValue(value?: string) { + if (value === undefined || value === '') { + return false; + } + const parsedIntValue = Number.parseInt(value, 10); + if (!Number.isNaN(parsedIntValue)) { + return parsedIntValue; + } + return value === 'true'; + } + + cli + .command('start [siteDir]') + .description('Start the development server.') + .option('-p, --port ', 'use specified port (default: 3000)') + .option('-h, --host ', 'use specified host (default: localhost)') + .option('-l, --locale ', 'use specified site locale') + .option( + '--hot-only', + 'do not fallback to page refresh if hot reload fails (default: false)', + ) + .option( + '--config ', + 'path to Docusaurus config file (default: `[siteDir]/docusaurus.config.js`)', + ) + .option('--no-open', 'do not open page in the browser (default: false)') + .option( + '--poll [interval]', + 'use polling rather than watching for reload (default: false). Can specify a poll interval in milliseconds', + normalizePollValue, + ) + .option( + '--no-minify', + 'build website without minimizing JS bundles (default: false)', + ) + .action(start); + + cli + .command('serve [siteDir]') + .description('Serve website locally.') + .option( + '--dir ', + 'the full path for the new output directory, relative to the current workspace (default: build)', + ) + .option( + '--config ', + 'path to Docusaurus config file (default: `[siteDir]/docusaurus.config.js`)', + ) + .option('-p, --port ', 'use specified port (default: 3000)') + .option('--build', 'build website before serving (default: false)') + .option('-h, --host ', 'use specified host (default: localhost)') + .option( + '--no-open', + 'do not open page in the browser (default: false, or true in CI)', + ) + .action(serve); + + cli + .command('clear [siteDir]') + .description('Remove build artifacts.') + .action(clear); + + cli + .command('write-translations [siteDir]') + .description('Extract required translations of your site.') + .option( + '-l, --locale ', + 'the locale folder to write the translations.\n"--locale fr" will write translations in the ./i18n/fr folder.', + ) + .option( + '--override', + 'By default, we only append missing translation messages to existing translation files. This option allows to override existing translation messages. Make sure to commit or backup your existing translations, as they may be overridden. (default: false)', + ) + .option( + '--config ', + 'path to Docusaurus config file (default:`[siteDir]/docusaurus.config.js`)', + ) + .option( + '--messagePrefix ', + 'Allows to init new written messages with a given prefix. This might help you to highlight untranslated message by making them stand out in the UI (default: "")', + ) + .action(writeTranslations); + + cli + .command('write-heading-ids [siteDir] [files...]') + .description('Generate heading ids in Markdown content.') + .option( + '--maintain-case', + "keep the headings' casing, otherwise make all lowercase (default: false)", + ) + .option('--overwrite', 'overwrite existing heading IDs (default: false)') + .action(writeHeadingIds); + + cli.arguments('').action((cmd) => { + cli.outputHelp(); + if (!cmd) { + throw new Error(logger.interpolate`Missing Docusaurus CLI command.`); + } + throw new Error( + logger.interpolate`Unknown Docusaurus CLI command code=${cmd}`, + ); + }); + + // There is an unrecognized subcommand + // Let plugins extend the CLI before parsing + if (!isInternalCommand(command)) { + await externalCommand({cli, siteDir, config}); + } + + return cli; +} diff --git a/packages/docusaurus/src/commands/external.ts b/packages/docusaurus/src/commands/external.ts index 44e161a1f11c..7cc10f263f77 100644 --- a/packages/docusaurus/src/commands/external.ts +++ b/packages/docusaurus/src/commands/external.ts @@ -10,9 +10,17 @@ import {loadContext} from '../server/site'; import {initPlugins} from '../server/plugins/init'; import type {CommanderStatic} from 'commander'; -export async function externalCommand(cli: CommanderStatic): Promise { - const siteDir = await fs.realpath('.'); - const context = await loadContext({siteDir}); +export async function externalCommand({ + cli, + siteDir: siteDirInput, + config, +}: { + cli: CommanderStatic; + siteDir: string; + config: string | undefined; +}): Promise { + const siteDir = await fs.realpath(siteDirInput); + const context = await loadContext({siteDir, config}); const plugins = await initPlugins(context); // Plugin Lifecycle - extendCli. diff --git a/packages/docusaurus/src/index.ts b/packages/docusaurus/src/index.ts index 0009867c0d97..3a6a2e1362e6 100644 --- a/packages/docusaurus/src/index.ts +++ b/packages/docusaurus/src/index.ts @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. */ +export {runCLI} from './commands/cli'; export {build} from './commands/build/build'; export {clear} from './commands/clear'; export {deploy} from './commands/deploy'; diff --git a/packages/docusaurus/src/server/config.ts b/packages/docusaurus/src/server/config.ts index 59b30b133e24..0cc238879039 100644 --- a/packages/docusaurus/src/server/config.ts +++ b/packages/docusaurus/src/server/config.ts @@ -26,10 +26,11 @@ async function findConfig(siteDir: string) { fs.pathExists, ); if (!configPath) { - logger.error('No config file found.'); - logger.info`Expected one of:${candidates} -You can provide a custom config path with the code=${'--config'} option.`; - throw new Error(); + const relativeSiteDir = path.relative(process.cwd(), siteDir); + throw new Error(logger.interpolate`No config file found in site dir code=${relativeSiteDir}. +Expected one of:${candidates.map(logger.code)} +You can provide a custom config path with the code=${'--config'} option. + `); } return configPath; }