From aecdfd33a663c51b36b9695fb68be4eabde5d20b Mon Sep 17 00:00:00 2001 From: Evan McCarthy Date: Thu, 13 Oct 2022 17:32:11 -0500 Subject: [PATCH] fix: add --config param to swizzle command --- packages/docusaurus/bin/docusaurus.mjs | 4 ++++ .../docusaurus/src/commands/swizzle/common.ts | 2 ++ .../src/commands/swizzle/context.ts | 5 +++-- .../docusaurus/src/commands/swizzle/index.ts | 2 +- website/docs/cli.md | 19 ++++++++++--------- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/packages/docusaurus/bin/docusaurus.mjs b/packages/docusaurus/bin/docusaurus.mjs index a9df67b31e6d..98a03e66e51d 100755 --- a/packages/docusaurus/bin/docusaurus.mjs +++ b/packages/docusaurus/bin/docusaurus.mjs @@ -77,6 +77,10 @@ cli 'copy TypeScript 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 diff --git a/packages/docusaurus/src/commands/swizzle/common.ts b/packages/docusaurus/src/commands/swizzle/common.ts index fad472d6b140..4ca7c391b8f9 100644 --- a/packages/docusaurus/src/commands/swizzle/common.ts +++ b/packages/docusaurus/src/commands/swizzle/common.ts @@ -67,6 +67,7 @@ export type SwizzleCLIOptions = { list: boolean; wrap: boolean; eject: boolean; + config?: string; }; export function normalizeOptions( @@ -78,6 +79,7 @@ export function normalizeOptions( list: options.list ?? false, wrap: options.wrap ?? false, eject: options.eject ?? false, + config: options.config ?? undefined, }; } diff --git a/packages/docusaurus/src/commands/swizzle/context.ts b/packages/docusaurus/src/commands/swizzle/context.ts index 721bedca758a..903d447da1f1 100644 --- a/packages/docusaurus/src/commands/swizzle/context.ts +++ b/packages/docusaurus/src/commands/swizzle/context.ts @@ -8,12 +8,13 @@ import {loadContext} from '../../server'; import {initPlugins} from '../../server/plugins/init'; import {loadPluginConfigs} from '../../server/plugins/configs'; -import type {SwizzleContext} from './common'; +import type {SwizzleCLIOptions, SwizzleContext} from './common'; export async function initSwizzleContext( siteDir: string, + options: SwizzleCLIOptions, ): Promise { - const context = await loadContext({siteDir}); + const context = await loadContext({siteDir, config: options.config}); const plugins = await initPlugins(context); const pluginConfigs = await loadPluginConfigs(context); diff --git a/packages/docusaurus/src/commands/swizzle/index.ts b/packages/docusaurus/src/commands/swizzle/index.ts index 1c76f59d7c62..d03ec217fdd1 100644 --- a/packages/docusaurus/src/commands/swizzle/index.ts +++ b/packages/docusaurus/src/commands/swizzle/index.ts @@ -98,7 +98,7 @@ export async function swizzle( const options = normalizeOptions(optionsParam); const {list, danger, typescript} = options; - const {plugins} = await initSwizzleContext(siteDir); + const {plugins} = await initSwizzleContext(siteDir, options); const themeNames = getThemeNames(plugins); if (list && !themeNameParam) { diff --git a/website/docs/cli.md b/website/docs/cli.md index 2f4f68d85cdf..01a3567fa31b 100644 --- a/website/docs/cli.md +++ b/website/docs/cli.md @@ -113,15 +113,16 @@ The swizzle CLI is interactive and will guide you through the whole [swizzle pro #### Options {#options-swizzle} -| Name | Description | -| --------------- | ---------------------------------------------------- | -| `themeName` | The name of the theme to swizzle from. | -| `componentName` | The name of the theme component to swizzle. | -| `--list` | Display components available for swizzling | -| `--eject` | [Eject](./swizzling.md#ejecting) the theme component | -| `--wrap` | [Wrap](./swizzling.md#wrapping) the theme component | -| `--danger` | Allow immediate swizzling of unsafe components | -| `--typescript` | Swizzle the TypeScript variant component | +| Name | Description | +| --- | --- | +| `themeName` | The name of the theme to swizzle from. | +| `componentName` | The name of the theme component to swizzle. | +| `--list` | Display components available for swizzling | +| `--eject` | [Eject](./swizzling.md#ejecting) the theme component | +| `--wrap` | [Wrap](./swizzling.md#wrapping) the theme component | +| `--danger` | Allow immediate swizzling of unsafe components | +| `--typescript` | Swizzle the TypeScript variant component | +| `--config` | Path to docusaurus config file, default to `[siteDir]/docusaurus.config.js` | :::caution