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(cli): output help when no conventional config + no subcommand #9648

Merged
merged 1 commit into from
Dec 21, 2023
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
28 changes: 24 additions & 4 deletions packages/docusaurus/bin/docusaurus.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ cli.arguments('<command>').action((cmd) => {
logger.error` Unknown command name=${cmd}.`;
});

// === The above is the commander configuration ===
// They don't start any code execution yet until cli.parse() is called below

/**
* @param {string | undefined} command
*/
Expand All @@ -237,12 +240,29 @@ function isInternalCommand(command) {
);
}

if (!isInternalCommand(process.argv.slice(2)[0])) {
await externalCommand(cli);
}
// process.argv always looks like this:
// [
// '/path/to/node',
// '/path/to/docusaurus.mjs',
// '<subcommand>',
// ...subcommandArgs
// ]

if (!process.argv.slice(2).length) {
// There is no subcommand
// TODO: can we use commander to handle this case?
if (process.argv.length < 3 || process.argv[2]?.startsWith('--')) {
cli.outputHelp();
process.exit(1);
}

// There is an unrecognized subcommand
// Let plugins extend the CLI before parsing
if (!isInternalCommand(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);
Expand Down
Loading