@docusaurus/core 2.0.0-beta.fc64c12e4 → 2.0.0
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.js → docusaurus.mjs} +81 -118
- 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 -8
- 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 +18 -51
- package/lib/client/exports/Link.d.ts +4 -10
- package/lib/client/exports/Link.js +38 -38
- package/lib/client/exports/Translate.d.ts +1 -1
- package/lib/client/exports/Translate.js +11 -10
- 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 +6 -13
- 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 +108 -146
- 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/{server/html-tags/htmlTags.d.ts → client/theme-fallback/NotFound/index.d.ts} +2 -1
- 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/client/{exports/context.js → theme-fallback/SiteMetadata/index.d.ts} +2 -2
- 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 +94 -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 +29 -28
- package/lib/commands/start.d.ts +9 -2
- package/lib/commands/start.js +107 -102
- 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 +46 -25
- 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 +4 -4
- package/lib/server/configValidation.js +86 -41
- 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 -13
- package/lib/server/index.js +83 -165
- package/lib/server/plugins/configs.d.ts +51 -0
- package/lib/server/plugins/configs.js +101 -0
- package/lib/server/plugins/index.d.ts +9 -8
- package/lib/server/plugins/index.js +73 -137
- package/lib/server/plugins/init.d.ts +6 -5
- 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 +5 -1
- 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 +166 -99
- package/lib/server/siteMetadata.d.ts +12 -0
- package/lib/server/siteMetadata.js +81 -0
- package/lib/server/translations/translations.d.ts +14 -19
- package/lib/server/translations/translations.js +40 -72
- package/lib/server/translations/translationsExtractor.d.ts +10 -4
- package/lib/server/translations/translationsExtractor.js +158 -122
- package/lib/server/utils.d.ts +7 -1
- package/lib/server/utils.js +7 -8
- 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 +45 -57
- 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 +33 -17
- 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 +30 -29
- package/lib/webpack/server.d.ts +5 -5
- package/lib/webpack/server.js +21 -12
- 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 +3 -2
- package/lib/webpack/utils.d.ts +15 -31
- package/lib/webpack/utils.js +61 -182
- package/package.json +81 -77
- package/bin/beforeCli.js +0 -103
- package/lib/.tsbuildinfo +0 -1
- package/lib/choosePort.js +0 -105
- package/lib/client/.eslintrc.js +0 -29
- package/lib/client/.tsbuildinfo +0 -1
- 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 -40
- 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/plugins/applyRouteTrailingSlash.d.ts +0 -9
- package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
- 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 -12
- package/lib/server/themes/index.js +0 -47
- 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
|
@@ -0,0 +1,81 @@
|
|
|
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.loadSiteMetadata = exports.getPluginVersion = 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 logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
14
|
+
const utils_1 = require("@docusaurus/utils");
|
|
15
|
+
async function getPackageJsonVersion(packageJsonPath) {
|
|
16
|
+
if (await fs_extra_1.default.pathExists(packageJsonPath)) {
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require
|
|
18
|
+
return require(packageJsonPath).version;
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
async function getPackageJsonName(packageJsonPath) {
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require
|
|
24
|
+
return require(packageJsonPath).name;
|
|
25
|
+
}
|
|
26
|
+
async function getPluginVersion(pluginPath, siteDir) {
|
|
27
|
+
let potentialPluginPackageJsonDirectory = path_1.default.dirname(pluginPath);
|
|
28
|
+
while (potentialPluginPackageJsonDirectory !== '/') {
|
|
29
|
+
const packageJsonPath = path_1.default.join(potentialPluginPackageJsonDirectory, 'package.json');
|
|
30
|
+
if ((await fs_extra_1.default.pathExists(packageJsonPath)) &&
|
|
31
|
+
(await fs_extra_1.default.lstat(packageJsonPath)).isFile()) {
|
|
32
|
+
if (potentialPluginPackageJsonDirectory === siteDir) {
|
|
33
|
+
// If the plugin belongs to the same docusaurus project, we classify it
|
|
34
|
+
// as local plugin.
|
|
35
|
+
return { type: 'project' };
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
type: 'package',
|
|
39
|
+
name: await getPackageJsonName(packageJsonPath),
|
|
40
|
+
version: await getPackageJsonVersion(packageJsonPath),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
potentialPluginPackageJsonDirectory = path_1.default.dirname(potentialPluginPackageJsonDirectory);
|
|
44
|
+
}
|
|
45
|
+
// In the case where a plugin is a path where no parent directory contains
|
|
46
|
+
// package.json, we can only classify it as local. Could happen if one puts a
|
|
47
|
+
// script in the parent directory of the site.
|
|
48
|
+
return { type: 'local' };
|
|
49
|
+
}
|
|
50
|
+
exports.getPluginVersion = getPluginVersion;
|
|
51
|
+
/**
|
|
52
|
+
* We want all `@docusaurus/*` packages to have the exact same version!
|
|
53
|
+
* @see https://github.com/facebook/docusaurus/issues/3371
|
|
54
|
+
* @see https://github.com/facebook/docusaurus/pull/3386
|
|
55
|
+
*/
|
|
56
|
+
function checkDocusaurusPackagesVersion(siteMetadata) {
|
|
57
|
+
const { docusaurusVersion } = siteMetadata;
|
|
58
|
+
Object.entries(siteMetadata.pluginVersions).forEach(([plugin, versionInfo]) => {
|
|
59
|
+
if (versionInfo.type === 'package' &&
|
|
60
|
+
versionInfo.name?.startsWith('@docusaurus/') &&
|
|
61
|
+
versionInfo.version &&
|
|
62
|
+
versionInfo.version !== docusaurusVersion) {
|
|
63
|
+
// Should we throw instead? It still could work with different versions
|
|
64
|
+
logger_1.default.error `Invalid name=${plugin} version number=${versionInfo.version}.
|
|
65
|
+
All official @docusaurus/* packages should have the exact same version as @docusaurus/core (number=${docusaurusVersion}).
|
|
66
|
+
Maybe you want to check, or regenerate your yarn.lock or package-lock.json file?`;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async function loadSiteMetadata({ plugins, siteDir, }) {
|
|
71
|
+
const siteMetadata = {
|
|
72
|
+
docusaurusVersion: utils_1.DOCUSAURUS_VERSION,
|
|
73
|
+
siteVersion: await getPackageJsonVersion(path_1.default.join(siteDir, 'package.json')),
|
|
74
|
+
pluginVersions: Object.fromEntries(plugins
|
|
75
|
+
.filter(({ version: { type } }) => type !== 'synthetic')
|
|
76
|
+
.map(({ name, version }) => [name, version])),
|
|
77
|
+
};
|
|
78
|
+
checkDocusaurusPackagesVersion(siteMetadata);
|
|
79
|
+
return siteMetadata;
|
|
80
|
+
}
|
|
81
|
+
exports.loadSiteMetadata = loadSiteMetadata;
|
|
@@ -1,36 +1,31 @@
|
|
|
1
|
-
|
|
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, CodeTranslations, InitializedPlugin } from '@docusaurus/types';
|
|
2
8
|
export declare type WriteTranslationsOptions = {
|
|
3
9
|
override?: boolean;
|
|
4
10
|
messagePrefix?: string;
|
|
5
11
|
};
|
|
6
12
|
declare type TranslationContext = {
|
|
7
|
-
|
|
8
|
-
locale: string;
|
|
13
|
+
localizationDir: string;
|
|
9
14
|
};
|
|
10
|
-
export declare function ensureTranslationFileContent(content: unknown): asserts content is TranslationFileContent;
|
|
11
|
-
export declare function readTranslationFileContent(filePath: string): Promise<TranslationFileContent | undefined>;
|
|
12
|
-
export declare function writeTranslationFileContent({ filePath, content: newContent, options, }: {
|
|
13
|
-
filePath: string;
|
|
14
|
-
content: TranslationFileContent;
|
|
15
|
-
options?: WriteTranslationsOptions;
|
|
16
|
-
}): Promise<void>;
|
|
17
|
-
export declare function getTranslationsDirPath(context: TranslationContext): string;
|
|
18
|
-
export declare function getTranslationsLocaleDirPath(context: TranslationContext): string;
|
|
19
|
-
export declare function getCodeTranslationsFilePath(context: TranslationContext): string;
|
|
20
15
|
export declare function readCodeTranslationFileContent(context: TranslationContext): Promise<TranslationFileContent | undefined>;
|
|
21
16
|
export declare function writeCodeTranslations(context: TranslationContext, content: TranslationFileContent, options: WriteTranslationsOptions): Promise<void>;
|
|
22
|
-
export declare function writePluginTranslations({
|
|
17
|
+
export declare function writePluginTranslations({ localizationDir, plugin, translationFile, options, }: TranslationContext & {
|
|
23
18
|
plugin: InitializedPlugin;
|
|
24
19
|
translationFile: TranslationFile;
|
|
25
20
|
options?: WriteTranslationsOptions;
|
|
26
21
|
}): Promise<void>;
|
|
27
|
-
export declare function localizePluginTranslationFile({
|
|
22
|
+
export declare function localizePluginTranslationFile({ localizationDir, plugin, translationFile, }: TranslationContext & {
|
|
28
23
|
plugin: InitializedPlugin;
|
|
29
24
|
translationFile: TranslationFile;
|
|
30
25
|
}): Promise<TranslationFile>;
|
|
31
|
-
export declare function getPluginsDefaultCodeTranslationMessages(plugins: InitializedPlugin[]): Promise<
|
|
26
|
+
export declare function getPluginsDefaultCodeTranslationMessages(plugins: InitializedPlugin[]): Promise<CodeTranslations>;
|
|
32
27
|
export declare function applyDefaultCodeTranslations({ extractedCodeTranslations, defaultCodeMessages, }: {
|
|
33
|
-
extractedCodeTranslations:
|
|
34
|
-
defaultCodeMessages:
|
|
35
|
-
}):
|
|
28
|
+
extractedCodeTranslations: TranslationFileContent;
|
|
29
|
+
defaultCodeMessages: CodeTranslations;
|
|
30
|
+
}): TranslationFileContent;
|
|
36
31
|
export {};
|
|
@@ -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
|
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.applyDefaultCodeTranslations = exports.getPluginsDefaultCodeTranslationMessages = exports.localizePluginTranslationFile = exports.writePluginTranslations = exports.writeCodeTranslations = exports.readCodeTranslationFileContent = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
11
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
12
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
|
-
const lodash_1 = require("lodash");
|
|
13
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
14
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
14
15
|
const utils_1 = require("@docusaurus/utils");
|
|
15
16
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
16
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
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(),
|
|
@@ -27,40 +27,35 @@ function ensureTranslationFileContent(content) {
|
|
|
27
27
|
convert: false,
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
|
-
exports.ensureTranslationFileContent = ensureTranslationFileContent;
|
|
31
30
|
async function readTranslationFileContent(filePath) {
|
|
32
31
|
if (await fs_extra_1.default.pathExists(filePath)) {
|
|
33
32
|
try {
|
|
34
|
-
const content =
|
|
33
|
+
const content = await fs_extra_1.default.readJSON(filePath);
|
|
35
34
|
ensureTranslationFileContent(content);
|
|
36
35
|
return content;
|
|
37
36
|
}
|
|
38
|
-
catch (
|
|
39
|
-
|
|
37
|
+
catch (err) {
|
|
38
|
+
logger_1.default.error `Invalid translation file at path=${filePath}.`;
|
|
39
|
+
throw err;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
return undefined;
|
|
43
43
|
}
|
|
44
|
-
exports.readTranslationFileContent = readTranslationFileContent;
|
|
45
44
|
function mergeTranslationFileContent({ existingContent = {}, newContent, options, }) {
|
|
46
45
|
// Apply messagePrefix to all messages
|
|
47
|
-
const newContentTransformed = lodash_1.mapValues(newContent, (value) => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
message: `${(_a = options.messagePrefix) !== null && _a !== void 0 ? _a : ''}${value.message}`,
|
|
52
|
-
});
|
|
53
|
-
});
|
|
46
|
+
const newContentTransformed = lodash_1.default.mapValues(newContent, (value) => ({
|
|
47
|
+
...value,
|
|
48
|
+
message: `${options.messagePrefix ?? ''}${value.message}`,
|
|
49
|
+
}));
|
|
54
50
|
const result = { ...existingContent };
|
|
55
51
|
// We only add missing keys here, we don't delete existing ones
|
|
56
52
|
Object.entries(newContentTransformed).forEach(([key, { message, description }]) => {
|
|
57
|
-
var _a, _b;
|
|
58
53
|
result[key] = {
|
|
59
|
-
// If
|
|
54
|
+
// If messages already exist, we don't override them (unless requested)
|
|
60
55
|
message: options.override
|
|
61
56
|
? message
|
|
62
|
-
:
|
|
63
|
-
description,
|
|
57
|
+
: existingContent[key]?.message ?? message,
|
|
58
|
+
description,
|
|
64
59
|
};
|
|
65
60
|
});
|
|
66
61
|
return result;
|
|
@@ -68,11 +63,10 @@ function mergeTranslationFileContent({ existingContent = {}, newContent, options
|
|
|
68
63
|
async function writeTranslationFileContent({ filePath, content: newContent, options = {}, }) {
|
|
69
64
|
const existingContent = await readTranslationFileContent(filePath);
|
|
70
65
|
// Warn about potential legacy keys
|
|
71
|
-
const unknownKeys = lodash_1.difference(Object.keys(existingContent
|
|
66
|
+
const unknownKeys = lodash_1.default.difference(Object.keys(existingContent ?? {}), Object.keys(newContent));
|
|
72
67
|
if (unknownKeys.length > 0) {
|
|
73
|
-
|
|
74
|
-
Maybe you should remove them?
|
|
75
|
-
- ${unknownKeys.join('\n- ')}`));
|
|
68
|
+
logger_1.default.warn `Some translation keys looks unknown to us in file path=${filePath}.
|
|
69
|
+
Maybe you should remove them? ${unknownKeys}`;
|
|
76
70
|
}
|
|
77
71
|
const mergedContent = mergeTranslationFileContent({
|
|
78
72
|
existingContent,
|
|
@@ -81,27 +75,13 @@ Maybe you should remove them?
|
|
|
81
75
|
});
|
|
82
76
|
// Avoid creating empty translation files
|
|
83
77
|
if (Object.keys(mergedContent).length > 0) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
.padStart(3, ' ')} translations will be written at "${utils_1.toMessageRelativeFilePath(filePath)}".`);
|
|
87
|
-
await fs_extra_1.default.ensureDir(path_1.default.dirname(filePath));
|
|
88
|
-
await fs_extra_1.default.writeFile(filePath, JSON.stringify(mergedContent, null, 2));
|
|
78
|
+
logger_1.default.info `number=${Object.keys(mergedContent).length} translations will be written at path=${(0, utils_1.toMessageRelativeFilePath)(filePath)}.`;
|
|
79
|
+
await fs_extra_1.default.outputFile(filePath, `${JSON.stringify(mergedContent, null, 2)}\n`);
|
|
89
80
|
}
|
|
90
81
|
}
|
|
91
|
-
exports.writeTranslationFileContent = writeTranslationFileContent;
|
|
92
|
-
// should we make this configurable?
|
|
93
|
-
function getTranslationsDirPath(context) {
|
|
94
|
-
return path_1.default.resolve(path_1.default.join(context.siteDir, `i18n`));
|
|
95
|
-
}
|
|
96
|
-
exports.getTranslationsDirPath = getTranslationsDirPath;
|
|
97
|
-
function getTranslationsLocaleDirPath(context) {
|
|
98
|
-
return path_1.default.join(getTranslationsDirPath(context), context.locale);
|
|
99
|
-
}
|
|
100
|
-
exports.getTranslationsLocaleDirPath = getTranslationsLocaleDirPath;
|
|
101
82
|
function getCodeTranslationsFilePath(context) {
|
|
102
|
-
return path_1.default.join(
|
|
83
|
+
return path_1.default.join(context.localizationDir, utils_1.CODE_TRANSLATIONS_FILE_NAME);
|
|
103
84
|
}
|
|
104
|
-
exports.getCodeTranslationsFilePath = getCodeTranslationsFilePath;
|
|
105
85
|
async function readCodeTranslationFileContent(context) {
|
|
106
86
|
return readTranslationFileContent(getCodeTranslationsFilePath(context));
|
|
107
87
|
}
|
|
@@ -123,21 +103,19 @@ function addTranslationFileExtension(translationFilePath) {
|
|
|
123
103
|
}
|
|
124
104
|
return `${translationFilePath}.json`;
|
|
125
105
|
}
|
|
126
|
-
function getPluginTranslationFilePath({
|
|
127
|
-
const dirPath = utils_1.getPluginI18nPath({
|
|
128
|
-
|
|
129
|
-
locale,
|
|
106
|
+
function getPluginTranslationFilePath({ localizationDir, plugin, translationFilePath, }) {
|
|
107
|
+
const dirPath = (0, utils_1.getPluginI18nPath)({
|
|
108
|
+
localizationDir,
|
|
130
109
|
pluginName: plugin.name,
|
|
131
110
|
pluginId: plugin.options.id,
|
|
132
111
|
});
|
|
133
112
|
const filePath = addTranslationFileExtension(translationFilePath);
|
|
134
113
|
return path_1.default.join(dirPath, filePath);
|
|
135
114
|
}
|
|
136
|
-
async function writePluginTranslations({
|
|
115
|
+
async function writePluginTranslations({ localizationDir, plugin, translationFile, options, }) {
|
|
137
116
|
const filePath = getPluginTranslationFilePath({
|
|
138
117
|
plugin,
|
|
139
|
-
|
|
140
|
-
locale,
|
|
118
|
+
localizationDir,
|
|
141
119
|
translationFilePath: translationFile.path,
|
|
142
120
|
});
|
|
143
121
|
await writeTranslationFileContent({
|
|
@@ -147,16 +125,15 @@ async function writePluginTranslations({ siteDir, plugin, locale, translationFil
|
|
|
147
125
|
});
|
|
148
126
|
}
|
|
149
127
|
exports.writePluginTranslations = writePluginTranslations;
|
|
150
|
-
async function localizePluginTranslationFile({
|
|
128
|
+
async function localizePluginTranslationFile({ localizationDir, plugin, translationFile, }) {
|
|
151
129
|
const filePath = getPluginTranslationFilePath({
|
|
152
130
|
plugin,
|
|
153
|
-
|
|
154
|
-
locale,
|
|
131
|
+
localizationDir,
|
|
155
132
|
translationFilePath: translationFile.path,
|
|
156
133
|
});
|
|
157
134
|
const localizedContent = await readTranslationFileContent(filePath);
|
|
158
135
|
if (localizedContent) {
|
|
159
|
-
//
|
|
136
|
+
// Localized messages "override" default unlocalized messages
|
|
160
137
|
return {
|
|
161
138
|
path: translationFile.path,
|
|
162
139
|
content: {
|
|
@@ -165,32 +142,23 @@ async function localizePluginTranslationFile({ siteDir, plugin, locale, translat
|
|
|
165
142
|
},
|
|
166
143
|
};
|
|
167
144
|
}
|
|
168
|
-
|
|
169
|
-
return translationFile;
|
|
170
|
-
}
|
|
145
|
+
return translationFile;
|
|
171
146
|
}
|
|
172
147
|
exports.localizePluginTranslationFile = localizePluginTranslationFile;
|
|
173
148
|
async function getPluginsDefaultCodeTranslationMessages(plugins) {
|
|
174
|
-
const pluginsMessages = await Promise.all(plugins.map((plugin) =>
|
|
175
|
-
return pluginsMessages.reduce((allMessages, pluginMessages) => {
|
|
176
|
-
return { ...allMessages, ...pluginMessages };
|
|
177
|
-
}, {});
|
|
149
|
+
const pluginsMessages = await Promise.all(plugins.map((plugin) => plugin.getDefaultCodeTranslationMessages?.() ?? {}));
|
|
150
|
+
return pluginsMessages.reduce((allMessages, pluginMessages) => ({ ...allMessages, ...pluginMessages }), {});
|
|
178
151
|
}
|
|
179
152
|
exports.getPluginsDefaultCodeTranslationMessages = getPluginsDefaultCodeTranslationMessages;
|
|
180
153
|
function applyDefaultCodeTranslations({ extractedCodeTranslations, defaultCodeMessages, }) {
|
|
181
|
-
const unusedDefaultCodeMessages = lodash_1.difference(Object.keys(defaultCodeMessages), Object.keys(extractedCodeTranslations));
|
|
154
|
+
const unusedDefaultCodeMessages = lodash_1.default.difference(Object.keys(defaultCodeMessages), Object.keys(extractedCodeTranslations));
|
|
182
155
|
if (unusedDefaultCodeMessages.length > 0) {
|
|
183
|
-
|
|
184
|
-
Please report this Docusaurus issue.
|
|
185
|
-
- ${unusedDefaultCodeMessages.join('\n- ')}
|
|
186
|
-
`));
|
|
156
|
+
logger_1.default.warn `Unused default message codes found.
|
|
157
|
+
Please report this Docusaurus issue. name=${unusedDefaultCodeMessages}`;
|
|
187
158
|
}
|
|
188
|
-
return lodash_1.mapValues(extractedCodeTranslations, (messageTranslation, messageId) => {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
message: (_a = defaultCodeMessages[messageId]) !== null && _a !== void 0 ? _a : messageTranslation.message,
|
|
193
|
-
};
|
|
194
|
-
});
|
|
159
|
+
return lodash_1.default.mapValues(extractedCodeTranslations, (messageTranslation, messageId) => ({
|
|
160
|
+
...messageTranslation,
|
|
161
|
+
message: defaultCodeMessages[messageId] ?? messageTranslation.message,
|
|
162
|
+
}));
|
|
195
163
|
}
|
|
196
164
|
exports.applyDefaultCodeTranslations = applyDefaultCodeTranslations;
|
|
@@ -1,10 +1,16 @@
|
|
|
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 TransformOptions } from '@babel/core';
|
|
8
|
+
import type { InitializedPlugin, TranslationFileContent } from '@docusaurus/types';
|
|
3
9
|
export declare function globSourceCodeFilePaths(dirPaths: string[]): Promise<string[]>;
|
|
4
|
-
export declare function extractSiteSourceCodeTranslations(siteDir: string, plugins: InitializedPlugin[], babelOptions: TransformOptions): Promise<TranslationFileContent>;
|
|
10
|
+
export declare function extractSiteSourceCodeTranslations(siteDir: string, plugins: InitializedPlugin[], babelOptions: TransformOptions, extraSourceCodeFilePaths?: string[]): Promise<TranslationFileContent>;
|
|
5
11
|
declare type SourceCodeFileTranslations = {
|
|
6
12
|
sourceCodeFilePath: string;
|
|
7
|
-
translations:
|
|
13
|
+
translations: TranslationFileContent;
|
|
8
14
|
warnings: string[];
|
|
9
15
|
};
|
|
10
16
|
export declare function extractAllSourceCodeFileTranslations(sourceCodeFilePaths: string[], babelOptions: TransformOptions): Promise<SourceCodeFileTranslations[]>;
|