Skip to content

Commit

Permalink
feat(core): add --config param to swizzle command (#8210)
Browse files Browse the repository at this point in the history
  • Loading branch information
e-im authored and slorber committed Oct 28, 2022
1 parent a9b622b commit 7dd225a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
4 changes: 4 additions & 0 deletions packages/docusaurus/bin/docusaurus.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ cli
'copy TypeScript theme files when possible (default: false)',
)
.option('--danger', 'enable swizzle for unsafe component of themes')
.option(
'--config <config>',
'path to Docusaurus config file (default: `[siteDir]/docusaurus.config.js`)',
)
.action(swizzle);

cli
Expand Down
2 changes: 2 additions & 0 deletions packages/docusaurus/src/commands/swizzle/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export type SwizzleCLIOptions = {
list: boolean;
wrap: boolean;
eject: boolean;
config?: string;
};

export function normalizeOptions(
Expand All @@ -78,6 +79,7 @@ export function normalizeOptions(
list: options.list ?? false,
wrap: options.wrap ?? false,
eject: options.eject ?? false,
config: options.config ?? undefined,
};
}

Expand Down
5 changes: 3 additions & 2 deletions packages/docusaurus/src/commands/swizzle/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SwizzleContext> {
const context = await loadContext({siteDir});
const context = await loadContext({siteDir, config: options.config});
const plugins = await initPlugins(context);
const pluginConfigs = await loadPluginConfigs(context);

Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/src/commands/swizzle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 10 additions & 9 deletions website/docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7dd225a

Please sign in to comment.