@docusaurus/core 2.0.0-beta.15d451942 → 2.0.0-beta.16
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 +136 -0
- package/bin/docusaurus.mjs +280 -0
- package/lib/babel/preset.d.ts +8 -3
- package/lib/babel/preset.js +8 -7
- package/lib/choosePort.js +32 -41
- package/lib/client/.eslintrc.js +0 -1
- package/lib/client/App.d.ts +1 -2
- package/lib/client/App.js +19 -24
- package/lib/client/LinksCollector.d.ts +3 -3
- package/lib/client/LinksCollector.js +5 -9
- package/lib/client/PendingNavigation.d.ts +24 -1
- package/lib/client/PendingNavigation.js +5 -7
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +13 -0
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +15 -10
- package/lib/client/client-lifecycles-dispatcher.d.ts +2 -5
- package/lib/client/client-lifecycles-dispatcher.js +5 -9
- package/lib/client/clientEntry.js +11 -5
- package/lib/client/docusaurus.d.ts +6 -0
- package/lib/client/docusaurus.js +17 -23
- 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 +7 -6
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +36 -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 +1 -1
- package/lib/client/exports/Interpolate.js +15 -21
- package/lib/client/exports/Link.d.ts +11 -5
- package/lib/client/exports/Link.js +29 -17
- package/lib/client/exports/Translate.d.ts +3 -3
- package/lib/client/exports/Translate.js +15 -10
- package/lib/client/exports/browserContext.d.ts +11 -0
- package/lib/client/exports/browserContext.js +22 -0
- package/lib/client/exports/constants.js +1 -11
- package/lib/client/exports/docusaurusContext.d.ts +12 -0
- package/lib/client/exports/docusaurusContext.js +25 -0
- 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 +3 -5
- package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
- package/lib/client/exports/useDocusaurusContext.js +3 -9
- 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/client/flat.d.ts +2 -2
- package/lib/client/flat.js +8 -11
- package/lib/client/normalizeLocation.d.ts +2 -5
- package/lib/client/normalizeLocation.js +1 -2
- package/lib/client/nprogress.css +2 -2
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +1 -3
- package/lib/client/preload.d.ts +3 -2
- package/lib/client/preload.js +2 -1
- 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 +39 -0
- package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
- package/lib/client/theme-fallback/Layout/index.js +10 -19
- 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 +9 -16
- package/lib/{webpack/sharedModuleAliases.d.ts → client/theme-fallback/Root/index.d.ts} +4 -4
- package/lib/client/theme-fallback/Root/index.js +2 -7
- package/lib/commands/build.d.ts +1 -1
- package/lib/commands/build.js +59 -61
- package/lib/commands/clear.d.ts +6 -0
- package/lib/commands/clear.js +32 -21
- package/lib/commands/commandUtils.d.ts +7 -1
- package/lib/commands/commandUtils.js +7 -7
- package/lib/commands/deploy.d.ts +4 -1
- package/lib/commands/deploy.js +115 -71
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +4 -4
- package/lib/commands/serve.d.ts +1 -1
- package/lib/commands/serve.js +30 -16
- package/lib/commands/start.d.ts +1 -1
- package/lib/commands/start.js +100 -89
- package/lib/commands/swizzle/actions.d.ts +23 -0
- package/lib/commands/swizzle/actions.js +102 -0
- package/lib/commands/swizzle/common.d.ts +33 -0
- package/lib/commands/swizzle/common.js +57 -0
- package/lib/commands/swizzle/components.d.ts +29 -0
- package/lib/commands/swizzle/components.js +165 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +77 -0
- package/lib/{client/exports → commands/swizzle}/context.d.ts +2 -4
- package/lib/commands/swizzle/context.js +30 -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/commands/swizzle/tables.d.ts +9 -0
- package/lib/commands/swizzle/tables.js +116 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +105 -0
- package/lib/commands/writeHeadingIds.d.ts +9 -6
- package/lib/commands/writeHeadingIds.js +44 -46
- package/lib/commands/writeTranslations.d.ts +2 -2
- package/lib/commands/writeTranslations.js +36 -14
- package/lib/index.d.ts +10 -9
- package/lib/index.js +20 -19
- package/lib/server/brokenLinks.d.ts +1 -1
- package/lib/server/brokenLinks.js +38 -33
- package/lib/server/client-modules/index.d.ts +1 -1
- package/lib/server/client-modules/index.js +1 -3
- package/lib/server/config.d.ts +2 -2
- package/lib/server/config.js +10 -7
- package/lib/server/configValidation.d.ts +4 -2
- package/lib/server/configValidation.js +63 -32
- package/lib/server/duplicateRoutes.d.ts +1 -1
- package/lib/server/duplicateRoutes.js +10 -6
- package/lib/server/html-tags/htmlTags.js +8 -9
- package/lib/server/html-tags/index.d.ts +2 -2
- package/lib/server/html-tags/index.js +3 -3
- package/lib/server/i18n.d.ts +1 -2
- package/lib/server/i18n.js +31 -46
- package/lib/server/index.d.ts +9 -2
- package/lib/server/index.js +165 -87
- package/lib/server/loadSetup.d.ts +2 -3
- package/lib/server/loadSetup.js +5 -5
- 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 +3 -4
- package/lib/server/plugins/index.js +53 -37
- package/lib/server/plugins/init.d.ts +11 -5
- package/lib/server/plugins/init.js +40 -47
- 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 +14 -14
- package/lib/server/routes.d.ts +1 -1
- package/lib/server/routes.js +51 -28
- package/lib/server/themes/alias.d.ts +3 -2
- package/lib/server/themes/alias.js +24 -15
- package/lib/server/themes/index.d.ts +6 -2
- package/lib/server/themes/index.js +36 -24
- package/lib/server/translations/translations.d.ts +10 -5
- package/lib/server/translations/translations.js +27 -35
- package/lib/server/translations/translationsExtractor.d.ts +9 -4
- package/lib/server/translations/translationsExtractor.js +160 -119
- package/lib/server/utils.d.ts +9 -3
- package/lib/server/utils.js +8 -10
- package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
- package/lib/server/versions/index.d.ts +3 -4
- package/lib/server/versions/index.js +22 -21
- package/lib/webpack/base.d.ts +4 -4
- package/lib/webpack/base.js +54 -38
- package/lib/webpack/client.d.ts +3 -3
- package/lib/webpack/client.js +15 -21
- package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
- package/lib/webpack/plugins/ChunkAssetPlugin.js +17 -10
- 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 +5 -6
- package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
- package/lib/webpack/plugins/WaitPlugin.js +4 -4
- package/lib/webpack/server.d.ts +3 -3
- package/lib/webpack/server.js +18 -11
- 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 +9 -30
- package/lib/webpack/utils.js +58 -171
- package/package.json +76 -69
- 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/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
|
@@ -6,34 +6,43 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.sortAliases = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
11
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
12
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
13
13
|
const utils_1 = require("@docusaurus/utils");
|
|
14
|
-
const lodash_1 = require("lodash");
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
15
|
+
// Order of Webpack aliases is important because one alias can shadow another
|
|
16
|
+
// This ensure @theme/NavbarItem alias is after @theme/NavbarItem/LocaleDropdown
|
|
17
|
+
// See https://github.com/facebook/docusaurus/pull/3922
|
|
18
|
+
// See https://github.com/facebook/docusaurus/issues/5382
|
|
19
|
+
function sortAliases(aliases) {
|
|
20
|
+
// Alphabetical order by default
|
|
21
|
+
const entries = lodash_1.default.sortBy(Object.entries(aliases), ([alias]) => alias);
|
|
22
|
+
// @theme/NavbarItem should be after @theme/NavbarItem/LocaleDropdown
|
|
23
|
+
entries.sort(([alias1], [alias2]) => alias1.includes(`${alias2}/`) ? -1 : 0);
|
|
24
|
+
return Object.fromEntries(entries);
|
|
25
|
+
}
|
|
26
|
+
exports.sortAliases = sortAliases;
|
|
27
|
+
async function themeAlias(themePath, addOriginalAlias) {
|
|
28
|
+
if (!(await fs_extra_1.default.pathExists(themePath))) {
|
|
17
29
|
return {};
|
|
18
30
|
}
|
|
19
|
-
const themeComponentFiles =
|
|
31
|
+
const themeComponentFiles = await (0, utils_1.Globby)(['**/*.{js,jsx,ts,tsx}'], {
|
|
20
32
|
cwd: themePath,
|
|
21
33
|
});
|
|
22
|
-
// See https://github.com/facebook/docusaurus/pull/3922
|
|
23
|
-
// ensure @theme/NavbarItem alias is created after @theme/NavbarItem/LocaleDropdown
|
|
24
|
-
const sortedThemeComponentFiles = lodash_1.sortBy(themeComponentFiles, (file) => file.endsWith('/index.js'));
|
|
25
34
|
const aliases = {};
|
|
26
|
-
|
|
35
|
+
themeComponentFiles.forEach((relativeSource) => {
|
|
27
36
|
const filePath = path_1.default.join(themePath, relativeSource);
|
|
28
|
-
const fileName = utils_1.fileToPath(relativeSource);
|
|
29
|
-
const aliasName = utils_1.posixPath(utils_1.normalizeUrl(['@theme', fileName]).replace(/\/$/, ''));
|
|
37
|
+
const fileName = (0, utils_1.fileToPath)(relativeSource);
|
|
38
|
+
const aliasName = (0, utils_1.posixPath)((0, utils_1.normalizeUrl)(['@theme', fileName]).replace(/\/$/, ''));
|
|
30
39
|
aliases[aliasName] = filePath;
|
|
31
40
|
if (addOriginalAlias) {
|
|
32
41
|
// For swizzled components to access the original.
|
|
33
|
-
const originalAliasName = utils_1.posixPath(utils_1.normalizeUrl(['@theme-original', fileName]).replace(/\/$/, ''));
|
|
42
|
+
const originalAliasName = (0, utils_1.posixPath)((0, utils_1.normalizeUrl)(['@theme-original', fileName]).replace(/\/$/, ''));
|
|
34
43
|
aliases[originalAliasName] = filePath;
|
|
35
44
|
}
|
|
36
45
|
});
|
|
37
|
-
return aliases;
|
|
46
|
+
return sortAliases(aliases);
|
|
38
47
|
}
|
|
39
48
|
exports.default = themeAlias;
|
|
@@ -4,5 +4,9 @@
|
|
|
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
|
-
export
|
|
7
|
+
import type { ThemeAliases, LoadedPlugin } from '@docusaurus/types';
|
|
8
|
+
export declare function loadThemeAliases(themePaths: string[], userThemePaths: string[]): Promise<ThemeAliases>;
|
|
9
|
+
export declare function loadPluginsThemeAliases({ siteDir, plugins, }: {
|
|
10
|
+
siteDir: string;
|
|
11
|
+
plugins: LoadedPlugin[];
|
|
12
|
+
}): Promise<ThemeAliases>;
|
|
@@ -6,30 +6,42 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.loadPluginsThemeAliases = exports.loadThemeAliases = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
12
|
+
const utils_1 = require("@docusaurus/utils");
|
|
13
|
+
const alias_1 = (0, tslib_1.__importStar)(require("./alias"));
|
|
14
|
+
const ThemeFallbackDir = path_1.default.resolve(__dirname, '../../client/theme-fallback');
|
|
15
|
+
async function loadThemeAliases(themePaths, userThemePaths) {
|
|
16
|
+
const aliases = {};
|
|
17
|
+
for (const themePath of themePaths) {
|
|
18
|
+
const themeAliases = await (0, alias_1.default)(themePath, true);
|
|
19
|
+
Object.keys(themeAliases).forEach((aliasKey) => {
|
|
20
|
+
// If this alias shadows a previous one, use @theme-init to preserve the
|
|
21
|
+
// initial one. @theme-init is only applied once: to the initial theme
|
|
22
|
+
// that provided this component
|
|
23
|
+
if (aliasKey in aliases) {
|
|
24
|
+
const componentName = aliasKey.substring(aliasKey.indexOf('/') + 1);
|
|
25
|
+
const initAlias = `@theme-init/${componentName}`;
|
|
26
|
+
if (!(initAlias in aliases)) {
|
|
27
|
+
aliases[initAlias] = aliases[aliasKey];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
aliases[aliasKey] = themeAliases[aliasKey];
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
for (const themePath of userThemePaths) {
|
|
34
|
+
const userThemeAliases = await (0, alias_1.default)(themePath, false);
|
|
35
|
+
Object.assign(aliases, userThemeAliases);
|
|
36
|
+
}
|
|
37
|
+
return (0, alias_1.sortAliases)(aliases);
|
|
22
38
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const userThemeAliases = alias_1.default(themePath, false);
|
|
31
|
-
aliases = { ...aliases, ...buildThemeAliases(userThemeAliases, aliases) };
|
|
32
|
-
});
|
|
33
|
-
return aliases;
|
|
39
|
+
exports.loadThemeAliases = loadThemeAliases;
|
|
40
|
+
function loadPluginsThemeAliases({ siteDir, plugins, }) {
|
|
41
|
+
const pluginThemes = plugins
|
|
42
|
+
.map((plugin) => (plugin.getThemePath ? plugin.getThemePath() : undefined))
|
|
43
|
+
.filter((x) => Boolean(x));
|
|
44
|
+
const userTheme = path_1.default.resolve(siteDir, utils_1.THEME_PATH);
|
|
45
|
+
return loadThemeAliases([ThemeFallbackDir, ...pluginThemes], [userTheme]);
|
|
34
46
|
}
|
|
35
|
-
exports.
|
|
47
|
+
exports.loadPluginsThemeAliases = loadPluginsThemeAliases;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 { TranslationFileContent, TranslationFile, TranslationMessage, InitializedPlugin } from '@docusaurus/types';
|
|
3
8
|
export declare type WriteTranslationsOptions = {
|
|
4
9
|
override?: boolean;
|
|
5
10
|
messagePrefix?: string;
|
|
@@ -21,15 +26,15 @@ export declare function getCodeTranslationsFilePath(context: TranslationContext)
|
|
|
21
26
|
export declare function readCodeTranslationFileContent(context: TranslationContext): Promise<TranslationFileContent | undefined>;
|
|
22
27
|
export declare function writeCodeTranslations(context: TranslationContext, content: TranslationFileContent, options: WriteTranslationsOptions): Promise<void>;
|
|
23
28
|
export declare function writePluginTranslations({ siteDir, plugin, locale, translationFile, options, }: TranslationContext & {
|
|
24
|
-
plugin:
|
|
29
|
+
plugin: InitializedPlugin;
|
|
25
30
|
translationFile: TranslationFile;
|
|
26
31
|
options?: WriteTranslationsOptions;
|
|
27
32
|
}): Promise<void>;
|
|
28
33
|
export declare function localizePluginTranslationFile({ siteDir, plugin, locale, translationFile, }: TranslationContext & {
|
|
29
|
-
plugin:
|
|
34
|
+
plugin: InitializedPlugin;
|
|
30
35
|
translationFile: TranslationFile;
|
|
31
36
|
}): Promise<TranslationFile>;
|
|
32
|
-
export declare function getPluginsDefaultCodeTranslationMessages(plugins:
|
|
37
|
+
export declare function getPluginsDefaultCodeTranslationMessages(plugins: InitializedPlugin[]): Promise<Record<string, string>>;
|
|
33
38
|
export declare function applyDefaultCodeTranslations({ extractedCodeTranslations, defaultCodeMessages, }: {
|
|
34
39
|
extractedCodeTranslations: Record<string, TranslationMessage>;
|
|
35
40
|
defaultCodeMessages: Record<string, string>;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.applyDefaultCodeTranslations = exports.getPluginsDefaultCodeTranslationMessages = exports.localizePluginTranslationFile = exports.writePluginTranslations = exports.writeCodeTranslations = exports.readCodeTranslationFileContent = exports.getCodeTranslationsFilePath = exports.getTranslationsLocaleDirPath = exports.getTranslationsDirPath = exports.writeTranslationFileContent = exports.readTranslationFileContent = exports.ensureTranslationFileContent = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
2
|
/**
|
|
6
3
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
7
4
|
*
|
|
8
5
|
* This source code is licensed under the MIT license found in the
|
|
9
6
|
* LICENSE file in the root directory of this source tree.
|
|
10
7
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.applyDefaultCodeTranslations = exports.getPluginsDefaultCodeTranslationMessages = exports.localizePluginTranslationFile = exports.writePluginTranslations = exports.writeCodeTranslations = exports.readCodeTranslationFileContent = exports.getCodeTranslationsFilePath = exports.getTranslationsLocaleDirPath = exports.getTranslationsDirPath = exports.writeTranslationFileContent = exports.readTranslationFileContent = exports.ensureTranslationFileContent = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
12
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
13
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
14
14
|
const utils_1 = require("@docusaurus/utils");
|
|
15
15
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
16
|
-
const
|
|
16
|
+
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
17
17
|
const TranslationFileContentSchema = utils_validation_1.Joi.object()
|
|
18
18
|
.pattern(utils_validation_1.Joi.string(), utils_validation_1.Joi.object({
|
|
19
19
|
message: utils_validation_1.Joi.string().allow('').required(),
|
|
@@ -35,8 +35,9 @@ async function readTranslationFileContent(filePath) {
|
|
|
35
35
|
ensureTranslationFileContent(content);
|
|
36
36
|
return content;
|
|
37
37
|
}
|
|
38
|
-
catch (
|
|
39
|
-
|
|
38
|
+
catch (err) {
|
|
39
|
+
logger_1.default.error `Invalid translation file at path=${filePath}.`;
|
|
40
|
+
throw err;
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
return undefined;
|
|
@@ -44,7 +45,7 @@ async function readTranslationFileContent(filePath) {
|
|
|
44
45
|
exports.readTranslationFileContent = readTranslationFileContent;
|
|
45
46
|
function mergeTranslationFileContent({ existingContent = {}, newContent, options, }) {
|
|
46
47
|
// Apply messagePrefix to all messages
|
|
47
|
-
const newContentTransformed = lodash_1.mapValues(newContent, (value) => {
|
|
48
|
+
const newContentTransformed = lodash_1.default.mapValues(newContent, (value) => {
|
|
48
49
|
var _a;
|
|
49
50
|
return ({
|
|
50
51
|
...value,
|
|
@@ -56,7 +57,7 @@ function mergeTranslationFileContent({ existingContent = {}, newContent, options
|
|
|
56
57
|
Object.entries(newContentTransformed).forEach(([key, { message, description }]) => {
|
|
57
58
|
var _a, _b;
|
|
58
59
|
result[key] = {
|
|
59
|
-
// If
|
|
60
|
+
// If messages already exist, we don't override them (unless requested)
|
|
60
61
|
message: options.override
|
|
61
62
|
? message
|
|
62
63
|
: (_b = (_a = existingContent[key]) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : message,
|
|
@@ -68,11 +69,10 @@ function mergeTranslationFileContent({ existingContent = {}, newContent, options
|
|
|
68
69
|
async function writeTranslationFileContent({ filePath, content: newContent, options = {}, }) {
|
|
69
70
|
const existingContent = await readTranslationFileContent(filePath);
|
|
70
71
|
// Warn about potential legacy keys
|
|
71
|
-
const unknownKeys = lodash_1.difference(Object.keys(existingContent !== null && existingContent !== void 0 ? existingContent : {}), Object.keys(newContent));
|
|
72
|
+
const unknownKeys = lodash_1.default.difference(Object.keys(existingContent !== null && existingContent !== void 0 ? existingContent : {}), Object.keys(newContent));
|
|
72
73
|
if (unknownKeys.length > 0) {
|
|
73
|
-
|
|
74
|
-
Maybe you should remove them?
|
|
75
|
-
- ${unknownKeys.join('\n- ')}`));
|
|
74
|
+
logger_1.default.warn `Some translation keys looks unknown to us in file path=${filePath}.
|
|
75
|
+
Maybe you should remove them? ${unknownKeys}`;
|
|
76
76
|
}
|
|
77
77
|
const mergedContent = mergeTranslationFileContent({
|
|
78
78
|
existingContent,
|
|
@@ -81,11 +81,9 @@ Maybe you should remove them?
|
|
|
81
81
|
});
|
|
82
82
|
// Avoid creating empty translation files
|
|
83
83
|
if (Object.keys(mergedContent).length > 0) {
|
|
84
|
-
|
|
85
|
-
.length.toString()
|
|
86
|
-
.padStart(3, ' ')} translations will be written at ${utils_1.toMessageRelativeFilePath(filePath)}`);
|
|
84
|
+
logger_1.default.info `number=${Object.keys(mergedContent).length} translations will be written at path=${(0, utils_1.toMessageRelativeFilePath)(filePath)}.`;
|
|
87
85
|
await fs_extra_1.default.ensureDir(path_1.default.dirname(filePath));
|
|
88
|
-
await fs_extra_1.default.writeFile(filePath, JSON.stringify(mergedContent, null, 2));
|
|
86
|
+
await fs_extra_1.default.writeFile(filePath, `${JSON.stringify(mergedContent, null, 2)}\n`);
|
|
89
87
|
}
|
|
90
88
|
}
|
|
91
89
|
exports.writeTranslationFileContent = writeTranslationFileContent;
|
|
@@ -119,12 +117,12 @@ exports.writeCodeTranslations = writeCodeTranslations;
|
|
|
119
117
|
// (json/yaml/toml/xml...)
|
|
120
118
|
function addTranslationFileExtension(translationFilePath) {
|
|
121
119
|
if (translationFilePath.endsWith('.json')) {
|
|
122
|
-
throw new Error(`Translation file path does
|
|
120
|
+
throw new Error(`Translation file path at "${translationFilePath}" does not need to end with ".json", we add the extension automatically.`);
|
|
123
121
|
}
|
|
124
122
|
return `${translationFilePath}.json`;
|
|
125
123
|
}
|
|
126
124
|
function getPluginTranslationFilePath({ siteDir, plugin, locale, translationFilePath, }) {
|
|
127
|
-
const dirPath = utils_1.getPluginI18nPath({
|
|
125
|
+
const dirPath = (0, utils_1.getPluginI18nPath)({
|
|
128
126
|
siteDir,
|
|
129
127
|
locale,
|
|
130
128
|
pluginName: plugin.name,
|
|
@@ -165,32 +163,26 @@ async function localizePluginTranslationFile({ siteDir, plugin, locale, translat
|
|
|
165
163
|
},
|
|
166
164
|
};
|
|
167
165
|
}
|
|
168
|
-
|
|
169
|
-
return translationFile;
|
|
170
|
-
}
|
|
166
|
+
return translationFile;
|
|
171
167
|
}
|
|
172
168
|
exports.localizePluginTranslationFile = localizePluginTranslationFile;
|
|
173
169
|
async function getPluginsDefaultCodeTranslationMessages(plugins) {
|
|
174
170
|
const pluginsMessages = await Promise.all(plugins.map((plugin) => { var _a, _b; return (_b = (_a = plugin.getDefaultCodeTranslationMessages) === null || _a === void 0 ? void 0 : _a.call(plugin)) !== null && _b !== void 0 ? _b : {}; }));
|
|
175
|
-
return pluginsMessages.reduce((allMessages, pluginMessages) => {
|
|
176
|
-
return { ...allMessages, ...pluginMessages };
|
|
177
|
-
}, {});
|
|
171
|
+
return pluginsMessages.reduce((allMessages, pluginMessages) => ({ ...allMessages, ...pluginMessages }), {});
|
|
178
172
|
}
|
|
179
173
|
exports.getPluginsDefaultCodeTranslationMessages = getPluginsDefaultCodeTranslationMessages;
|
|
180
174
|
function applyDefaultCodeTranslations({ extractedCodeTranslations, defaultCodeMessages, }) {
|
|
181
|
-
const unusedDefaultCodeMessages = lodash_1.difference(Object.keys(defaultCodeMessages), Object.keys(extractedCodeTranslations));
|
|
175
|
+
const unusedDefaultCodeMessages = lodash_1.default.difference(Object.keys(defaultCodeMessages), Object.keys(extractedCodeTranslations));
|
|
182
176
|
if (unusedDefaultCodeMessages.length > 0) {
|
|
183
|
-
|
|
184
|
-
Please report this Docusaurus issue.
|
|
185
|
-
- ${unusedDefaultCodeMessages.join('\n- ')}
|
|
186
|
-
`));
|
|
177
|
+
logger_1.default.warn `Unused default message codes found.
|
|
178
|
+
Please report this Docusaurus issue. name=${unusedDefaultCodeMessages}`;
|
|
187
179
|
}
|
|
188
|
-
return lodash_1.mapValues(extractedCodeTranslations, (messageTranslation, messageId) => {
|
|
180
|
+
return lodash_1.default.mapValues(extractedCodeTranslations, (messageTranslation, messageId) => {
|
|
189
181
|
var _a;
|
|
190
|
-
return {
|
|
182
|
+
return ({
|
|
191
183
|
...messageTranslation,
|
|
192
184
|
message: (_a = defaultCodeMessages[messageId]) !== null && _a !== void 0 ? _a : messageTranslation.message,
|
|
193
|
-
};
|
|
185
|
+
});
|
|
194
186
|
});
|
|
195
187
|
}
|
|
196
188
|
exports.applyDefaultCodeTranslations = applyDefaultCodeTranslations;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 TransformOptions } from '@babel/core';
|
|
8
|
+
import type { InitializedPlugin, TranslationFileContent, TranslationMessage } from '@docusaurus/types';
|
|
4
9
|
export declare function globSourceCodeFilePaths(dirPaths: string[]): Promise<string[]>;
|
|
5
|
-
export declare function extractSiteSourceCodeTranslations(siteDir: string, plugins:
|
|
10
|
+
export declare function extractSiteSourceCodeTranslations(siteDir: string, plugins: InitializedPlugin[], babelOptions: TransformOptions, extraSourceCodeFilePaths?: string[]): Promise<TranslationFileContent>;
|
|
6
11
|
declare type SourceCodeFileTranslations = {
|
|
7
12
|
sourceCodeFilePath: string;
|
|
8
13
|
translations: Record<string, TranslationMessage>;
|