Skip to content

Commit 7dd225a

Browse files
e-imslorber
authored andcommitted
feat(core): add --config param to swizzle command (#8210)
1 parent a9b622b commit 7dd225a

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

packages/docusaurus/bin/docusaurus.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ cli
7777
'copy TypeScript theme files when possible (default: false)',
7878
)
7979
.option('--danger', 'enable swizzle for unsafe component of themes')
80+
.option(
81+
'--config <config>',
82+
'path to Docusaurus config file (default: `[siteDir]/docusaurus.config.js`)',
83+
)
8084
.action(swizzle);
8185

8286
cli

packages/docusaurus/src/commands/swizzle/common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export type SwizzleCLIOptions = {
6767
list: boolean;
6868
wrap: boolean;
6969
eject: boolean;
70+
config?: string;
7071
};
7172

7273
export function normalizeOptions(
@@ -78,6 +79,7 @@ export function normalizeOptions(
7879
list: options.list ?? false,
7980
wrap: options.wrap ?? false,
8081
eject: options.eject ?? false,
82+
config: options.config ?? undefined,
8183
};
8284
}
8385

packages/docusaurus/src/commands/swizzle/context.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
import {loadContext} from '../../server';
99
import {initPlugins} from '../../server/plugins/init';
1010
import {loadPluginConfigs} from '../../server/plugins/configs';
11-
import type {SwizzleContext} from './common';
11+
import type {SwizzleCLIOptions, SwizzleContext} from './common';
1212

1313
export async function initSwizzleContext(
1414
siteDir: string,
15+
options: SwizzleCLIOptions,
1516
): Promise<SwizzleContext> {
16-
const context = await loadContext({siteDir});
17+
const context = await loadContext({siteDir, config: options.config});
1718
const plugins = await initPlugins(context);
1819
const pluginConfigs = await loadPluginConfigs(context);
1920

packages/docusaurus/src/commands/swizzle/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export async function swizzle(
9898
const options = normalizeOptions(optionsParam);
9999
const {list, danger, typescript} = options;
100100

101-
const {plugins} = await initSwizzleContext(siteDir);
101+
const {plugins} = await initSwizzleContext(siteDir, options);
102102
const themeNames = getThemeNames(plugins);
103103

104104
if (list && !themeNameParam) {

website/docs/cli.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,16 @@ The swizzle CLI is interactive and will guide you through the whole [swizzle pro
113113

114114
#### Options {#options-swizzle}
115115

116-
| Name | Description |
117-
| --------------- | ---------------------------------------------------- |
118-
| `themeName` | The name of the theme to swizzle from. |
119-
| `componentName` | The name of the theme component to swizzle. |
120-
| `--list` | Display components available for swizzling |
121-
| `--eject` | [Eject](./swizzling.md#ejecting) the theme component |
122-
| `--wrap` | [Wrap](./swizzling.md#wrapping) the theme component |
123-
| `--danger` | Allow immediate swizzling of unsafe components |
124-
| `--typescript` | Swizzle the TypeScript variant component |
116+
| Name | Description |
117+
| --- | --- |
118+
| `themeName` | The name of the theme to swizzle from. |
119+
| `componentName` | The name of the theme component to swizzle. |
120+
| `--list` | Display components available for swizzling |
121+
| `--eject` | [Eject](./swizzling.md#ejecting) the theme component |
122+
| `--wrap` | [Wrap](./swizzling.md#wrapping) the theme component |
123+
| `--danger` | Allow immediate swizzling of unsafe components |
124+
| `--typescript` | Swizzle the TypeScript variant component |
125+
| `--config` | Path to docusaurus config file, default to `[siteDir]/docusaurus.config.js` |
125126

126127
:::caution
127128

0 commit comments

Comments
 (0)