@docusaurus/core 2.0.0-beta.15d451942 → 2.0.0-beta.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/beforeCli.mjs +133 -0
- package/bin/docusaurus.mjs +279 -0
- package/lib/babel/preset.d.ts +8 -3
- package/lib/babel/preset.js +8 -7
- package/lib/choosePort.js +31 -43
- package/lib/client/.eslintrc.js +0 -1
- package/lib/client/App.d.ts +1 -2
- package/lib/client/App.js +23 -24
- package/lib/client/LinksCollector.d.ts +3 -3
- package/lib/client/LinksCollector.js +7 -11
- package/lib/client/PendingNavigation.d.ts +24 -1
- package/lib/client/PendingNavigation.js +5 -7
- package/lib/{webpack/sharedModuleAliases.d.ts → client/SiteMetadataDefaults.d.ts} +2 -4
- package/lib/client/SiteMetadataDefaults.js +19 -0
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +13 -0
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +15 -10
- package/lib/client/browserContext.d.ts +11 -0
- package/lib/client/browserContext.js +22 -0
- package/lib/client/client-lifecycles-dispatcher.d.ts +2 -5
- package/lib/client/client-lifecycles-dispatcher.js +6 -10
- package/lib/client/clientEntry.js +13 -7
- package/lib/client/docusaurus.d.ts +6 -0
- package/lib/client/docusaurus.js +16 -25
- package/lib/client/docusaurusContext.d.ts +12 -0
- package/lib/client/docusaurusContext.js +25 -0
- package/lib/client/exports/BrowserOnly.d.ts +2 -3
- package/lib/client/exports/BrowserOnly.js +14 -7
- package/lib/client/exports/ComponentCreator.d.ts +1 -2
- package/lib/client/exports/ComponentCreator.js +40 -19
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +35 -0
- package/lib/client/exports/Head.d.ts +2 -3
- package/lib/client/exports/Head.js +3 -4
- package/lib/client/exports/Interpolate.d.ts +2 -2
- package/lib/client/exports/Interpolate.js +20 -26
- package/lib/client/exports/Link.d.ts +11 -5
- package/lib/client/exports/Link.js +31 -20
- package/lib/client/exports/Translate.d.ts +1 -1
- package/lib/client/exports/Translate.js +14 -9
- package/lib/client/exports/constants.js +1 -11
- package/lib/client/exports/isInternalUrl.js +1 -1
- package/lib/client/exports/renderRoutes.d.ts +1 -2
- package/lib/client/exports/renderRoutes.js +1 -2
- package/lib/client/exports/router.d.ts +1 -1
- package/lib/client/exports/router.js +1 -1
- package/lib/client/exports/useBaseUrl.js +8 -5
- package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
- package/lib/client/exports/useDocusaurusContext.js +3 -9
- package/lib/client/exports/useGlobalData.d.ts +4 -3
- package/lib/client/exports/useGlobalData.js +4 -8
- package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
- package/lib/client/exports/useIsBrowser.js +11 -0
- package/lib/{server/loadSetup.d.ts → client/exports/useRouteContext.d.ts} +2 -3
- package/lib/client/exports/useRouteContext.js +15 -0
- package/lib/client/flat.d.ts +4 -2
- package/lib/client/flat.js +9 -13
- package/lib/client/normalizeLocation.d.ts +2 -5
- package/lib/client/normalizeLocation.js +2 -7
- package/lib/client/nprogress.css +2 -2
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +4 -6
- package/lib/client/preload.d.ts +3 -2
- package/lib/client/preload.js +5 -10
- package/lib/client/routeContext.d.ts +13 -0
- package/lib/client/routeContext.js +31 -0
- package/lib/client/serverEntry.d.ts +10 -0
- package/lib/client/serverEntry.js +90 -142
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +43 -0
- package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
- package/lib/client/theme-fallback/Layout/index.js +2 -26
- package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
- package/lib/client/theme-fallback/Loading/index.js +47 -115
- package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
- package/lib/client/theme-fallback/NotFound/index.js +17 -18
- package/lib/client/theme-fallback/Root/index.d.ts +10 -0
- package/lib/client/theme-fallback/Root/index.js +2 -6
- package/lib/client/theme-fallback/SiteMetadata/index.d.ts +8 -0
- package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
- package/lib/commands/build.d.ts +1 -1
- package/lib/commands/build.js +50 -54
- package/lib/commands/clear.d.ts +6 -0
- package/lib/commands/clear.js +30 -19
- package/lib/commands/commandUtils.d.ts +7 -1
- package/lib/commands/commandUtils.js +7 -7
- package/lib/commands/deploy.d.ts +1 -1
- package/lib/commands/deploy.js +83 -66
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +4 -8
- package/lib/commands/serve.d.ts +1 -1
- package/lib/commands/serve.js +25 -12
- package/lib/commands/start.d.ts +1 -1
- package/lib/commands/start.js +96 -87
- package/lib/commands/swizzle/actions.d.ts +23 -0
- package/lib/commands/swizzle/actions.js +101 -0
- package/lib/commands/swizzle/common.d.ts +33 -0
- package/lib/commands/swizzle/common.js +56 -0
- package/lib/commands/swizzle/components.d.ts +29 -0
- package/lib/commands/swizzle/components.js +162 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +80 -0
- package/lib/commands/swizzle/context.d.ts +8 -0
- package/lib/commands/swizzle/context.js +28 -0
- package/lib/commands/swizzle/index.d.ts +8 -0
- package/lib/commands/swizzle/index.js +115 -0
- package/lib/commands/swizzle/prompts.d.ts +12 -0
- package/lib/commands/swizzle/prompts.js +110 -0
- package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
- package/lib/commands/swizzle/tables.js +113 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +106 -0
- package/lib/commands/writeHeadingIds.d.ts +2 -6
- package/lib/commands/writeHeadingIds.js +19 -76
- package/lib/commands/writeTranslations.d.ts +2 -2
- package/lib/commands/writeTranslations.js +37 -17
- package/lib/index.d.ts +10 -9
- package/lib/index.js +20 -19
- package/lib/server/brokenLinks.d.ts +4 -17
- package/lib/server/brokenLinks.js +64 -52
- package/lib/server/client-modules/index.d.ts +2 -2
- package/lib/server/client-modules/index.js +4 -3
- package/lib/server/config.d.ts +2 -2
- package/lib/server/config.js +8 -5
- package/lib/server/configValidation.d.ts +4 -2
- package/lib/server/configValidation.js +93 -37
- package/lib/server/duplicateRoutes.d.ts +1 -3
- package/lib/server/duplicateRoutes.js +17 -13
- package/lib/server/html-tags/htmlTags.js +7 -8
- package/lib/server/html-tags/index.d.ts +2 -3
- package/lib/server/html-tags/index.js +3 -4
- package/lib/server/i18n.d.ts +2 -3
- package/lib/server/i18n.js +27 -48
- package/lib/server/index.d.ts +9 -2
- package/lib/server/index.js +175 -96
- package/lib/server/moduleShorthand.d.ts +9 -0
- package/lib/server/moduleShorthand.js +46 -0
- package/lib/server/plugins/applyRouteTrailingSlash.d.ts +9 -0
- package/lib/server/plugins/applyRouteTrailingSlash.js +19 -0
- package/lib/server/plugins/index.d.ts +4 -5
- package/lib/server/plugins/index.js +69 -45
- package/lib/server/plugins/init.d.ts +15 -5
- package/lib/server/plugins/init.js +68 -81
- package/lib/server/plugins/pluginIds.d.ts +2 -2
- package/lib/server/plugins/pluginIds.js +8 -5
- package/lib/server/presets/index.d.ts +3 -3
- package/lib/server/presets/index.js +16 -23
- package/lib/server/routes.d.ts +3 -5
- package/lib/server/routes.js +68 -36
- package/lib/server/themes/alias.d.ts +3 -2
- package/lib/server/themes/alias.js +24 -13
- package/lib/server/themes/index.d.ts +6 -2
- package/lib/server/themes/index.js +36 -24
- package/lib/server/translations/translations.d.ts +21 -17
- package/lib/server/translations/translations.js +33 -54
- package/lib/server/translations/translationsExtractor.d.ts +12 -5
- package/lib/server/translations/translationsExtractor.js +159 -121
- package/lib/server/utils.d.ts +9 -3
- package/lib/server/utils.js +7 -9
- package/lib/server/versions/index.d.ts +3 -4
- package/lib/server/versions/index.js +22 -24
- package/lib/webpack/base.d.ts +6 -4
- package/lib/webpack/base.js +51 -36
- package/lib/webpack/client.d.ts +3 -3
- package/lib/webpack/client.js +12 -19
- package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
- package/lib/webpack/plugins/ChunkAssetPlugin.js +24 -17
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -6
- package/lib/webpack/plugins/CleanWebpackPlugin.js +10 -16
- package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
- package/lib/webpack/plugins/LogPlugin.js +4 -5
- package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
- package/lib/webpack/plugins/WaitPlugin.js +1 -1
- package/lib/webpack/server.d.ts +3 -3
- package/lib/webpack/server.js +14 -7
- package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
- package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
- package/lib/{client → webpack}/templates/ssr.html.template.js +5 -4
- package/lib/webpack/utils.d.ts +15 -30
- package/lib/webpack/utils.js +57 -175
- package/package.json +77 -70
- package/bin/docusaurus.js +0 -326
- package/lib/.tsbuildinfo +0 -5732
- package/lib/client/.tsbuildinfo +0 -4171
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- package/lib/commands/swizzle.d.ts +0 -9
- package/lib/commands/swizzle.js +0 -245
- package/lib/constants.d.ts +0 -18
- package/lib/constants.js +0 -23
- package/lib/server/loadSetup.js +0 -25
- package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
- package/lib/server/versions/__fixtures__/package.json +0 -3
- package/lib/server/versions/__tests/index.test.js +0 -25
- package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
- package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
- package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
- package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
- package/lib/webpack/sharedModuleAliases.js +0 -18
- package/tsconfig.client.json +0 -13
- package/tsconfig.json +0 -13
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.wrap = exports.eject = exports.getAction = exports.SwizzleActions = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
12
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
14
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
15
|
+
const utils_1 = require("@docusaurus/utils");
|
|
16
|
+
const prompts_1 = require("./prompts");
|
|
17
|
+
exports.SwizzleActions = ['wrap', 'eject'];
|
|
18
|
+
async function getAction(componentConfig, options) {
|
|
19
|
+
if (options.wrap) {
|
|
20
|
+
return 'wrap';
|
|
21
|
+
}
|
|
22
|
+
if (options.eject) {
|
|
23
|
+
return 'eject';
|
|
24
|
+
}
|
|
25
|
+
return (0, prompts_1.askSwizzleAction)(componentConfig);
|
|
26
|
+
}
|
|
27
|
+
exports.getAction = getAction;
|
|
28
|
+
async function isDir(dirPath) {
|
|
29
|
+
return ((await fs_extra_1.default.pathExists(dirPath)) && (await fs_extra_1.default.stat(dirPath)).isDirectory());
|
|
30
|
+
}
|
|
31
|
+
async function eject({ siteDir, themePath, componentName, }) {
|
|
32
|
+
const fromPath = path_1.default.join(themePath, componentName);
|
|
33
|
+
const isDirectory = await isDir(fromPath);
|
|
34
|
+
const globPattern = isDirectory
|
|
35
|
+
? // do we really want to copy all components?
|
|
36
|
+
path_1.default.join(fromPath, '*')
|
|
37
|
+
: `${fromPath}.*`;
|
|
38
|
+
const globPatternPosix = (0, utils_1.posixPath)(globPattern);
|
|
39
|
+
const filesToCopy = await (0, utils_1.Globby)(globPatternPosix, {
|
|
40
|
+
ignore: ['**/*.{story,stories,test,tests}.{js,jsx,ts,tsx}'],
|
|
41
|
+
});
|
|
42
|
+
if (filesToCopy.length === 0) {
|
|
43
|
+
// This should never happen
|
|
44
|
+
throw new Error(logger_1.default.interpolate `No files to copy from path=${fromPath} with glob code=${globPatternPosix}`);
|
|
45
|
+
}
|
|
46
|
+
const toPath = isDirectory
|
|
47
|
+
? path_1.default.join(siteDir, utils_1.THEME_PATH, componentName)
|
|
48
|
+
: path_1.default.join(siteDir, utils_1.THEME_PATH);
|
|
49
|
+
await fs_extra_1.default.ensureDir(toPath);
|
|
50
|
+
const createdFiles = await Promise.all(filesToCopy.map(async (sourceFile) => {
|
|
51
|
+
const fileName = path_1.default.basename(sourceFile);
|
|
52
|
+
const targetFile = path_1.default.join(toPath, fileName);
|
|
53
|
+
try {
|
|
54
|
+
await fs_extra_1.default.copy(sourceFile, targetFile, { overwrite: true });
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
throw new Error(logger_1.default.interpolate `Could not copy file from ${sourceFile} to ${targetFile}`);
|
|
58
|
+
}
|
|
59
|
+
return targetFile;
|
|
60
|
+
}));
|
|
61
|
+
return { createdFiles };
|
|
62
|
+
}
|
|
63
|
+
exports.eject = eject;
|
|
64
|
+
async function wrap({ siteDir, themePath, componentName: themeComponentName, typescript, importType = 'original', }) {
|
|
65
|
+
const isDirectory = await isDir(path_1.default.join(themePath, themeComponentName));
|
|
66
|
+
// Top/Parent/ComponentName => ComponentName
|
|
67
|
+
const componentName = lodash_1.default.last(themeComponentName.split('/'));
|
|
68
|
+
const wrapperComponentName = `${componentName}Wrapper`;
|
|
69
|
+
const wrapperFileName = `${themeComponentName}${isDirectory ? '/index' : ''}${typescript ? '.tsx' : '.js'}`;
|
|
70
|
+
await fs_extra_1.default.ensureDir(path_1.default.resolve(siteDir, utils_1.THEME_PATH));
|
|
71
|
+
const toPath = path_1.default.resolve(siteDir, utils_1.THEME_PATH, wrapperFileName);
|
|
72
|
+
const content = typescript
|
|
73
|
+
? `import React, {ComponentProps} from 'react';
|
|
74
|
+
import type ${componentName}Type from '@theme/${themeComponentName}';
|
|
75
|
+
import ${componentName} from '@theme-${importType}/${themeComponentName}';
|
|
76
|
+
|
|
77
|
+
type Props = ComponentProps<typeof ${componentName}Type>
|
|
78
|
+
|
|
79
|
+
export default function ${wrapperComponentName}(props: Props): JSX.Element {
|
|
80
|
+
return (
|
|
81
|
+
<>
|
|
82
|
+
<${componentName} {...props} />
|
|
83
|
+
</>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
`
|
|
87
|
+
: `import React from 'react';
|
|
88
|
+
import ${componentName} from '@theme-${importType}/${themeComponentName}';
|
|
89
|
+
|
|
90
|
+
export default function ${wrapperComponentName}(props) {
|
|
91
|
+
return (
|
|
92
|
+
<>
|
|
93
|
+
<${componentName} {...props} />
|
|
94
|
+
</>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
`;
|
|
98
|
+
await fs_extra_1.default.outputFile(toPath, content);
|
|
99
|
+
return { createdFiles: [toPath] };
|
|
100
|
+
}
|
|
101
|
+
exports.wrap = wrap;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { InitializedPlugin, SwizzleAction, SwizzleActionStatus } from '@docusaurus/types';
|
|
8
|
+
import type { NormalizedPluginConfig } from '../../server/plugins/init';
|
|
9
|
+
export declare const SwizzleActions: SwizzleAction[];
|
|
10
|
+
export declare const SwizzleActionsStatuses: SwizzleActionStatus[];
|
|
11
|
+
export declare const PartiallySafeHint: string;
|
|
12
|
+
export declare function actionStatusLabel(status: SwizzleActionStatus): string;
|
|
13
|
+
export declare function actionStatusColor(status: SwizzleActionStatus, str: string): string;
|
|
14
|
+
export declare function actionStatusSuffix(status: SwizzleActionStatus, options?: {
|
|
15
|
+
partiallySafe?: boolean;
|
|
16
|
+
}): string;
|
|
17
|
+
export declare type SwizzlePlugin = {
|
|
18
|
+
instance: InitializedPlugin;
|
|
19
|
+
plugin: NormalizedPluginConfig;
|
|
20
|
+
};
|
|
21
|
+
export declare type SwizzleContext = {
|
|
22
|
+
plugins: SwizzlePlugin[];
|
|
23
|
+
};
|
|
24
|
+
export declare type SwizzleOptions = {
|
|
25
|
+
typescript: boolean;
|
|
26
|
+
danger: boolean;
|
|
27
|
+
list: boolean;
|
|
28
|
+
wrap: boolean;
|
|
29
|
+
eject: boolean;
|
|
30
|
+
};
|
|
31
|
+
export declare function normalizeOptions(options: Partial<SwizzleOptions>): SwizzleOptions;
|
|
32
|
+
export declare function findStringIgnoringCase(str: string, values: string[]): string | undefined;
|
|
33
|
+
export declare function findClosestValue(str: string, values: string[], maxLevenshtein?: number): string | undefined;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.findClosestValue = exports.findStringIgnoringCase = exports.normalizeOptions = exports.actionStatusSuffix = exports.actionStatusColor = exports.actionStatusLabel = exports.PartiallySafeHint = exports.SwizzleActionsStatuses = exports.SwizzleActions = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const leven_1 = tslib_1.__importDefault(require("leven"));
|
|
12
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
13
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
14
|
+
exports.SwizzleActions = ['wrap', 'eject'];
|
|
15
|
+
exports.SwizzleActionsStatuses = [
|
|
16
|
+
'safe',
|
|
17
|
+
'unsafe',
|
|
18
|
+
'forbidden',
|
|
19
|
+
];
|
|
20
|
+
exports.PartiallySafeHint = logger_1.default.red('*');
|
|
21
|
+
function actionStatusLabel(status) {
|
|
22
|
+
return lodash_1.default.capitalize(status);
|
|
23
|
+
}
|
|
24
|
+
exports.actionStatusLabel = actionStatusLabel;
|
|
25
|
+
const SwizzleActionStatusColors = {
|
|
26
|
+
safe: logger_1.default.green,
|
|
27
|
+
unsafe: logger_1.default.yellow,
|
|
28
|
+
forbidden: logger_1.default.red,
|
|
29
|
+
};
|
|
30
|
+
function actionStatusColor(status, str) {
|
|
31
|
+
const colorFn = SwizzleActionStatusColors[status];
|
|
32
|
+
return colorFn(str);
|
|
33
|
+
}
|
|
34
|
+
exports.actionStatusColor = actionStatusColor;
|
|
35
|
+
function actionStatusSuffix(status, options = {}) {
|
|
36
|
+
return ` (${actionStatusColor(status, actionStatusLabel(status))}${options.partiallySafe ? exports.PartiallySafeHint : ''})`;
|
|
37
|
+
}
|
|
38
|
+
exports.actionStatusSuffix = actionStatusSuffix;
|
|
39
|
+
function normalizeOptions(options) {
|
|
40
|
+
return {
|
|
41
|
+
typescript: options.typescript ?? false,
|
|
42
|
+
danger: options.danger ?? false,
|
|
43
|
+
list: options.list ?? false,
|
|
44
|
+
wrap: options.wrap ?? false,
|
|
45
|
+
eject: options.eject ?? false,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
exports.normalizeOptions = normalizeOptions;
|
|
49
|
+
function findStringIgnoringCase(str, values) {
|
|
50
|
+
return values.find((v) => v.toLowerCase() === str.toLowerCase());
|
|
51
|
+
}
|
|
52
|
+
exports.findStringIgnoringCase = findStringIgnoringCase;
|
|
53
|
+
function findClosestValue(str, values, maxLevenshtein = 3) {
|
|
54
|
+
return values.find((v) => (0, leven_1.default)(v, str) <= maxLevenshtein);
|
|
55
|
+
}
|
|
56
|
+
exports.findClosestValue = findClosestValue;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { SwizzleAction, SwizzleActionStatus, SwizzleComponentConfig, SwizzleConfig } from '@docusaurus/types';
|
|
8
|
+
export declare type ThemeComponents = {
|
|
9
|
+
themeName: string;
|
|
10
|
+
all: string[];
|
|
11
|
+
getConfig: (component: string) => SwizzleComponentConfig;
|
|
12
|
+
getDescription: (component: string) => string;
|
|
13
|
+
getActionStatus: (component: string, action: SwizzleAction) => SwizzleActionStatus;
|
|
14
|
+
isSafeAction: (component: string, action: SwizzleAction) => boolean;
|
|
15
|
+
hasAnySafeAction: (component: string) => boolean;
|
|
16
|
+
hasAllSafeAction: (component: string) => boolean;
|
|
17
|
+
};
|
|
18
|
+
export declare function readComponentNames(themePath: string): Promise<string[]>;
|
|
19
|
+
export declare function listComponentNames(themeComponents: ThemeComponents): string;
|
|
20
|
+
export declare function getThemeComponents({ themeName, themePath, swizzleConfig, }: {
|
|
21
|
+
themeName: string;
|
|
22
|
+
themePath: string;
|
|
23
|
+
swizzleConfig: SwizzleConfig;
|
|
24
|
+
}): Promise<ThemeComponents>;
|
|
25
|
+
export declare function getComponentName({ componentNameParam, themeComponents, list, }: {
|
|
26
|
+
componentNameParam: string | undefined;
|
|
27
|
+
themeComponents: ThemeComponents;
|
|
28
|
+
list: boolean | undefined;
|
|
29
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.getComponentName = exports.getThemeComponents = exports.listComponentNames = exports.readComponentNames = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
12
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
14
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
15
|
+
const utils_1 = require("@docusaurus/utils");
|
|
16
|
+
const prompts_1 = require("./prompts");
|
|
17
|
+
const common_1 = require("./common");
|
|
18
|
+
const tables_1 = require("./tables");
|
|
19
|
+
const actions_1 = require("./actions");
|
|
20
|
+
const formatComponentName = (componentName) => componentName.replace(/[/\\]index\.[jt]sx?/, '').replace(/\.[jt]sx?/, '');
|
|
21
|
+
const skipReadDirNames = ['__test__', '__tests__', '__mocks__', '__fixtures__'];
|
|
22
|
+
async function readComponentNames(themePath) {
|
|
23
|
+
if (!(await fs_extra_1.default.pathExists(themePath))) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
async function walk(dir) {
|
|
27
|
+
const files = await Promise.all((await fs_extra_1.default.readdir(dir)).flatMap(async (file) => {
|
|
28
|
+
const fullPath = path_1.default.join(dir, file);
|
|
29
|
+
const stat = await fs_extra_1.default.stat(fullPath);
|
|
30
|
+
const isDir = stat.isDirectory();
|
|
31
|
+
return { file, fullPath, isDir };
|
|
32
|
+
}));
|
|
33
|
+
return (await Promise.all(files.map(async (file) => {
|
|
34
|
+
if (file.isDir) {
|
|
35
|
+
if (skipReadDirNames.includes(file.file)) {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
return walk(file.fullPath);
|
|
39
|
+
}
|
|
40
|
+
else if (
|
|
41
|
+
// TODO can probably be refactored
|
|
42
|
+
/(?<!\.d)\.[jt]sx?$/.test(file.fullPath) &&
|
|
43
|
+
!/(?<!\.d)\.(?:test|tests|story|stories)\.[jt]sx?$/.test(file.fullPath)) {
|
|
44
|
+
const componentName = formatComponentName((0, utils_1.posixPath)(path_1.default.relative(themePath, file.fullPath)));
|
|
45
|
+
return [{ ...file, componentName }];
|
|
46
|
+
}
|
|
47
|
+
return [];
|
|
48
|
+
}))).flat();
|
|
49
|
+
}
|
|
50
|
+
const componentFiles = await walk(themePath);
|
|
51
|
+
const componentFilesOrdered = lodash_1.default.orderBy(componentFiles, [(f) => f.componentName], ['asc']);
|
|
52
|
+
return componentFilesOrdered.map((f) => f.componentName);
|
|
53
|
+
}
|
|
54
|
+
exports.readComponentNames = readComponentNames;
|
|
55
|
+
function listComponentNames(themeComponents) {
|
|
56
|
+
if (themeComponents.all.length === 0) {
|
|
57
|
+
return 'No component to swizzle.';
|
|
58
|
+
}
|
|
59
|
+
return `${(0, tables_1.themeComponentsTable)(themeComponents)}
|
|
60
|
+
|
|
61
|
+
${(0, tables_1.helpTables)()}
|
|
62
|
+
`;
|
|
63
|
+
}
|
|
64
|
+
exports.listComponentNames = listComponentNames;
|
|
65
|
+
async function getThemeComponents({ themeName, themePath, swizzleConfig, }) {
|
|
66
|
+
const FallbackSwizzleActionStatus = 'unsafe';
|
|
67
|
+
const FallbackSwizzleComponentDescription = 'N/A';
|
|
68
|
+
const FallbackSwizzleComponentConfig = {
|
|
69
|
+
actions: {
|
|
70
|
+
wrap: FallbackSwizzleActionStatus,
|
|
71
|
+
eject: FallbackSwizzleActionStatus,
|
|
72
|
+
},
|
|
73
|
+
description: FallbackSwizzleComponentDescription,
|
|
74
|
+
};
|
|
75
|
+
const allComponents = await readComponentNames(themePath);
|
|
76
|
+
function getConfig(component) {
|
|
77
|
+
if (!allComponents.includes(component)) {
|
|
78
|
+
throw new Error(`Can't get component config: component doesn't exist: ${component}`);
|
|
79
|
+
}
|
|
80
|
+
return (swizzleConfig.components[component] ?? FallbackSwizzleComponentConfig);
|
|
81
|
+
}
|
|
82
|
+
function getDescription(component) {
|
|
83
|
+
return (getConfig(component).description ?? FallbackSwizzleComponentDescription);
|
|
84
|
+
}
|
|
85
|
+
function getActionStatus(component, action) {
|
|
86
|
+
return getConfig(component).actions[action] ?? FallbackSwizzleActionStatus;
|
|
87
|
+
}
|
|
88
|
+
function isSafeAction(component, action) {
|
|
89
|
+
return getActionStatus(component, action) === 'safe';
|
|
90
|
+
}
|
|
91
|
+
function hasAllSafeAction(component) {
|
|
92
|
+
return actions_1.SwizzleActions.every((action) => isSafeAction(component, action));
|
|
93
|
+
}
|
|
94
|
+
function hasAnySafeAction(component) {
|
|
95
|
+
return actions_1.SwizzleActions.some((action) => isSafeAction(component, action));
|
|
96
|
+
}
|
|
97
|
+
// Present the safest components first
|
|
98
|
+
const orderedComponents = lodash_1.default.orderBy(allComponents, [
|
|
99
|
+
hasAllSafeAction,
|
|
100
|
+
(component) => isSafeAction(component, 'wrap'),
|
|
101
|
+
(component) => isSafeAction(component, 'eject'),
|
|
102
|
+
(component) => component,
|
|
103
|
+
], ['desc', 'desc', 'desc', 'asc']);
|
|
104
|
+
return {
|
|
105
|
+
themeName,
|
|
106
|
+
all: orderedComponents,
|
|
107
|
+
getConfig,
|
|
108
|
+
getDescription,
|
|
109
|
+
getActionStatus,
|
|
110
|
+
isSafeAction,
|
|
111
|
+
hasAnySafeAction,
|
|
112
|
+
hasAllSafeAction,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
exports.getThemeComponents = getThemeComponents;
|
|
116
|
+
// Returns a valid value if recovering is possible
|
|
117
|
+
function handleInvalidComponentNameParam({ componentNameParam, themeComponents, }) {
|
|
118
|
+
// Trying to recover invalid value
|
|
119
|
+
// We look for potential matches that only differ in casing.
|
|
120
|
+
const differentCaseMatch = (0, common_1.findStringIgnoringCase)(componentNameParam, themeComponents.all);
|
|
121
|
+
if (differentCaseMatch) {
|
|
122
|
+
logger_1.default.warn `Component name=${componentNameParam} doesn't exist.`;
|
|
123
|
+
logger_1.default.info `name=${differentCaseMatch} will be used instead of name=${componentNameParam}.`;
|
|
124
|
+
return differentCaseMatch;
|
|
125
|
+
}
|
|
126
|
+
// No recovery value is possible: print error
|
|
127
|
+
logger_1.default.error `Component name=${componentNameParam} not found.`;
|
|
128
|
+
const suggestion = (0, common_1.findClosestValue)(componentNameParam, themeComponents.all);
|
|
129
|
+
if (suggestion) {
|
|
130
|
+
logger_1.default.info `Did you mean name=${suggestion}? ${themeComponents.hasAnySafeAction(suggestion)
|
|
131
|
+
? `Note: this component is an unsafe internal component and can only be swizzled with code=${'--danger'} or explicit confirmation.`
|
|
132
|
+
: ''}`;
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
logger_1.default.info(listComponentNames(themeComponents));
|
|
136
|
+
}
|
|
137
|
+
return process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
async function handleComponentNameParam({ componentNameParam, themeComponents, }) {
|
|
140
|
+
const isValidName = themeComponents.all.includes(componentNameParam);
|
|
141
|
+
if (!isValidName) {
|
|
142
|
+
return handleInvalidComponentNameParam({
|
|
143
|
+
componentNameParam,
|
|
144
|
+
themeComponents,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return componentNameParam;
|
|
148
|
+
}
|
|
149
|
+
async function getComponentName({ componentNameParam, themeComponents, list, }) {
|
|
150
|
+
if (list) {
|
|
151
|
+
logger_1.default.info(listComponentNames(themeComponents));
|
|
152
|
+
return process.exit(0);
|
|
153
|
+
}
|
|
154
|
+
const componentName = componentNameParam
|
|
155
|
+
? await handleComponentNameParam({
|
|
156
|
+
componentNameParam,
|
|
157
|
+
themeComponents,
|
|
158
|
+
})
|
|
159
|
+
: await (0, prompts_1.askComponentName)(themeComponents);
|
|
160
|
+
return componentName;
|
|
161
|
+
}
|
|
162
|
+
exports.getComponentName = getComponentName;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { SwizzleConfig } from '@docusaurus/types';
|
|
8
|
+
import type { SwizzlePlugin } from './common';
|
|
9
|
+
export declare function normalizeSwizzleConfig(unsafeSwizzleConfig: unknown): SwizzleConfig;
|
|
10
|
+
export declare function getThemeSwizzleConfig(themeName: string, plugins: SwizzlePlugin[]): SwizzleConfig;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.getThemeSwizzleConfig = exports.normalizeSwizzleConfig = void 0;
|
|
10
|
+
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
11
|
+
const common_1 = require("./common");
|
|
12
|
+
const themes_1 = require("./themes");
|
|
13
|
+
function getModuleSwizzleConfig(swizzlePlugin) {
|
|
14
|
+
const getSwizzleConfig = swizzlePlugin.plugin.plugin?.getSwizzleConfig ??
|
|
15
|
+
swizzlePlugin.plugin.pluginModule?.module.getSwizzleConfig ??
|
|
16
|
+
swizzlePlugin.plugin.pluginModule?.module?.getSwizzleConfig;
|
|
17
|
+
if (getSwizzleConfig) {
|
|
18
|
+
return getSwizzleConfig();
|
|
19
|
+
}
|
|
20
|
+
// TODO deprecate getSwizzleComponentList later
|
|
21
|
+
const getSwizzleComponentList = swizzlePlugin.plugin.plugin?.getSwizzleComponentList ??
|
|
22
|
+
swizzlePlugin.plugin.pluginModule?.module.getSwizzleComponentList ??
|
|
23
|
+
swizzlePlugin.plugin.pluginModule?.module?.getSwizzleComponentList;
|
|
24
|
+
if (getSwizzleComponentList) {
|
|
25
|
+
const safeComponents = getSwizzleComponentList() ?? [];
|
|
26
|
+
const safeComponentConfig = {
|
|
27
|
+
actions: {
|
|
28
|
+
eject: 'safe',
|
|
29
|
+
wrap: 'safe',
|
|
30
|
+
},
|
|
31
|
+
description: undefined,
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
components: Object.fromEntries(safeComponents.map((comp) => [comp, safeComponentConfig])),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
function normalizeSwizzleConfig(unsafeSwizzleConfig) {
|
|
40
|
+
const schema = utils_validation_1.Joi.object({
|
|
41
|
+
components: utils_validation_1.Joi.object()
|
|
42
|
+
.pattern(utils_validation_1.Joi.string(), utils_validation_1.Joi.object({
|
|
43
|
+
actions: utils_validation_1.Joi.object().pattern(utils_validation_1.Joi.string().valid(...common_1.SwizzleActions), utils_validation_1.Joi.string().valid(...common_1.SwizzleActionsStatuses)),
|
|
44
|
+
description: utils_validation_1.Joi.string(),
|
|
45
|
+
}))
|
|
46
|
+
.required(),
|
|
47
|
+
});
|
|
48
|
+
const result = schema.validate(unsafeSwizzleConfig);
|
|
49
|
+
if (result.error) {
|
|
50
|
+
throw new Error(`Swizzle config does not match expected schema: ${result.error.message}`);
|
|
51
|
+
}
|
|
52
|
+
const swizzleConfig = result.value;
|
|
53
|
+
// Ensure all components always declare all actions
|
|
54
|
+
Object.values(swizzleConfig.components).forEach((componentConfig) => {
|
|
55
|
+
common_1.SwizzleActions.forEach((action) => {
|
|
56
|
+
if (!componentConfig.actions[action]) {
|
|
57
|
+
componentConfig.actions[action] = 'unsafe';
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
return swizzleConfig;
|
|
62
|
+
}
|
|
63
|
+
exports.normalizeSwizzleConfig = normalizeSwizzleConfig;
|
|
64
|
+
const FallbackSwizzleConfig = {
|
|
65
|
+
components: {},
|
|
66
|
+
};
|
|
67
|
+
function getThemeSwizzleConfig(themeName, plugins) {
|
|
68
|
+
const plugin = (0, themes_1.getPluginByThemeName)(plugins, themeName);
|
|
69
|
+
const config = getModuleSwizzleConfig(plugin);
|
|
70
|
+
if (config) {
|
|
71
|
+
try {
|
|
72
|
+
return normalizeSwizzleConfig(config);
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
throw new Error(`Invalid Swizzle config for theme ${themeName}.\n${e.message}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return FallbackSwizzleConfig;
|
|
79
|
+
}
|
|
80
|
+
exports.getThemeSwizzleConfig = getThemeSwizzleConfig;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { SwizzleContext } from './common';
|
|
8
|
+
export declare function initSwizzleContext(siteDir: string): Promise<SwizzleContext>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.initSwizzleContext = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const server_1 = require("../../server");
|
|
12
|
+
const init_1 = tslib_1.__importStar(require("../../server/plugins/init"));
|
|
13
|
+
async function initSwizzleContext(siteDir) {
|
|
14
|
+
const context = await (0, server_1.loadContext)(siteDir);
|
|
15
|
+
const pluginConfigs = await (0, server_1.loadPluginConfigs)(context);
|
|
16
|
+
const plugins = await (0, init_1.default)({
|
|
17
|
+
pluginConfigs,
|
|
18
|
+
context,
|
|
19
|
+
});
|
|
20
|
+
const pluginsNormalized = await (0, init_1.normalizePluginConfigs)(pluginConfigs, context.siteConfigPath);
|
|
21
|
+
return {
|
|
22
|
+
plugins: plugins.map((plugin, pluginIndex) => ({
|
|
23
|
+
plugin: pluginsNormalized[pluginIndex],
|
|
24
|
+
instance: plugin,
|
|
25
|
+
})),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
exports.initSwizzleContext = initSwizzleContext;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { SwizzleOptions } from './common';
|
|
8
|
+
export default function swizzle(siteDir: string, themeNameParam: string | undefined, componentNameParam: string | undefined, optionsParam: Partial<SwizzleOptions>): Promise<void>;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
11
|
+
const themes_1 = require("./themes");
|
|
12
|
+
const components_1 = require("./components");
|
|
13
|
+
const tables_1 = require("./tables");
|
|
14
|
+
const common_1 = require("./common");
|
|
15
|
+
const actions_1 = require("./actions");
|
|
16
|
+
const config_1 = require("./config");
|
|
17
|
+
const prompts_1 = require("./prompts");
|
|
18
|
+
const context_1 = require("./context");
|
|
19
|
+
async function listAllThemeComponents({ themeNames, plugins, typescript, }) {
|
|
20
|
+
const themeComponentsTables = (await Promise.all(themeNames.map(async (themeName) => {
|
|
21
|
+
const themePath = (0, themes_1.getThemePath)({ themeName, plugins, typescript });
|
|
22
|
+
const swizzleConfig = (0, config_1.getThemeSwizzleConfig)(themeName, plugins);
|
|
23
|
+
const themeComponents = await (0, components_1.getThemeComponents)({
|
|
24
|
+
themeName,
|
|
25
|
+
themePath,
|
|
26
|
+
swizzleConfig,
|
|
27
|
+
});
|
|
28
|
+
return (0, tables_1.themeComponentsTable)(themeComponents);
|
|
29
|
+
}))).join('\n\n');
|
|
30
|
+
logger_1.default.info(`All theme components available to swizzle:
|
|
31
|
+
|
|
32
|
+
${themeComponentsTables}
|
|
33
|
+
|
|
34
|
+
${(0, tables_1.helpTables)()}
|
|
35
|
+
`);
|
|
36
|
+
return process.exit(0);
|
|
37
|
+
}
|
|
38
|
+
async function ensureActionSafety({ componentName, componentConfig, action, danger, }) {
|
|
39
|
+
const actionStatus = componentConfig.actions[action];
|
|
40
|
+
if (actionStatus === 'forbidden') {
|
|
41
|
+
logger_1.default.error `
|
|
42
|
+
Swizzle action name=${action} is forbidden for component name=${componentName}
|
|
43
|
+
`;
|
|
44
|
+
return process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
if (actionStatus === 'unsafe' && !danger) {
|
|
47
|
+
logger_1.default.warn `
|
|
48
|
+
Swizzle action name=${action} is unsafe to perform on name=${componentName}.
|
|
49
|
+
It is more likely to be affected by breaking changes in the future
|
|
50
|
+
If you want to swizzle it, use the code=${'--danger'} flag, or confirm that you understand the risks.
|
|
51
|
+
`;
|
|
52
|
+
const swizzleDangerousComponent = await (0, prompts_1.askSwizzleDangerousComponent)();
|
|
53
|
+
if (!swizzleDangerousComponent) {
|
|
54
|
+
return process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
async function swizzle(siteDir, themeNameParam, componentNameParam, optionsParam) {
|
|
60
|
+
const options = (0, common_1.normalizeOptions)(optionsParam);
|
|
61
|
+
const { list, danger, typescript } = options;
|
|
62
|
+
const { plugins } = await (0, context_1.initSwizzleContext)(siteDir);
|
|
63
|
+
const themeNames = (0, themes_1.getThemeNames)(plugins);
|
|
64
|
+
if (list && !themeNameParam) {
|
|
65
|
+
await listAllThemeComponents({ themeNames, plugins, typescript });
|
|
66
|
+
}
|
|
67
|
+
const themeName = await (0, themes_1.getThemeName)({ themeNameParam, themeNames, list });
|
|
68
|
+
const themePath = (0, themes_1.getThemePath)({ themeName, plugins, typescript });
|
|
69
|
+
const swizzleConfig = (0, config_1.getThemeSwizzleConfig)(themeName, plugins);
|
|
70
|
+
const themeComponents = await (0, components_1.getThemeComponents)({
|
|
71
|
+
themeName,
|
|
72
|
+
themePath,
|
|
73
|
+
swizzleConfig,
|
|
74
|
+
});
|
|
75
|
+
const componentName = await (0, components_1.getComponentName)({
|
|
76
|
+
componentNameParam,
|
|
77
|
+
themeComponents,
|
|
78
|
+
list,
|
|
79
|
+
});
|
|
80
|
+
const componentConfig = themeComponents.getConfig(componentName);
|
|
81
|
+
const action = await (0, actions_1.getAction)(componentConfig, options);
|
|
82
|
+
await ensureActionSafety({ componentName, componentConfig, action, danger });
|
|
83
|
+
async function executeAction() {
|
|
84
|
+
switch (action) {
|
|
85
|
+
case 'wrap': {
|
|
86
|
+
const result = await (0, actions_1.wrap)({
|
|
87
|
+
siteDir,
|
|
88
|
+
themePath,
|
|
89
|
+
componentName,
|
|
90
|
+
typescript,
|
|
91
|
+
});
|
|
92
|
+
logger_1.default.success `
|
|
93
|
+
Created wrapper of name=${componentName} from name=${themeName} in path=${result.createdFiles}.
|
|
94
|
+
`;
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
case 'eject': {
|
|
98
|
+
const result = await (0, actions_1.eject)({
|
|
99
|
+
siteDir,
|
|
100
|
+
themePath,
|
|
101
|
+
componentName,
|
|
102
|
+
});
|
|
103
|
+
logger_1.default.success `
|
|
104
|
+
Ejected name=${componentName} from name=${themeName} to path=${result.createdFiles}.
|
|
105
|
+
`;
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
default:
|
|
109
|
+
throw new Error(`Unexpected action ${action}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
await executeAction();
|
|
113
|
+
return process.exit(0);
|
|
114
|
+
}
|
|
115
|
+
exports.default = swizzle;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { ThemeComponents } from './components';
|
|
8
|
+
import type { SwizzleAction, SwizzleComponentConfig } from '@docusaurus/types';
|
|
9
|
+
export declare function askThemeName(themeNames: string[]): Promise<string>;
|
|
10
|
+
export declare function askComponentName(themeComponents: ThemeComponents): Promise<string>;
|
|
11
|
+
export declare function askSwizzleDangerousComponent(): Promise<boolean>;
|
|
12
|
+
export declare function askSwizzleAction(componentConfig: SwizzleComponentConfig): Promise<SwizzleAction>;
|