@docusaurus/core 2.0.0-beta.ff31de0ff → 2.0.1
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/README.md +1 -0
- package/bin/beforeCli.mjs +140 -0
- package/bin/docusaurus.mjs +223 -0
- package/lib/babel/preset.d.ts +8 -3
- package/lib/babel/preset.js +10 -8
- package/lib/client/App.d.ts +2 -3
- package/lib/client/App.js +31 -28
- package/lib/client/BaseUrlIssueBanner/index.d.ts +27 -0
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +25 -14
- package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
- package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
- package/lib/client/ClientLifecyclesDispatcher.js +39 -0
- package/lib/client/LinksCollector.d.ts +3 -3
- package/lib/client/LinksCollector.js +8 -13
- package/lib/client/PendingNavigation.d.ts +17 -3
- package/lib/client/PendingNavigation.js +47 -72
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → SiteMetadataDefaults.d.ts} +1 -2
- package/lib/client/SiteMetadataDefaults.js +21 -0
- package/lib/{choosePort.d.ts → client/browserContext.d.ts} +5 -5
- package/lib/client/browserContext.js +22 -0
- package/lib/client/clientEntry.js +14 -9
- package/lib/client/docusaurus.d.ts +12 -6
- package/lib/client/docusaurus.js +30 -43
- package/lib/client/docusaurusContext.d.ts +12 -0
- package/lib/client/docusaurusContext.js +25 -0
- package/lib/client/exports/BrowserOnly.d.ts +3 -5
- package/lib/client/exports/BrowserOnly.js +14 -7
- package/lib/client/exports/ComponentCreator.d.ts +6 -2
- package/lib/client/exports/ComponentCreator.js +75 -42
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +37 -0
- package/lib/client/exports/ExecutionEnvironment.js +7 -8
- 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 -49
- package/lib/client/exports/Link.d.ts +4 -10
- package/lib/client/exports/Link.js +44 -38
- 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 +11 -14
- 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 +8 -15
- 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/client/exports/useRouteContext.d.ts +8 -0
- package/lib/client/exports/useRouteContext.js +15 -0
- package/lib/client/flat.d.ts +12 -2
- package/lib/client/flat.js +19 -15
- package/lib/client/normalizeLocation.d.ts +2 -5
- package/lib/client/normalizeLocation.js +14 -10
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +12 -32
- package/lib/client/preload.d.ts +3 -4
- package/lib/client/preload.js +5 -12
- 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 +109 -136
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +45 -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 +50 -116
- package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
- package/lib/client/theme-fallback/NotFound/index.js +19 -18
- package/lib/client/theme-fallback/Root/index.d.ts +10 -0
- package/lib/client/theme-fallback/Root/index.js +2 -6
- package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/SiteMetadata/index.d.ts} +2 -1
- package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
- package/lib/commands/build.d.ts +6 -2
- package/lib/commands/build.js +81 -64
- package/lib/commands/clear.d.ts +7 -1
- package/lib/commands/clear.js +34 -21
- package/lib/commands/deploy.d.ts +5 -2
- package/lib/commands/deploy.js +102 -81
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +9 -11
- package/lib/commands/serve.d.ts +8 -2
- package/lib/commands/serve.js +40 -20
- package/lib/commands/start.d.ts +9 -2
- package/lib/commands/start.js +111 -101
- package/lib/commands/swizzle/actions.d.ts +23 -0
- package/lib/commands/swizzle/actions.js +106 -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 +200 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +84 -0
- package/lib/{server/client-modules/index.d.ts → commands/swizzle/context.d.ts} +2 -2
- package/lib/commands/swizzle/context.js +24 -0
- package/lib/commands/swizzle/index.d.ts +8 -0
- package/lib/commands/swizzle/index.js +119 -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 +22 -81
- package/lib/commands/writeTranslations.d.ts +4 -5
- package/lib/commands/writeTranslations.js +48 -28
- package/lib/index.d.ts +9 -9
- package/lib/index.js +14 -14
- package/lib/server/brokenLinks.d.ts +4 -17
- package/lib/server/brokenLinks.js +67 -56
- package/lib/server/clientModules.d.ts +12 -0
- package/lib/server/clientModules.js +20 -0
- package/lib/server/config.d.ts +5 -2
- package/lib/server/config.js +29 -6
- package/lib/server/configValidation.d.ts +5 -3
- package/lib/server/configValidation.js +105 -44
- package/lib/server/getHostPort.d.ts +14 -0
- package/lib/server/getHostPort.js +79 -0
- package/lib/server/htmlTags.d.ts +12 -0
- package/lib/server/htmlTags.js +62 -0
- package/lib/server/i18n.d.ts +3 -13
- package/lib/server/i18n.js +21 -55
- package/lib/server/index.d.ts +28 -6
- package/lib/server/index.js +86 -173
- package/lib/server/plugins/configs.d.ts +51 -0
- package/lib/server/plugins/configs.js +101 -0
- package/lib/server/plugins/index.d.ts +10 -10
- package/lib/server/plugins/index.js +76 -128
- package/lib/server/plugins/init.d.ts +6 -9
- package/lib/server/plugins/init.js +44 -109
- package/lib/server/plugins/moduleShorthand.d.ts +9 -0
- package/lib/server/plugins/moduleShorthand.js +46 -0
- package/lib/server/plugins/pluginIds.d.ts +6 -2
- package/lib/server/plugins/pluginIds.js +12 -7
- package/lib/server/plugins/presets.d.ts +12 -0
- package/lib/server/plugins/presets.js +49 -0
- package/lib/server/plugins/routeConfig.d.ts +11 -0
- package/lib/server/plugins/routeConfig.js +54 -0
- package/lib/server/plugins/synthetic.d.ts +20 -0
- package/lib/server/plugins/synthetic.js +111 -0
- package/lib/server/routes.d.ts +39 -7
- package/lib/server/routes.js +182 -95
- package/lib/server/siteMetadata.d.ts +12 -0
- package/lib/server/siteMetadata.js +81 -0
- package/lib/server/translations/translations.d.ts +16 -22
- package/lib/server/translations/translations.js +41 -73
- package/lib/server/translations/translationsExtractor.d.ts +10 -5
- package/lib/server/translations/translationsExtractor.js +158 -122
- package/lib/server/utils.d.ts +9 -3
- package/lib/server/utils.js +7 -9
- package/lib/webpack/aliases/index.d.ts +34 -0
- package/lib/webpack/aliases/index.js +106 -0
- package/lib/webpack/base.d.ts +3 -4
- package/lib/webpack/base.js +56 -58
- 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 -25
- package/lib/webpack/plugins/CleanWebpackPlugin.js +34 -18
- package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
- package/lib/webpack/plugins/LogPlugin.js +4 -5
- package/lib/webpack/plugins/WaitPlugin.d.ts +3 -3
- package/lib/webpack/plugins/WaitPlugin.js +1 -1
- package/lib/webpack/server.d.ts +5 -5
- package/lib/webpack/server.js +23 -8
- 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 +16 -31
- package/lib/webpack/utils.js +63 -183
- package/package.json +83 -77
- package/bin/docusaurus.js +0 -326
- package/lib/.tsbuildinfo +0 -5682
- package/lib/choosePort.js +0 -105
- package/lib/client/.eslintrc.js +0 -29
- package/lib/client/.tsbuildinfo +0 -4127
- package/lib/client/client-lifecycles-dispatcher.d.ts +0 -12
- package/lib/client/client-lifecycles-dispatcher.js +0 -27
- package/lib/client/nprogress.css +0 -36
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- package/lib/commands/commandUtils.d.ts +0 -3
- package/lib/commands/commandUtils.js +0 -21
- 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/client-modules/index.js +0 -14
- package/lib/server/duplicateRoutes.d.ts +0 -10
- package/lib/server/duplicateRoutes.js +0 -38
- package/lib/server/html-tags/htmlTags.js +0 -39
- package/lib/server/html-tags/index.d.ts +0 -9
- package/lib/server/html-tags/index.js +0 -43
- package/lib/server/loadSetup.d.ts +0 -9
- package/lib/server/loadSetup.js +0 -25
- package/lib/server/presets/index.d.ts +0 -11
- package/lib/server/presets/index.js +0 -48
- package/lib/server/themes/alias.d.ts +0 -8
- package/lib/server/themes/alias.js +0 -39
- package/lib/server/themes/index.d.ts +0 -8
- package/lib/server/themes/index.js +0 -35
- 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/server/versions/index.d.ts +0 -10
- package/lib/server/versions/index.js +0 -50
- 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.d.ts +0 -10
- package/lib/webpack/sharedModuleAliases.js +0 -18
- package/tsconfig.client.json +0 -13
- package/tsconfig.json +0 -13
package/lib/commands/external.js
CHANGED
|
@@ -6,20 +6,18 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.externalCommand = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
11
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
10
12
|
const server_1 = require("../server");
|
|
11
|
-
const init_1 =
|
|
12
|
-
async function externalCommand(cli
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const plugins = init_1.
|
|
13
|
+
const init_1 = require("../server/plugins/init");
|
|
14
|
+
async function externalCommand(cli) {
|
|
15
|
+
const siteDir = await fs_extra_1.default.realpath('.');
|
|
16
|
+
const context = await (0, server_1.loadContext)({ siteDir });
|
|
17
|
+
const plugins = await (0, init_1.initPlugins)(context);
|
|
16
18
|
// Plugin Lifecycle - extendCli.
|
|
17
19
|
plugins.forEach((plugin) => {
|
|
18
|
-
|
|
19
|
-
if (!extendCli) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
extendCli(cli);
|
|
20
|
+
plugin.extendCli?.(cli);
|
|
23
21
|
});
|
|
24
22
|
}
|
|
25
|
-
exports.
|
|
23
|
+
exports.externalCommand = externalCommand;
|
package/lib/commands/serve.d.ts
CHANGED
|
@@ -4,5 +4,11 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import { type HostPortOptions } from '../server/getHostPort';
|
|
8
|
+
import type { LoadContextOptions } from '../server';
|
|
9
|
+
export declare type ServeCLIOptions = HostPortOptions & Pick<LoadContextOptions, 'config'> & {
|
|
10
|
+
dir?: string;
|
|
11
|
+
build?: boolean;
|
|
12
|
+
open?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare function serve(siteDirParam?: string, cliOptions?: Partial<ServeCLIOptions>): Promise<void>;
|
package/lib/commands/serve.js
CHANGED
|
@@ -6,41 +6,61 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.serve = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
11
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
10
12
|
const http_1 = tslib_1.__importDefault(require("http"));
|
|
11
|
-
const serve_handler_1 = tslib_1.__importDefault(require("serve-handler"));
|
|
12
|
-
const boxen_1 = tslib_1.__importDefault(require("boxen"));
|
|
13
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
14
13
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
15
|
+
const utils_1 = require("@docusaurus/utils");
|
|
16
|
+
const serve_handler_1 = tslib_1.__importDefault(require("serve-handler"));
|
|
17
|
+
const openBrowser_1 = tslib_1.__importDefault(require("react-dev-utils/openBrowser"));
|
|
18
|
+
const config_1 = require("../server/config");
|
|
19
|
+
const build_1 = require("./build");
|
|
20
|
+
const getHostPort_1 = require("../server/getHostPort");
|
|
21
|
+
async function serve(siteDirParam = '.', cliOptions = {}) {
|
|
22
|
+
const siteDir = await fs_extra_1.default.realpath(siteDirParam);
|
|
23
|
+
const buildDir = cliOptions.dir ?? utils_1.DEFAULT_BUILD_DIR_NAME;
|
|
24
|
+
let dir = path_1.default.resolve(siteDir, buildDir);
|
|
21
25
|
if (cliOptions.build) {
|
|
22
|
-
dir = await build_1.
|
|
26
|
+
dir = await (0, build_1.build)(siteDir, {
|
|
23
27
|
config: cliOptions.config,
|
|
24
28
|
outDir: dir,
|
|
25
29
|
}, false);
|
|
26
30
|
}
|
|
27
|
-
const host =
|
|
28
|
-
const port = await commandUtils_1.getCLIOptionPort(cliOptions.port, host);
|
|
31
|
+
const { host, port } = await (0, getHostPort_1.getHostPort)(cliOptions);
|
|
29
32
|
if (port === null) {
|
|
30
33
|
process.exit();
|
|
31
34
|
}
|
|
35
|
+
const { siteConfig: { baseUrl, trailingSlash }, } = await (0, config_1.loadSiteConfig)({
|
|
36
|
+
siteDir,
|
|
37
|
+
customConfigFilePath: cliOptions.config,
|
|
38
|
+
});
|
|
39
|
+
const servingUrl = `http://${host}:${port}`;
|
|
32
40
|
const server = http_1.default.createServer((req, res) => {
|
|
33
|
-
|
|
41
|
+
// Automatically redirect requests to /baseUrl/
|
|
42
|
+
if (!req.url?.startsWith(baseUrl)) {
|
|
43
|
+
res.writeHead(302, {
|
|
44
|
+
Location: baseUrl,
|
|
45
|
+
});
|
|
46
|
+
res.end();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
// Remove baseUrl before calling serveHandler, because /baseUrl/ should
|
|
50
|
+
// serve /build/index.html, not /build/baseUrl/index.html (does not exist)
|
|
51
|
+
req.url = req.url.replace(baseUrl, '/');
|
|
52
|
+
(0, serve_handler_1.default)(req, res, {
|
|
34
53
|
cleanUrls: true,
|
|
35
54
|
public: dir,
|
|
55
|
+
trailingSlash,
|
|
56
|
+
directoryListing: false,
|
|
36
57
|
});
|
|
37
58
|
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
padding: 1,
|
|
41
|
-
margin: 1,
|
|
42
|
-
align: 'center',
|
|
43
|
-
}));
|
|
59
|
+
const url = servingUrl + baseUrl;
|
|
60
|
+
logger_1.default.success `Serving path=${buildDir} directory at: url=${url}`;
|
|
44
61
|
server.listen(port);
|
|
62
|
+
if (cliOptions.open && !process.env.CI) {
|
|
63
|
+
(0, openBrowser_1.default)(url);
|
|
64
|
+
}
|
|
45
65
|
}
|
|
46
|
-
exports.
|
|
66
|
+
exports.serve = serve;
|
package/lib/commands/start.d.ts
CHANGED
|
@@ -4,5 +4,12 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import { type LoadContextOptions } from '../server';
|
|
8
|
+
import { type HostPortOptions } from '../server/getHostPort';
|
|
9
|
+
export declare type StartCLIOptions = HostPortOptions & Pick<LoadContextOptions, 'locale' | 'config'> & {
|
|
10
|
+
hotOnly?: boolean;
|
|
11
|
+
open?: boolean;
|
|
12
|
+
poll?: boolean | number;
|
|
13
|
+
minify?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare function start(siteDirParam?: string, cliOptions?: Partial<StartCLIOptions>): Promise<void>;
|
package/lib/commands/start.js
CHANGED
|
@@ -6,97 +6,100 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.start = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
11
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
13
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
14
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
10
15
|
const utils_1 = require("@docusaurus/utils");
|
|
11
|
-
const chalk = require("chalk");
|
|
12
16
|
const chokidar_1 = tslib_1.__importDefault(require("chokidar"));
|
|
13
|
-
const express_1 = tslib_1.__importDefault(require("express"));
|
|
14
17
|
const html_webpack_plugin_1 = tslib_1.__importDefault(require("html-webpack-plugin"));
|
|
15
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
16
|
-
const lodash_1 = require("lodash");
|
|
17
18
|
const openBrowser_1 = tslib_1.__importDefault(require("react-dev-utils/openBrowser"));
|
|
18
19
|
const WebpackDevServerUtils_1 = require("react-dev-utils/WebpackDevServerUtils");
|
|
19
|
-
const
|
|
20
|
-
// import evalSourceMapMiddleware from 'react-dev-utils/evalSourceMapMiddleware';
|
|
21
|
-
const evalSourceMapMiddleware_1 = tslib_1.__importDefault(require("../webpack/react-dev-utils-webpack5/evalSourceMapMiddleware"));
|
|
20
|
+
const evalSourceMapMiddleware_1 = tslib_1.__importDefault(require("react-dev-utils/evalSourceMapMiddleware"));
|
|
22
21
|
const webpack_1 = tslib_1.__importDefault(require("webpack"));
|
|
23
22
|
const webpack_dev_server_1 = tslib_1.__importDefault(require("webpack-dev-server"));
|
|
24
23
|
const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
|
|
25
|
-
const HotModuleReplacementPlugin_1 = tslib_1.__importDefault(require("webpack/lib/HotModuleReplacementPlugin"));
|
|
26
24
|
const server_1 = require("../server");
|
|
27
|
-
const constants_1 = require("../constants");
|
|
28
25
|
const client_1 = tslib_1.__importDefault(require("../webpack/client"));
|
|
29
26
|
const utils_2 = require("../webpack/utils");
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
const getHostPort_1 = require("../server/getHostPort");
|
|
28
|
+
async function start(siteDirParam = '.', cliOptions = {}) {
|
|
29
|
+
const siteDir = await fs_extra_1.default.realpath(siteDirParam);
|
|
33
30
|
process.env.NODE_ENV = 'development';
|
|
34
31
|
process.env.BABEL_ENV = 'development';
|
|
35
|
-
|
|
32
|
+
logger_1.default.info('Starting the development server...');
|
|
36
33
|
function loadSite() {
|
|
37
|
-
return server_1.load(
|
|
38
|
-
|
|
34
|
+
return (0, server_1.load)({
|
|
35
|
+
siteDir,
|
|
36
|
+
config: cliOptions.config,
|
|
39
37
|
locale: cliOptions.locale,
|
|
40
|
-
localizePath: undefined, //
|
|
38
|
+
localizePath: undefined, // Should this be configurable?
|
|
41
39
|
});
|
|
42
40
|
}
|
|
43
41
|
// Process all related files as a prop.
|
|
44
42
|
const props = await loadSite();
|
|
45
43
|
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
|
46
|
-
const host =
|
|
47
|
-
const port = await commandUtils_1.getCLIOptionPort(cliOptions.port, host);
|
|
44
|
+
const { host, port } = await (0, getHostPort_1.getHostPort)(cliOptions);
|
|
48
45
|
if (port === null) {
|
|
49
46
|
process.exit();
|
|
50
47
|
}
|
|
51
48
|
const { baseUrl, headTags, preBodyTags, postBodyTags } = props;
|
|
52
|
-
const urls = WebpackDevServerUtils_1.prepareUrls(protocol, host, port);
|
|
53
|
-
const openUrl = utils_1.normalizeUrl([urls.localUrlForBrowser, baseUrl]);
|
|
54
|
-
|
|
49
|
+
const urls = (0, WebpackDevServerUtils_1.prepareUrls)(protocol, host, port);
|
|
50
|
+
const openUrl = (0, utils_1.normalizeUrl)([urls.localUrlForBrowser, baseUrl]);
|
|
51
|
+
logger_1.default.success `Docusaurus website is running at: url=${openUrl}`;
|
|
55
52
|
// Reload files processing.
|
|
56
|
-
const reload = lodash_1.debounce(() => {
|
|
53
|
+
const reload = lodash_1.default.debounce(() => {
|
|
57
54
|
loadSite()
|
|
58
55
|
.then(({ baseUrl: newBaseUrl }) => {
|
|
59
|
-
const newOpenUrl = utils_1.normalizeUrl([urls.localUrlForBrowser, newBaseUrl]);
|
|
60
|
-
|
|
56
|
+
const newOpenUrl = (0, utils_1.normalizeUrl)([urls.localUrlForBrowser, newBaseUrl]);
|
|
57
|
+
if (newOpenUrl !== openUrl) {
|
|
58
|
+
logger_1.default.success `Docusaurus website is running at: url=${newOpenUrl}`;
|
|
59
|
+
}
|
|
61
60
|
})
|
|
62
61
|
.catch((err) => {
|
|
63
|
-
|
|
62
|
+
logger_1.default.error(err.stack);
|
|
64
63
|
});
|
|
65
64
|
}, 500);
|
|
66
|
-
const { siteConfig, plugins
|
|
65
|
+
const { siteConfig, plugins, localizationDir } = props;
|
|
67
66
|
const normalizeToSiteDir = (filepath) => {
|
|
68
67
|
if (filepath && path_1.default.isAbsolute(filepath)) {
|
|
69
|
-
return utils_1.posixPath(path_1.default.relative(siteDir, filepath));
|
|
68
|
+
return (0, utils_1.posixPath)(path_1.default.relative(siteDir, filepath));
|
|
70
69
|
}
|
|
71
|
-
return utils_1.posixPath(filepath);
|
|
70
|
+
return (0, utils_1.posixPath)(filepath);
|
|
72
71
|
};
|
|
73
|
-
const pluginPaths =
|
|
74
|
-
.
|
|
75
|
-
.
|
|
76
|
-
.filter(Boolean))
|
|
72
|
+
const pluginPaths = plugins
|
|
73
|
+
.flatMap((plugin) => plugin.getPathsToWatch?.() ?? [])
|
|
74
|
+
.filter(Boolean)
|
|
77
75
|
.map(normalizeToSiteDir);
|
|
78
|
-
const pathsToWatch = [
|
|
79
|
-
|
|
80
|
-
props.siteConfigPath,
|
|
81
|
-
translations_1.getTranslationsLocaleDirPath({
|
|
82
|
-
siteDir,
|
|
83
|
-
locale: props.i18n.currentLocale,
|
|
84
|
-
}),
|
|
85
|
-
];
|
|
86
|
-
const fsWatcher = chokidar_1.default.watch(pathsToWatch, {
|
|
87
|
-
cwd: siteDir,
|
|
88
|
-
ignoreInitial: true,
|
|
76
|
+
const pathsToWatch = [...pluginPaths, props.siteConfigPath, localizationDir];
|
|
77
|
+
const pollingOptions = {
|
|
89
78
|
usePolling: !!cliOptions.poll,
|
|
90
79
|
interval: Number.isInteger(cliOptions.poll)
|
|
91
80
|
? cliOptions.poll
|
|
92
81
|
: undefined,
|
|
82
|
+
};
|
|
83
|
+
const httpsConfig = await (0, utils_2.getHttpsConfig)();
|
|
84
|
+
const fsWatcher = chokidar_1.default.watch(pathsToWatch, {
|
|
85
|
+
cwd: siteDir,
|
|
86
|
+
ignoreInitial: true,
|
|
87
|
+
...{ pollingOptions },
|
|
93
88
|
});
|
|
94
89
|
['add', 'change', 'unlink', 'addDir', 'unlinkDir'].forEach((event) => fsWatcher.on(event, reload));
|
|
95
|
-
let config = webpack_merge_1.default(client_1.default(props), {
|
|
90
|
+
let config = (0, webpack_merge_1.default)(await (0, client_1.default)(props, cliOptions.minify), {
|
|
91
|
+
watchOptions: {
|
|
92
|
+
ignored: /node_modules\/(?!@docusaurus)/,
|
|
93
|
+
poll: cliOptions.poll,
|
|
94
|
+
},
|
|
95
|
+
infrastructureLogging: {
|
|
96
|
+
// Reduce log verbosity, see https://github.com/facebook/docusaurus/pull/5420#issuecomment-906613105
|
|
97
|
+
level: 'warn',
|
|
98
|
+
},
|
|
96
99
|
plugins: [
|
|
97
100
|
// Generates an `index.html` file with the <script> injected.
|
|
98
101
|
new html_webpack_plugin_1.default({
|
|
99
|
-
template: path_1.default.
|
|
102
|
+
template: path_1.default.join(__dirname, '../webpack/templates/index.html.template.ejs'),
|
|
100
103
|
// So we can define the position where the scripts are injected.
|
|
101
104
|
inject: false,
|
|
102
105
|
filename: 'index.html',
|
|
@@ -105,86 +108,93 @@ async function start(siteDir, cliOptions) {
|
|
|
105
108
|
preBodyTags,
|
|
106
109
|
postBodyTags,
|
|
107
110
|
}),
|
|
108
|
-
// This is necessary to emit hot updates for webpack-dev-server.
|
|
109
|
-
new HotModuleReplacementPlugin_1.default(),
|
|
110
111
|
],
|
|
111
112
|
});
|
|
112
113
|
// Plugin Lifecycle - configureWebpack and configurePostCss.
|
|
113
114
|
plugins.forEach((plugin) => {
|
|
114
|
-
var _a;
|
|
115
115
|
const { configureWebpack, configurePostCss } = plugin;
|
|
116
116
|
if (configurePostCss) {
|
|
117
|
-
config = utils_2.applyConfigurePostCss(configurePostCss, config);
|
|
117
|
+
config = (0, utils_2.applyConfigurePostCss)(configurePostCss.bind(plugin), config);
|
|
118
118
|
}
|
|
119
119
|
if (configureWebpack) {
|
|
120
|
-
config = utils_2.applyConfigureWebpack(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
|
|
121
|
-
config, false,
|
|
120
|
+
config = (0, utils_2.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
|
|
121
|
+
config, false, props.siteConfig.webpack?.jsLoader, plugin.content);
|
|
122
122
|
}
|
|
123
123
|
});
|
|
124
|
-
|
|
125
|
-
const devServerConfig = {
|
|
126
|
-
...{
|
|
127
|
-
compress: true,
|
|
128
|
-
clientLogLevel: 'error',
|
|
129
|
-
hot: true,
|
|
130
|
-
hotOnly: cliOptions.hotOnly,
|
|
131
|
-
// Use 'ws' instead of 'sockjs-node' on server since we're using native
|
|
132
|
-
// websockets in `webpackHotDevClient`.
|
|
133
|
-
transportMode: 'ws',
|
|
134
|
-
// Prevent a WS client from getting injected as we're already including
|
|
135
|
-
// `webpackHotDevClient`.
|
|
136
|
-
injectClient: false,
|
|
137
|
-
quiet: true,
|
|
138
|
-
https: utils_2.getHttpsConfig(),
|
|
139
|
-
headers: {
|
|
140
|
-
'access-control-allow-origin': '*',
|
|
141
|
-
},
|
|
142
|
-
publicPath: baseUrl,
|
|
143
|
-
watchOptions: {
|
|
144
|
-
ignored: /node_modules/,
|
|
145
|
-
poll: cliOptions.poll,
|
|
146
|
-
},
|
|
147
|
-
historyApiFallback: {
|
|
148
|
-
rewrites: [{ from: /\/*/, to: baseUrl }],
|
|
149
|
-
},
|
|
150
|
-
disableHostCheck: true,
|
|
151
|
-
// Disable overlay on browser since we use CRA's overlay error reporting.
|
|
152
|
-
overlay: false,
|
|
153
|
-
host,
|
|
154
|
-
before: (app, server) => {
|
|
155
|
-
app.use(baseUrl, express_1.default.static(path_1.default.resolve(siteDir, constants_1.STATIC_DIR_NAME)));
|
|
156
|
-
// This lets us fetch source contents from webpack for the error overlay.
|
|
157
|
-
app.use(evalSourceMapMiddleware_1.default(server));
|
|
158
|
-
// This lets us open files from the runtime error overlay.
|
|
159
|
-
app.use(errorOverlayMiddleware_1.default());
|
|
160
|
-
},
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
const compiler = webpack_1.default(config);
|
|
124
|
+
const compiler = (0, webpack_1.default)(config);
|
|
164
125
|
if (process.env.E2E_TEST) {
|
|
165
126
|
compiler.hooks.done.tap('done', (stats) => {
|
|
166
127
|
if (stats.hasErrors()) {
|
|
167
|
-
|
|
128
|
+
logger_1.default.error('E2E_TEST: Project has compiler errors.');
|
|
168
129
|
process.exit(1);
|
|
169
130
|
}
|
|
170
|
-
|
|
131
|
+
logger_1.default.success('E2E_TEST: Project can compile.');
|
|
171
132
|
process.exit(0);
|
|
172
133
|
});
|
|
173
134
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
135
|
+
// https://webpack.js.org/configuration/dev-server
|
|
136
|
+
const defaultDevServerConfig = {
|
|
137
|
+
hot: cliOptions.hotOnly ? 'only' : true,
|
|
138
|
+
liveReload: false,
|
|
139
|
+
client: {
|
|
140
|
+
progress: true,
|
|
141
|
+
overlay: {
|
|
142
|
+
warnings: false,
|
|
143
|
+
errors: true,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
headers: {
|
|
147
|
+
'access-control-allow-origin': '*',
|
|
148
|
+
},
|
|
149
|
+
devMiddleware: {
|
|
150
|
+
publicPath: baseUrl,
|
|
151
|
+
// Reduce log verbosity, see https://github.com/facebook/docusaurus/pull/5420#issuecomment-906613105
|
|
152
|
+
stats: 'summary',
|
|
153
|
+
},
|
|
154
|
+
static: siteConfig.staticDirectories.map((dir) => ({
|
|
155
|
+
publicPath: baseUrl,
|
|
156
|
+
directory: path_1.default.resolve(siteDir, dir),
|
|
157
|
+
watch: {
|
|
158
|
+
// Useful options for our own monorepo using symlinks!
|
|
159
|
+
// See https://github.com/webpack/webpack/issues/11612#issuecomment-879259806
|
|
160
|
+
followSymlinks: true,
|
|
161
|
+
ignored: /node_modules\/(?!@docusaurus)/,
|
|
162
|
+
...{ pollingOptions },
|
|
163
|
+
},
|
|
164
|
+
})),
|
|
165
|
+
...(httpsConfig && {
|
|
166
|
+
server: typeof httpsConfig === 'object'
|
|
167
|
+
? {
|
|
168
|
+
type: 'https',
|
|
169
|
+
options: httpsConfig,
|
|
170
|
+
}
|
|
171
|
+
: 'https',
|
|
172
|
+
}),
|
|
173
|
+
historyApiFallback: {
|
|
174
|
+
rewrites: [{ from: /\/*/, to: baseUrl }],
|
|
175
|
+
},
|
|
176
|
+
allowedHosts: 'all',
|
|
177
|
+
host,
|
|
178
|
+
port,
|
|
179
|
+
setupMiddlewares: (middlewares, devServer) => {
|
|
180
|
+
// This lets us fetch source contents from webpack for the error overlay.
|
|
181
|
+
middlewares.unshift((0, evalSourceMapMiddleware_1.default)(devServer));
|
|
182
|
+
return middlewares;
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
// Allow plugin authors to customize/override devServer config
|
|
186
|
+
const devServerConfig = (0, webpack_merge_1.default)([defaultDevServerConfig, config.devServer].filter(Boolean));
|
|
187
|
+
const devServer = new webpack_dev_server_1.default(devServerConfig, compiler);
|
|
188
|
+
devServer.startCallback(() => {
|
|
179
189
|
if (cliOptions.open) {
|
|
180
|
-
openBrowser_1.default(openUrl);
|
|
190
|
+
(0, openBrowser_1.default)(openUrl);
|
|
181
191
|
}
|
|
182
192
|
});
|
|
183
193
|
['SIGINT', 'SIGTERM'].forEach((sig) => {
|
|
184
194
|
process.on(sig, () => {
|
|
185
|
-
devServer.
|
|
195
|
+
devServer.stop();
|
|
186
196
|
process.exit();
|
|
187
197
|
});
|
|
188
198
|
});
|
|
189
199
|
}
|
|
190
|
-
exports.
|
|
200
|
+
exports.start = start;
|
|
@@ -0,0 +1,23 @@
|
|
|
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, SwizzleComponentConfig } from '@docusaurus/types';
|
|
8
|
+
import type { SwizzleCLIOptions } from './common';
|
|
9
|
+
export declare const SwizzleActions: SwizzleAction[];
|
|
10
|
+
export declare function getAction(componentConfig: SwizzleComponentConfig, options: Pick<SwizzleCLIOptions, 'wrap' | 'eject'>): Promise<SwizzleAction>;
|
|
11
|
+
export declare type ActionParams = {
|
|
12
|
+
siteDir: string;
|
|
13
|
+
themePath: string;
|
|
14
|
+
componentName: string;
|
|
15
|
+
typescript: boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare type ActionResult = {
|
|
18
|
+
createdFiles: string[];
|
|
19
|
+
};
|
|
20
|
+
export declare function eject({ siteDir, themePath, componentName, typescript, }: ActionParams): Promise<ActionResult>;
|
|
21
|
+
export declare function wrap({ siteDir, themePath, componentName: themeComponentName, typescript, importType, }: ActionParams & {
|
|
22
|
+
importType?: 'original' | 'init';
|
|
23
|
+
}): Promise<ActionResult>;
|
|
@@ -0,0 +1,106 @@
|
|
|
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 fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
13
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
14
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
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, typescript, }) {
|
|
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: lodash_1.default.compact([
|
|
41
|
+
'**/*.{story,stories,test,tests}.{js,jsx,ts,tsx}',
|
|
42
|
+
// When ejecting JS components, we want to avoid emitting TS files
|
|
43
|
+
// In particular the .d.ts files that theme build output contains
|
|
44
|
+
typescript ? null : '**/*.{d.ts,ts,tsx}',
|
|
45
|
+
]),
|
|
46
|
+
});
|
|
47
|
+
if (filesToCopy.length === 0) {
|
|
48
|
+
// This should never happen
|
|
49
|
+
throw new Error(logger_1.default.interpolate `No files to copy from path=${fromPath} with glob code=${globPatternPosix}`);
|
|
50
|
+
}
|
|
51
|
+
const toPath = path_1.default.join(siteDir, utils_1.THEME_PATH);
|
|
52
|
+
await fs_extra_1.default.ensureDir(toPath);
|
|
53
|
+
const createdFiles = await Promise.all(filesToCopy.map(async (sourceFile) => {
|
|
54
|
+
const targetFile = path_1.default.join(toPath, path_1.default.relative(themePath, sourceFile));
|
|
55
|
+
try {
|
|
56
|
+
const fileContents = await fs_extra_1.default.readFile(sourceFile, 'utf-8');
|
|
57
|
+
await fs_extra_1.default.outputFile(targetFile, fileContents.trimStart().replace(/^\/\*.+?\*\/\s*/ms, ''));
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
logger_1.default.error `Could not copy file from path=${sourceFile} to path=${targetFile}`;
|
|
61
|
+
throw err;
|
|
62
|
+
}
|
|
63
|
+
return targetFile;
|
|
64
|
+
}));
|
|
65
|
+
return { createdFiles };
|
|
66
|
+
}
|
|
67
|
+
exports.eject = eject;
|
|
68
|
+
async function wrap({ siteDir, themePath, componentName: themeComponentName, typescript, importType = 'original', }) {
|
|
69
|
+
const isDirectory = await isDir(path_1.default.join(themePath, themeComponentName));
|
|
70
|
+
// Top/Parent/ComponentName => ComponentName
|
|
71
|
+
const componentName = lodash_1.default.last(themeComponentName.split('/'));
|
|
72
|
+
const wrapperComponentName = `${componentName}Wrapper`;
|
|
73
|
+
const wrapperFileName = `${themeComponentName}${isDirectory ? '/index' : ''}${typescript ? '.tsx' : '.js'}`;
|
|
74
|
+
await fs_extra_1.default.ensureDir(path_1.default.resolve(siteDir, utils_1.THEME_PATH));
|
|
75
|
+
const toPath = path_1.default.resolve(siteDir, utils_1.THEME_PATH, wrapperFileName);
|
|
76
|
+
const content = typescript
|
|
77
|
+
? `import React from 'react';
|
|
78
|
+
import ${componentName} from '@theme-${importType}/${themeComponentName}';
|
|
79
|
+
import type ${componentName}Type from '@theme/${themeComponentName}';
|
|
80
|
+
import type {WrapperProps} from '@docusaurus/types';
|
|
81
|
+
|
|
82
|
+
type Props = WrapperProps<typeof ${componentName}Type>;
|
|
83
|
+
|
|
84
|
+
export default function ${wrapperComponentName}(props: Props): JSX.Element {
|
|
85
|
+
return (
|
|
86
|
+
<>
|
|
87
|
+
<${componentName} {...props} />
|
|
88
|
+
</>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
`
|
|
92
|
+
: `import React from 'react';
|
|
93
|
+
import ${componentName} from '@theme-${importType}/${themeComponentName}';
|
|
94
|
+
|
|
95
|
+
export default function ${wrapperComponentName}(props) {
|
|
96
|
+
return (
|
|
97
|
+
<>
|
|
98
|
+
<${componentName} {...props} />
|
|
99
|
+
</>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
`;
|
|
103
|
+
await fs_extra_1.default.outputFile(toPath, content);
|
|
104
|
+
return { createdFiles: [toPath] };
|
|
105
|
+
}
|
|
106
|
+
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 { NormalizedPluginConfig } from '../../server/plugins/configs';
|
|
8
|
+
import type { InitializedPlugin, SwizzleAction, SwizzleActionStatus } from '@docusaurus/types';
|
|
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 SwizzleCLIOptions = {
|
|
25
|
+
typescript: boolean;
|
|
26
|
+
danger: boolean;
|
|
27
|
+
list: boolean;
|
|
28
|
+
wrap: boolean;
|
|
29
|
+
eject: boolean;
|
|
30
|
+
};
|
|
31
|
+
export declare function normalizeOptions(options: Partial<SwizzleCLIOptions>): SwizzleCLIOptions;
|
|
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 lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
13
|
+
const leven_1 = tslib_1.__importDefault(require("leven"));
|
|
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;
|