@docusaurus/core 2.0.0-beta.15d451942 → 2.0.0-beta.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/beforeCli.mjs +133 -0
- package/bin/docusaurus.mjs +279 -0
- package/lib/babel/preset.d.ts +8 -3
- package/lib/babel/preset.js +8 -7
- package/lib/choosePort.js +31 -43
- package/lib/client/.eslintrc.js +0 -1
- package/lib/client/App.d.ts +1 -2
- package/lib/client/App.js +23 -24
- package/lib/client/LinksCollector.d.ts +3 -3
- package/lib/client/LinksCollector.js +7 -11
- package/lib/client/PendingNavigation.d.ts +24 -1
- package/lib/client/PendingNavigation.js +5 -7
- package/lib/{webpack/sharedModuleAliases.d.ts → client/SiteMetadataDefaults.d.ts} +2 -4
- package/lib/client/SiteMetadataDefaults.js +19 -0
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +13 -0
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +15 -10
- package/lib/client/browserContext.d.ts +11 -0
- package/lib/client/browserContext.js +22 -0
- package/lib/client/client-lifecycles-dispatcher.d.ts +2 -5
- package/lib/client/client-lifecycles-dispatcher.js +6 -10
- package/lib/client/clientEntry.js +13 -7
- package/lib/client/docusaurus.d.ts +6 -0
- package/lib/client/docusaurus.js +16 -25
- package/lib/client/docusaurusContext.d.ts +12 -0
- package/lib/client/docusaurusContext.js +25 -0
- package/lib/client/exports/BrowserOnly.d.ts +2 -3
- package/lib/client/exports/BrowserOnly.js +14 -7
- package/lib/client/exports/ComponentCreator.d.ts +1 -2
- package/lib/client/exports/ComponentCreator.js +40 -19
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +35 -0
- package/lib/client/exports/Head.d.ts +2 -3
- package/lib/client/exports/Head.js +3 -4
- package/lib/client/exports/Interpolate.d.ts +2 -2
- package/lib/client/exports/Interpolate.js +20 -26
- package/lib/client/exports/Link.d.ts +11 -5
- package/lib/client/exports/Link.js +31 -20
- package/lib/client/exports/Translate.d.ts +1 -1
- package/lib/client/exports/Translate.js +14 -9
- package/lib/client/exports/constants.js +1 -11
- package/lib/client/exports/isInternalUrl.js +1 -1
- package/lib/client/exports/renderRoutes.d.ts +1 -2
- package/lib/client/exports/renderRoutes.js +1 -2
- package/lib/client/exports/router.d.ts +1 -1
- package/lib/client/exports/router.js +1 -1
- package/lib/client/exports/useBaseUrl.js +8 -5
- package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
- package/lib/client/exports/useDocusaurusContext.js +3 -9
- package/lib/client/exports/useGlobalData.d.ts +4 -3
- package/lib/client/exports/useGlobalData.js +4 -8
- package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
- package/lib/client/exports/useIsBrowser.js +11 -0
- package/lib/{server/loadSetup.d.ts → client/exports/useRouteContext.d.ts} +2 -3
- package/lib/client/exports/useRouteContext.js +15 -0
- package/lib/client/flat.d.ts +4 -2
- package/lib/client/flat.js +9 -13
- package/lib/client/normalizeLocation.d.ts +2 -5
- package/lib/client/normalizeLocation.js +2 -7
- package/lib/client/nprogress.css +2 -2
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +4 -6
- package/lib/client/preload.d.ts +3 -2
- package/lib/client/preload.js +5 -10
- package/lib/client/routeContext.d.ts +13 -0
- package/lib/client/routeContext.js +31 -0
- package/lib/client/serverEntry.d.ts +10 -0
- package/lib/client/serverEntry.js +90 -142
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +43 -0
- package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
- package/lib/client/theme-fallback/Layout/index.js +2 -26
- package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
- package/lib/client/theme-fallback/Loading/index.js +47 -115
- package/lib/client/{exports/context.js → theme-fallback/NotFound/index.d.ts} +2 -2
- package/lib/client/theme-fallback/NotFound/index.js +17 -18
- package/lib/client/theme-fallback/Root/index.d.ts +10 -0
- package/lib/client/theme-fallback/Root/index.js +2 -6
- package/lib/client/theme-fallback/SiteMetadata/index.d.ts +8 -0
- package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
- package/lib/commands/build.d.ts +1 -1
- package/lib/commands/build.js +50 -54
- package/lib/commands/clear.d.ts +6 -0
- package/lib/commands/clear.js +30 -19
- package/lib/commands/commandUtils.d.ts +7 -1
- package/lib/commands/commandUtils.js +7 -7
- package/lib/commands/deploy.d.ts +1 -1
- package/lib/commands/deploy.js +83 -66
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +4 -8
- package/lib/commands/serve.d.ts +1 -1
- package/lib/commands/serve.js +25 -12
- package/lib/commands/start.d.ts +1 -1
- package/lib/commands/start.js +96 -87
- package/lib/commands/swizzle/actions.d.ts +23 -0
- package/lib/commands/swizzle/actions.js +101 -0
- package/lib/commands/swizzle/common.d.ts +33 -0
- package/lib/commands/swizzle/common.js +56 -0
- package/lib/commands/swizzle/components.d.ts +29 -0
- package/lib/commands/swizzle/components.js +162 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +80 -0
- package/lib/commands/swizzle/context.d.ts +8 -0
- package/lib/commands/swizzle/context.js +28 -0
- package/lib/commands/swizzle/index.d.ts +8 -0
- package/lib/commands/swizzle/index.js +115 -0
- package/lib/commands/swizzle/prompts.d.ts +12 -0
- package/lib/commands/swizzle/prompts.js +110 -0
- package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
- package/lib/commands/swizzle/tables.js +113 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +106 -0
- package/lib/commands/writeHeadingIds.d.ts +2 -6
- package/lib/commands/writeHeadingIds.js +19 -76
- package/lib/commands/writeTranslations.d.ts +2 -2
- package/lib/commands/writeTranslations.js +37 -17
- package/lib/index.d.ts +10 -9
- package/lib/index.js +20 -19
- package/lib/server/brokenLinks.d.ts +4 -17
- package/lib/server/brokenLinks.js +64 -52
- package/lib/server/client-modules/index.d.ts +2 -2
- package/lib/server/client-modules/index.js +4 -3
- package/lib/server/config.d.ts +2 -2
- package/lib/server/config.js +8 -5
- package/lib/server/configValidation.d.ts +4 -2
- package/lib/server/configValidation.js +93 -37
- package/lib/server/duplicateRoutes.d.ts +1 -3
- package/lib/server/duplicateRoutes.js +17 -13
- package/lib/server/html-tags/htmlTags.js +7 -8
- package/lib/server/html-tags/index.d.ts +2 -3
- package/lib/server/html-tags/index.js +3 -4
- package/lib/server/i18n.d.ts +2 -3
- package/lib/server/i18n.js +27 -48
- package/lib/server/index.d.ts +9 -2
- package/lib/server/index.js +175 -96
- package/lib/server/moduleShorthand.d.ts +9 -0
- package/lib/server/moduleShorthand.js +46 -0
- package/lib/server/plugins/applyRouteTrailingSlash.d.ts +9 -0
- package/lib/server/plugins/applyRouteTrailingSlash.js +19 -0
- package/lib/server/plugins/index.d.ts +4 -5
- package/lib/server/plugins/index.js +69 -45
- package/lib/server/plugins/init.d.ts +15 -5
- package/lib/server/plugins/init.js +68 -81
- package/lib/server/plugins/pluginIds.d.ts +2 -2
- package/lib/server/plugins/pluginIds.js +8 -5
- package/lib/server/presets/index.d.ts +3 -3
- package/lib/server/presets/index.js +16 -23
- package/lib/server/routes.d.ts +3 -5
- package/lib/server/routes.js +68 -36
- package/lib/server/themes/alias.d.ts +3 -2
- package/lib/server/themes/alias.js +24 -13
- package/lib/server/themes/index.d.ts +6 -2
- package/lib/server/themes/index.js +36 -24
- package/lib/server/translations/translations.d.ts +21 -17
- package/lib/server/translations/translations.js +33 -54
- package/lib/server/translations/translationsExtractor.d.ts +12 -5
- package/lib/server/translations/translationsExtractor.js +159 -121
- package/lib/server/utils.d.ts +9 -3
- package/lib/server/utils.js +7 -9
- package/lib/server/versions/index.d.ts +3 -4
- package/lib/server/versions/index.js +22 -24
- package/lib/webpack/base.d.ts +6 -4
- package/lib/webpack/base.js +51 -36
- package/lib/webpack/client.d.ts +3 -3
- package/lib/webpack/client.js +12 -19
- package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
- package/lib/webpack/plugins/ChunkAssetPlugin.js +24 -17
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -6
- package/lib/webpack/plugins/CleanWebpackPlugin.js +10 -16
- package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
- package/lib/webpack/plugins/LogPlugin.js +4 -5
- package/lib/webpack/plugins/WaitPlugin.d.ts +1 -1
- package/lib/webpack/plugins/WaitPlugin.js +1 -1
- package/lib/webpack/server.d.ts +3 -3
- package/lib/webpack/server.js +14 -7
- package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
- package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
- package/lib/{client → webpack}/templates/ssr.html.template.js +5 -4
- package/lib/webpack/utils.d.ts +15 -30
- package/lib/webpack/utils.js +57 -175
- package/package.json +77 -70
- package/bin/docusaurus.js +0 -326
- package/lib/.tsbuildinfo +0 -5732
- package/lib/client/.tsbuildinfo +0 -4171
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- package/lib/commands/swizzle.d.ts +0 -9
- package/lib/commands/swizzle.js +0 -245
- package/lib/constants.d.ts +0 -18
- package/lib/constants.js +0 -23
- package/lib/server/loadSetup.js +0 -25
- package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
- package/lib/server/versions/__fixtures__/package.json +0 -3
- package/lib/server/versions/__tests/index.test.js +0 -25
- package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
- package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
- package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
- package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
- package/lib/webpack/sharedModuleAliases.js +0 -18
- package/tsconfig.client.json +0 -13
- package/tsconfig.json +0 -13
|
@@ -0,0 +1,133 @@
|
|
|
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
|
+
|
|
8
|
+
// @ts-check
|
|
9
|
+
|
|
10
|
+
import logger from '@docusaurus/logger';
|
|
11
|
+
import fs from 'fs-extra';
|
|
12
|
+
import semver from 'semver';
|
|
13
|
+
import path from 'path';
|
|
14
|
+
import updateNotifier from 'update-notifier';
|
|
15
|
+
import boxen from 'boxen';
|
|
16
|
+
import {createRequire} from 'module';
|
|
17
|
+
|
|
18
|
+
const packageJson = createRequire(import.meta.url)('../package.json');
|
|
19
|
+
const sitePkg = createRequire(path.join(process.cwd(), 'package.json'))(
|
|
20
|
+
'./package.json',
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
name,
|
|
25
|
+
version,
|
|
26
|
+
engines: {node: requiredVersion},
|
|
27
|
+
} = packageJson;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Notify user if `@docusaurus` packages are outdated
|
|
31
|
+
*
|
|
32
|
+
* Note: this is a 2-step process to avoid delaying cli usage by awaiting a
|
|
33
|
+
* response:
|
|
34
|
+
* - 1st run: trigger background job to check releases + store result
|
|
35
|
+
* - 2nd run: display potential update to users
|
|
36
|
+
*
|
|
37
|
+
* cache data is stored in `~/.config/configstore/update-notifier-@docusaurus`
|
|
38
|
+
*/
|
|
39
|
+
export default async function beforeCli() {
|
|
40
|
+
const notifier = updateNotifier({
|
|
41
|
+
pkg: {
|
|
42
|
+
name,
|
|
43
|
+
version,
|
|
44
|
+
},
|
|
45
|
+
// Check is in background so it's fine to use a small value like 1h
|
|
46
|
+
// Use 0 for debugging
|
|
47
|
+
updateCheckInterval: 1000 * 60 * 60,
|
|
48
|
+
// updateCheckInterval: 0
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Hacky way to ensure we check for updates on first run
|
|
52
|
+
// Note: the notification will only happen in the 2nd run
|
|
53
|
+
// See https://github.com/yeoman/update-notifier/issues/209
|
|
54
|
+
try {
|
|
55
|
+
if (
|
|
56
|
+
notifier.config &&
|
|
57
|
+
// @ts-expect-error: this is an internal API
|
|
58
|
+
!notifier.disabled &&
|
|
59
|
+
Date.now() - notifier.config.get('lastUpdateCheck') < 50
|
|
60
|
+
) {
|
|
61
|
+
notifier.config.set('lastUpdateCheck', 0);
|
|
62
|
+
notifier.check();
|
|
63
|
+
}
|
|
64
|
+
} catch (err) {
|
|
65
|
+
// Do not stop cli if this fails, see https://github.com/facebook/docusaurus/issues/5400
|
|
66
|
+
logger.error(err);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* We don't want to display update message for canary releases.
|
|
71
|
+
* See https://github.com/facebook/docusaurus/issues/5378
|
|
72
|
+
* @param {import('update-notifier').UpdateInfo} update
|
|
73
|
+
*/
|
|
74
|
+
function ignoreUpdate(update) {
|
|
75
|
+
const isCanaryRelease = update?.current?.startsWith('0.0.0');
|
|
76
|
+
return isCanaryRelease;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (
|
|
80
|
+
notifier.config &&
|
|
81
|
+
notifier.update &&
|
|
82
|
+
semver.lt(notifier.update.current, notifier.update.latest)
|
|
83
|
+
) {
|
|
84
|
+
// Because notifier clears cached data after reading it, leading to notifier
|
|
85
|
+
// not consistently displaying the update.
|
|
86
|
+
// See https://github.com/yeoman/update-notifier/issues/209
|
|
87
|
+
notifier.config.set('update', notifier.update);
|
|
88
|
+
|
|
89
|
+
if (ignoreUpdate(notifier.update)) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const siteDocusaurusPackagesForUpdate = Object.keys({
|
|
94
|
+
...sitePkg.dependencies,
|
|
95
|
+
...sitePkg.devDependencies,
|
|
96
|
+
})
|
|
97
|
+
.filter((p) => p.startsWith('@docusaurus'))
|
|
98
|
+
.map((p) => p.concat('@latest'))
|
|
99
|
+
.join(' ');
|
|
100
|
+
const isYarnUsed = await fs.pathExists(path.resolve('yarn.lock'));
|
|
101
|
+
const upgradeCommand = isYarnUsed
|
|
102
|
+
? `yarn upgrade ${siteDocusaurusPackagesForUpdate}`
|
|
103
|
+
: `npm i ${siteDocusaurusPackagesForUpdate}`;
|
|
104
|
+
|
|
105
|
+
/** @type {import('boxen').Options} */
|
|
106
|
+
const boxenOptions = {
|
|
107
|
+
padding: 1,
|
|
108
|
+
margin: 1,
|
|
109
|
+
align: 'center',
|
|
110
|
+
borderColor: 'yellow',
|
|
111
|
+
borderStyle: 'round',
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const docusaurusUpdateMessage = boxen(
|
|
115
|
+
`Update available ${logger.dim(
|
|
116
|
+
`${notifier.update.current}`,
|
|
117
|
+
)} → ${logger.green(`${notifier.update.latest}`)}
|
|
118
|
+
|
|
119
|
+
To upgrade Docusaurus packages with the latest version, run the following command:
|
|
120
|
+
${logger.code(upgradeCommand)}`,
|
|
121
|
+
boxenOptions,
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
console.log(docusaurusUpdateMessage);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// notify user if node version needs to be updated
|
|
128
|
+
if (!semver.satisfies(process.version, requiredVersion)) {
|
|
129
|
+
logger.error('Minimum Node.js version not met :(');
|
|
130
|
+
logger.info`You are using Node.js number=${process.version}, Requirement: Node.js number=${requiredVersion}.`;
|
|
131
|
+
process.exit(1);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
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
|
+
|
|
9
|
+
// @ts-check
|
|
10
|
+
|
|
11
|
+
import logger from '@docusaurus/logger';
|
|
12
|
+
import fs from 'fs-extra';
|
|
13
|
+
import cli from 'commander';
|
|
14
|
+
import {createRequire} from 'module';
|
|
15
|
+
import {
|
|
16
|
+
build,
|
|
17
|
+
swizzle,
|
|
18
|
+
deploy,
|
|
19
|
+
start,
|
|
20
|
+
externalCommand,
|
|
21
|
+
serve,
|
|
22
|
+
clear,
|
|
23
|
+
writeTranslations,
|
|
24
|
+
writeHeadingIds,
|
|
25
|
+
} from '../lib/index.js';
|
|
26
|
+
import beforeCli from './beforeCli.mjs';
|
|
27
|
+
|
|
28
|
+
await beforeCli();
|
|
29
|
+
|
|
30
|
+
const resolveDir = (dir = '.') => fs.realpath(dir);
|
|
31
|
+
|
|
32
|
+
cli
|
|
33
|
+
.version(createRequire(import.meta.url)('../package.json').version)
|
|
34
|
+
.usage('<command> [options]');
|
|
35
|
+
|
|
36
|
+
cli
|
|
37
|
+
.command('build [siteDir]')
|
|
38
|
+
.description('Build website.')
|
|
39
|
+
.option(
|
|
40
|
+
'--bundle-analyzer',
|
|
41
|
+
'visualize size of webpack output files with an interactive zoomable tree map (default: false)',
|
|
42
|
+
)
|
|
43
|
+
.option(
|
|
44
|
+
'--out-dir <dir>',
|
|
45
|
+
'the full path for the new output directory, relative to the current workspace (default: build)',
|
|
46
|
+
)
|
|
47
|
+
.option(
|
|
48
|
+
'--config <config>',
|
|
49
|
+
'path to docusaurus config file (default: `[siteDir]/docusaurus.config.js`)',
|
|
50
|
+
)
|
|
51
|
+
.option(
|
|
52
|
+
'-l, --locale <locale>',
|
|
53
|
+
'build the site in a specified locale. Build all known locales otherwise',
|
|
54
|
+
)
|
|
55
|
+
.option(
|
|
56
|
+
'--no-minify',
|
|
57
|
+
'build website without minimizing JS bundles (default: false)',
|
|
58
|
+
)
|
|
59
|
+
.action(async (siteDir, {bundleAnalyzer, config, outDir, locale, minify}) => {
|
|
60
|
+
build(await resolveDir(siteDir), {
|
|
61
|
+
bundleAnalyzer,
|
|
62
|
+
outDir,
|
|
63
|
+
config,
|
|
64
|
+
locale,
|
|
65
|
+
minify,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
cli
|
|
70
|
+
.command('swizzle [themeName] [componentName] [siteDir]')
|
|
71
|
+
.description(
|
|
72
|
+
'Wraps or ejects the original theme files into website folder for customization.',
|
|
73
|
+
)
|
|
74
|
+
.option(
|
|
75
|
+
'-w, --wrap',
|
|
76
|
+
'Creates a wrapper around the original theme component.\nAllows rendering other components before/after the original theme component.',
|
|
77
|
+
)
|
|
78
|
+
.option(
|
|
79
|
+
'-e, --eject',
|
|
80
|
+
'Ejects the full source code of the original theme component.\nAllows overriding the original component entirely with your own UI and logic.',
|
|
81
|
+
)
|
|
82
|
+
.option(
|
|
83
|
+
'-l, --list',
|
|
84
|
+
'only list the available themes/components without further prompting (default: false)',
|
|
85
|
+
)
|
|
86
|
+
.option(
|
|
87
|
+
'-t, --typescript',
|
|
88
|
+
'copy TypeScript theme files when possible (default: false)',
|
|
89
|
+
)
|
|
90
|
+
.option('--danger', 'enable swizzle for unsafe component of themes')
|
|
91
|
+
.action(async (themeName, componentName, siteDir, options) => {
|
|
92
|
+
swizzle(await resolveDir(siteDir), themeName, componentName, options);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
cli
|
|
96
|
+
.command('deploy [siteDir]')
|
|
97
|
+
.description('Deploy website to GitHub pages.')
|
|
98
|
+
.option(
|
|
99
|
+
'-l, --locale <locale>',
|
|
100
|
+
'deploy the site in a specified locale. Deploy all known locales otherwise',
|
|
101
|
+
)
|
|
102
|
+
.option(
|
|
103
|
+
'--out-dir <dir>',
|
|
104
|
+
'the full path for the new output directory, relative to the current workspace (default: build)',
|
|
105
|
+
)
|
|
106
|
+
.option(
|
|
107
|
+
'--config <config>',
|
|
108
|
+
'path to Docusaurus config file (default: `[siteDir]/docusaurus.config.js`)',
|
|
109
|
+
)
|
|
110
|
+
.option(
|
|
111
|
+
'--skip-build',
|
|
112
|
+
'skip building website before deploy it (default: false)',
|
|
113
|
+
)
|
|
114
|
+
.action(async (siteDir, {outDir, skipBuild, config}) => {
|
|
115
|
+
deploy(await resolveDir(siteDir), {
|
|
116
|
+
outDir,
|
|
117
|
+
config,
|
|
118
|
+
skipBuild,
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
cli
|
|
123
|
+
.command('start [siteDir]')
|
|
124
|
+
.description('Start the development server.')
|
|
125
|
+
.option('-p, --port <port>', 'use specified port (default: 3000)')
|
|
126
|
+
.option('-h, --host <host>', 'use specified host (default: localhost)')
|
|
127
|
+
.option('-l, --locale <locale>', 'use specified site locale')
|
|
128
|
+
.option(
|
|
129
|
+
'--hot-only',
|
|
130
|
+
'do not fallback to page refresh if hot reload fails (default: false)',
|
|
131
|
+
)
|
|
132
|
+
.option(
|
|
133
|
+
'--config <config>',
|
|
134
|
+
'path to Docusaurus config file (default: `[siteDir]/docusaurus.config.js`)',
|
|
135
|
+
)
|
|
136
|
+
.option('--no-open', 'do not open page in the browser (default: false)')
|
|
137
|
+
.option(
|
|
138
|
+
'--poll [interval]',
|
|
139
|
+
'use polling rather than watching for reload (default: false). Can specify a poll interval in milliseconds',
|
|
140
|
+
)
|
|
141
|
+
.action(
|
|
142
|
+
async (siteDir, {port, host, locale, config, hotOnly, open, poll}) => {
|
|
143
|
+
start(await resolveDir(siteDir), {
|
|
144
|
+
port,
|
|
145
|
+
host,
|
|
146
|
+
locale,
|
|
147
|
+
config,
|
|
148
|
+
hotOnly,
|
|
149
|
+
open,
|
|
150
|
+
poll,
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
cli
|
|
156
|
+
.command('serve [siteDir]')
|
|
157
|
+
.description('Serve website locally.')
|
|
158
|
+
.option(
|
|
159
|
+
'--dir <dir>',
|
|
160
|
+
'the full path for the new output directory, relative to the current workspace (default: build)',
|
|
161
|
+
)
|
|
162
|
+
.option(
|
|
163
|
+
'--config <config>',
|
|
164
|
+
'path to Docusaurus config file (default: `[siteDir]/docusaurus.config.js`)',
|
|
165
|
+
)
|
|
166
|
+
.option('-p, --port <port>', 'use specified port (default: 3000)')
|
|
167
|
+
.option('--build', 'build website before serving (default: false)')
|
|
168
|
+
.option('-h, --host <host>', 'use specified host (default: localhost)')
|
|
169
|
+
.action(
|
|
170
|
+
async (
|
|
171
|
+
siteDir,
|
|
172
|
+
{
|
|
173
|
+
dir = 'build',
|
|
174
|
+
port = 3000,
|
|
175
|
+
host = 'localhost',
|
|
176
|
+
build: buildSite = false,
|
|
177
|
+
config,
|
|
178
|
+
},
|
|
179
|
+
) => {
|
|
180
|
+
serve(await resolveDir(siteDir), {
|
|
181
|
+
dir,
|
|
182
|
+
port,
|
|
183
|
+
build: buildSite,
|
|
184
|
+
config,
|
|
185
|
+
host,
|
|
186
|
+
});
|
|
187
|
+
},
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
cli
|
|
191
|
+
.command('clear [siteDir]')
|
|
192
|
+
.description('Remove build artifacts.')
|
|
193
|
+
.action(async (siteDir) => {
|
|
194
|
+
clear(await resolveDir(siteDir));
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
cli
|
|
198
|
+
.command('write-translations [siteDir]')
|
|
199
|
+
.description('Extract required translations of your site.')
|
|
200
|
+
.option(
|
|
201
|
+
'-l, --locale <locale>',
|
|
202
|
+
'the locale folder to write the translations\n"--locale fr" will write translations in ./i18n/fr folder)',
|
|
203
|
+
)
|
|
204
|
+
.option(
|
|
205
|
+
'--override',
|
|
206
|
+
'by default, we only append missing translation messages to existing translation files. This option allows to override existing translation messages. Make sure to commit or backup your existing translations, as they may be overridden',
|
|
207
|
+
)
|
|
208
|
+
.option(
|
|
209
|
+
'--config <config>',
|
|
210
|
+
'path to Docusaurus config file (default:`[siteDir]/docusaurus.config.js`)',
|
|
211
|
+
)
|
|
212
|
+
.option(
|
|
213
|
+
'--messagePrefix <messagePrefix>',
|
|
214
|
+
'allows to init new written messages with a given prefix. This might help you to highlight untranslated message to make them stand out in the UI',
|
|
215
|
+
)
|
|
216
|
+
.action(
|
|
217
|
+
async (
|
|
218
|
+
siteDir,
|
|
219
|
+
{locale = undefined, override = false, messagePrefix = '', config},
|
|
220
|
+
) => {
|
|
221
|
+
writeTranslations(await resolveDir(siteDir), {
|
|
222
|
+
locale,
|
|
223
|
+
override,
|
|
224
|
+
config,
|
|
225
|
+
messagePrefix,
|
|
226
|
+
});
|
|
227
|
+
},
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
cli
|
|
231
|
+
.command('write-heading-ids [siteDir] [files...]')
|
|
232
|
+
.description('Generate heading ids in Markdown content.')
|
|
233
|
+
.option(
|
|
234
|
+
'--maintain-case',
|
|
235
|
+
"keep the headings' casing, otherwise make all lowercase (default: false)",
|
|
236
|
+
)
|
|
237
|
+
.option('--overwrite', 'overwrite existing heading IDs (default: false)')
|
|
238
|
+
.action(async (siteDir, files, options) =>
|
|
239
|
+
writeHeadingIds(await resolveDir(siteDir), files, options),
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
cli.arguments('<command>').action((cmd) => {
|
|
243
|
+
cli.outputHelp();
|
|
244
|
+
logger.error` Unknown command name=${cmd}.`;
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* @param {string | undefined} command
|
|
249
|
+
*/
|
|
250
|
+
function isInternalCommand(command) {
|
|
251
|
+
return (
|
|
252
|
+
command &&
|
|
253
|
+
[
|
|
254
|
+
'start',
|
|
255
|
+
'build',
|
|
256
|
+
'swizzle',
|
|
257
|
+
'deploy',
|
|
258
|
+
'serve',
|
|
259
|
+
'clear',
|
|
260
|
+
'write-translations',
|
|
261
|
+
'write-heading-ids',
|
|
262
|
+
].includes(command)
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (!isInternalCommand(process.argv.slice(2)[0])) {
|
|
267
|
+
await externalCommand(cli, await resolveDir('.'));
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (!process.argv.slice(2).length) {
|
|
271
|
+
cli.outputHelp();
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
cli.parse(process.argv);
|
|
275
|
+
|
|
276
|
+
process.on('unhandledRejection', (err) => {
|
|
277
|
+
logger.error(err);
|
|
278
|
+
process.exit(1);
|
|
279
|
+
});
|
package/lib/babel/preset.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
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 { ConfigAPI, TransformOptions } from '@babel/core';
|
|
8
|
+
export default function babelPresets(api: ConfigAPI): TransformOptions;
|
package/lib/babel/preset.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
2
|
/**
|
|
5
3
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
4
|
*
|
|
7
5
|
* This source code is licensed under the MIT license found in the
|
|
8
6
|
* LICENSE file in the root directory of this source tree.
|
|
9
7
|
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
10
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
11
11
|
function getTransformOptions(isServer) {
|
|
12
12
|
const absoluteRuntimePath = path_1.default.dirname(require.resolve(`@babel/runtime/package.json`));
|
|
13
13
|
return {
|
|
14
|
-
// All optional newlines and whitespace will be omitted when generating code
|
|
14
|
+
// All optional newlines and whitespace will be omitted when generating code
|
|
15
|
+
// in compact mode
|
|
15
16
|
compact: true,
|
|
16
17
|
presets: [
|
|
17
18
|
isServer
|
|
@@ -46,9 +47,9 @@ function getTransformOptions(isServer) {
|
|
|
46
47
|
{
|
|
47
48
|
corejs: false,
|
|
48
49
|
helpers: true,
|
|
49
|
-
// By default, it assumes @babel/runtime@7.0.0. Since we use >7.0.0,
|
|
50
|
-
// explicitly specify the version so that it can reuse the
|
|
51
|
-
// See https://github.com/babel/babel/issues/10261
|
|
50
|
+
// By default, it assumes @babel/runtime@7.0.0. Since we use >7.0.0,
|
|
51
|
+
// better to explicitly specify the version so that it can reuse the
|
|
52
|
+
// helper better. See https://github.com/babel/babel/issues/10261
|
|
52
53
|
// eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
|
|
53
54
|
version: require('@babel/runtime/package.json').version,
|
|
54
55
|
regenerator: true,
|
|
@@ -67,7 +68,7 @@ function getTransformOptions(isServer) {
|
|
|
67
68
|
};
|
|
68
69
|
}
|
|
69
70
|
function babelPresets(api) {
|
|
70
|
-
const callerName = api.caller((caller) => caller
|
|
71
|
+
const callerName = api.caller((caller) => caller?.name);
|
|
71
72
|
return getTransformOptions(callerName === 'server');
|
|
72
73
|
}
|
|
73
74
|
exports.default = babelPresets;
|
package/lib/choosePort.js
CHANGED
|
@@ -14,7 +14,7 @@ const tslib_1 = require("tslib");
|
|
|
14
14
|
const child_process_1 = require("child_process");
|
|
15
15
|
const detect_port_1 = tslib_1.__importDefault(require("detect-port"));
|
|
16
16
|
const is_root_1 = tslib_1.__importDefault(require("is-root"));
|
|
17
|
-
const
|
|
17
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
18
18
|
const prompts_1 = tslib_1.__importDefault(require("prompts"));
|
|
19
19
|
const isInteractive = process.stdout.isTTY;
|
|
20
20
|
const execOptions = {
|
|
@@ -22,7 +22,7 @@ const execOptions = {
|
|
|
22
22
|
stdio: [
|
|
23
23
|
'pipe',
|
|
24
24
|
'pipe',
|
|
25
|
-
'ignore',
|
|
25
|
+
'ignore',
|
|
26
26
|
],
|
|
27
27
|
};
|
|
28
28
|
// Clears console
|
|
@@ -31,21 +31,18 @@ function clearConsole() {
|
|
|
31
31
|
}
|
|
32
32
|
// Gets process id of what is on port
|
|
33
33
|
function getProcessIdOnPort(port) {
|
|
34
|
-
return child_process_1.execSync(`lsof -i:${port} -P -t -sTCP:LISTEN`, execOptions)
|
|
35
|
-
.toString()
|
|
34
|
+
return (0, child_process_1.execSync)(`lsof -i:${port} -P -t -sTCP:LISTEN`, execOptions)
|
|
36
35
|
.split('\n')[0]
|
|
37
36
|
.trim();
|
|
38
37
|
}
|
|
39
38
|
// Gets process command
|
|
40
39
|
function getProcessCommand(processId) {
|
|
41
|
-
const command = child_process_1.execSync(`ps -o command -p ${processId} | sed -n 2p`, execOptions);
|
|
42
|
-
return command.
|
|
40
|
+
const command = (0, child_process_1.execSync)(`ps -o command -p ${processId} | sed -n 2p`, execOptions);
|
|
41
|
+
return command.replace(/\n$/, '');
|
|
43
42
|
}
|
|
44
43
|
// Gets directory of a process from its process id
|
|
45
44
|
function getDirectoryOfProcessById(processId) {
|
|
46
|
-
return child_process_1.execSync(`lsof -p ${processId} | awk '$4=="cwd" {for (i=9; i<=NF; i++) printf "%s ", $i}'`, execOptions)
|
|
47
|
-
.toString()
|
|
48
|
-
.trim();
|
|
45
|
+
return (0, child_process_1.execSync)(`lsof -p ${processId} | awk '$4=="cwd" {for (i=9; i<=NF; i++) printf "%s ", $i}'`, execOptions).trim();
|
|
49
46
|
}
|
|
50
47
|
// Gets process on port
|
|
51
48
|
function getProcessForPort(port) {
|
|
@@ -53,12 +50,9 @@ function getProcessForPort(port) {
|
|
|
53
50
|
const processId = getProcessIdOnPort(port);
|
|
54
51
|
const directory = getDirectoryOfProcessById(processId);
|
|
55
52
|
const command = getProcessCommand(processId);
|
|
56
|
-
return
|
|
57
|
-
chalk_1.default.grey(` (pid ${processId})\n`) +
|
|
58
|
-
chalk_1.default.blue(' in ') +
|
|
59
|
-
chalk_1.default.cyan(directory));
|
|
53
|
+
return logger_1.default.interpolate `code=${command} subdue=${`(pid ${processId})`} in path=${directory}`;
|
|
60
54
|
}
|
|
61
|
-
catch
|
|
55
|
+
catch {
|
|
62
56
|
return null;
|
|
63
57
|
}
|
|
64
58
|
}
|
|
@@ -67,39 +61,33 @@ function getProcessForPort(port) {
|
|
|
67
61
|
* to choose another if port is already being used
|
|
68
62
|
*/
|
|
69
63
|
async function choosePort(host, defaultPort) {
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
try {
|
|
65
|
+
const port = await (0, detect_port_1.default)({ port: defaultPort, hostname: host });
|
|
72
66
|
if (port === defaultPort) {
|
|
73
|
-
return
|
|
67
|
+
return port;
|
|
74
68
|
}
|
|
75
|
-
const message = process.platform !== 'win32' && defaultPort < 1024 && !is_root_1.default()
|
|
69
|
+
const message = process.platform !== 'win32' && defaultPort < 1024 && !(0, is_root_1.default)()
|
|
76
70
|
? `Admin permissions are required to run a server on a port below 1024.`
|
|
77
71
|
: `Something is already running on port ${defaultPort}.`;
|
|
78
|
-
if (isInteractive) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const question = {
|
|
82
|
-
type: 'confirm',
|
|
83
|
-
name: 'shouldChangePort',
|
|
84
|
-
message: `${chalk_1.default.yellow(`${message}${existingProcess ? ` Probably:\n ${existingProcess}` : ''}`)}\n\nWould you like to run the app on another port instead?`,
|
|
85
|
-
initial: true,
|
|
86
|
-
};
|
|
87
|
-
prompts_1.default(question).then((answer) => {
|
|
88
|
-
if (answer.shouldChangePort === true) {
|
|
89
|
-
resolve(port);
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
resolve(null);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
console.log(chalk_1.default.red(message));
|
|
98
|
-
resolve(null);
|
|
72
|
+
if (!isInteractive) {
|
|
73
|
+
logger_1.default.error(message);
|
|
74
|
+
return null;
|
|
99
75
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
76
|
+
clearConsole();
|
|
77
|
+
const existingProcess = getProcessForPort(defaultPort);
|
|
78
|
+
const { shouldChangePort } = await (0, prompts_1.default)({
|
|
79
|
+
type: 'confirm',
|
|
80
|
+
name: 'shouldChangePort',
|
|
81
|
+
message: logger_1.default.yellow(`${logger_1.default.bold('[WARNING]')} ${message}${existingProcess ? ` Probably:\n ${existingProcess}` : ''}
|
|
82
|
+
|
|
83
|
+
Would you like to run the app on another port instead?`),
|
|
84
|
+
initial: true,
|
|
85
|
+
});
|
|
86
|
+
return shouldChangePort ? port : null;
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
logger_1.default.error `Could not find an open port at ${host}.`;
|
|
90
|
+
throw err;
|
|
91
|
+
}
|
|
104
92
|
}
|
|
105
93
|
exports.default = choosePort;
|
package/lib/client/.eslintrc.js
CHANGED
package/lib/client/App.d.ts
CHANGED
package/lib/client/App.js
CHANGED
|
@@ -4,34 +4,33 @@
|
|
|
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 React
|
|
7
|
+
import React from 'react';
|
|
8
8
|
import routes from '@generated/routes';
|
|
9
|
-
import siteConfig from '@generated/docusaurus.config';
|
|
10
|
-
import globalData from '@generated/globalData';
|
|
11
|
-
import i18n from '@generated/i18n';
|
|
12
|
-
import codeTranslations from '@generated/codeTranslations';
|
|
13
|
-
import siteMetadata from '@generated/site-metadata';
|
|
14
9
|
import renderRoutes from './exports/renderRoutes';
|
|
15
|
-
import
|
|
10
|
+
import { BrowserContextProvider } from './browserContext';
|
|
11
|
+
import { DocusaurusContextProvider } from './docusaurusContext';
|
|
16
12
|
import PendingNavigation from './PendingNavigation';
|
|
17
13
|
import BaseUrlIssueBanner from './baseUrlIssueBanner/BaseUrlIssueBanner';
|
|
14
|
+
import SiteMetadataDefaults from './SiteMetadataDefaults';
|
|
18
15
|
import Root from '@theme/Root';
|
|
16
|
+
import SiteMetadata from '@theme/SiteMetadata';
|
|
19
17
|
import './client-lifecycles-dispatcher';
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
18
|
+
// TODO, quick fix for CSS insertion order
|
|
19
|
+
import ErrorBoundary from '@docusaurus/ErrorBoundary';
|
|
20
|
+
import Error from '@theme/Error';
|
|
21
|
+
export default function App() {
|
|
22
|
+
return (<ErrorBoundary fallback={Error}>
|
|
23
|
+
<DocusaurusContextProvider>
|
|
24
|
+
<BrowserContextProvider>
|
|
25
|
+
<Root>
|
|
26
|
+
<SiteMetadataDefaults />
|
|
27
|
+
<SiteMetadata />
|
|
28
|
+
<BaseUrlIssueBanner />
|
|
29
|
+
<PendingNavigation routes={routes} delay={1000}>
|
|
30
|
+
{renderRoutes(routes)}
|
|
31
|
+
</PendingNavigation>
|
|
32
|
+
</Root>
|
|
33
|
+
</BrowserContextProvider>
|
|
34
|
+
</DocusaurusContextProvider>
|
|
35
|
+
</ErrorBoundary>);
|
|
36
36
|
}
|
|
37
|
-
export default App;
|
|
@@ -4,7 +4,7 @@
|
|
|
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 { ReactNode } from 'react';
|
|
7
|
+
import { type ReactNode } from 'react';
|
|
8
8
|
declare type LinksCollector = {
|
|
9
9
|
collectLink: (link: string) => void;
|
|
10
10
|
};
|
|
@@ -13,8 +13,8 @@ declare type StatefulLinksCollector = LinksCollector & {
|
|
|
13
13
|
};
|
|
14
14
|
export declare const createStatefulLinksCollector: () => StatefulLinksCollector;
|
|
15
15
|
export declare const useLinksCollector: () => LinksCollector;
|
|
16
|
-
export declare
|
|
16
|
+
export declare function LinksCollectorProvider({ children, linksCollector, }: {
|
|
17
17
|
children: ReactNode;
|
|
18
18
|
linksCollector: LinksCollector;
|
|
19
|
-
})
|
|
19
|
+
}): JSX.Element;
|
|
20
20
|
export {};
|