@docusaurus/core 2.0.0-beta.12faed89d → 2.0.0-beta.14
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.js +46 -22
- package/bin/docusaurus.js +42 -44
- package/lib/babel/preset.d.ts +6 -0
- package/lib/babel/preset.js +3 -3
- package/lib/choosePort.js +19 -20
- package/lib/client/.eslintrc.js +0 -1
- package/lib/client/App.js +12 -22
- package/lib/client/LinksCollector.d.ts +2 -2
- package/lib/client/LinksCollector.js +4 -8
- package/lib/client/PendingNavigation.d.ts +24 -1
- package/lib/client/PendingNavigation.js +1 -1
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +5 -0
- package/lib/client/client-lifecycles-dispatcher.d.ts +2 -2
- package/lib/client/client-lifecycles-dispatcher.js +0 -2
- package/lib/client/docusaurus.d.ts +6 -0
- package/lib/client/docusaurus.js +11 -19
- package/lib/client/exports/BrowserOnly.js +5 -3
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +35 -0
- package/lib/client/exports/Interpolate.js +12 -15
- package/lib/client/exports/Link.js +9 -9
- package/lib/client/exports/Translate.d.ts +2 -2
- package/lib/client/exports/Translate.js +13 -9
- package/lib/client/exports/browserContext.d.ts +11 -0
- package/lib/client/exports/browserContext.js +21 -0
- package/lib/client/exports/constants.js +1 -11
- package/lib/client/exports/{context.d.ts → docusaurusContext.d.ts} +5 -3
- package/lib/client/exports/docusaurusContext.js +25 -0
- package/lib/client/exports/useBaseUrl.js +2 -4
- package/lib/client/exports/useDocusaurusContext.js +2 -7
- package/lib/client/exports/useGlobalData.js +1 -5
- package/lib/client/exports/{context.js → useIsBrowser.d.ts} +1 -2
- package/lib/{webpack/sharedModuleAliases.d.ts → client/exports/useIsBrowser.js} +5 -4
- package/lib/client/flat.d.ts +2 -1
- package/lib/client/flat.js +7 -9
- package/lib/client/normalizeLocation.d.ts +1 -3
- package/lib/client/prefetch.js +0 -1
- package/lib/client/serverEntry.js +20 -42
- package/lib/client/theme-fallback/Error/index.js +47 -0
- package/lib/client/theme-fallback/Layout/index.js +1 -1
- package/lib/client/theme-fallback/Loading/index.js +2 -2
- package/lib/client/theme-fallback/Root/index.js +1 -3
- package/lib/commands/build.js +39 -44
- package/lib/commands/clear.d.ts +6 -0
- package/lib/commands/clear.js +17 -18
- package/lib/commands/commandUtils.d.ts +6 -0
- package/lib/commands/commandUtils.js +7 -7
- package/lib/commands/deploy.d.ts +3 -0
- package/lib/commands/deploy.js +99 -64
- package/lib/commands/external.js +4 -4
- package/lib/commands/serve.js +12 -18
- package/lib/commands/start.js +98 -86
- package/lib/commands/swizzle.js +42 -51
- package/lib/commands/writeHeadingIds.d.ts +9 -6
- package/lib/commands/writeHeadingIds.js +33 -34
- package/lib/commands/writeTranslations.js +31 -11
- package/lib/server/brokenLinks.js +13 -17
- package/lib/server/client-modules/index.js +1 -3
- package/lib/server/config.js +4 -4
- package/lib/server/configValidation.d.ts +1 -1
- package/lib/server/configValidation.js +14 -7
- package/lib/server/duplicateRoutes.js +8 -2
- package/lib/server/html-tags/htmlTags.js +5 -6
- package/lib/server/html-tags/index.js +2 -2
- package/lib/server/i18n.js +16 -16
- package/lib/server/index.js +132 -59
- package/lib/server/loadSetup.js +3 -3
- package/lib/server/moduleShorthand.d.ts +9 -0
- package/lib/server/moduleShorthand.js +42 -0
- package/lib/server/plugins/applyRouteTrailingSlash.js +1 -1
- package/lib/server/plugins/index.d.ts +1 -1
- package/lib/server/plugins/index.js +25 -21
- package/lib/server/plugins/init.js +9 -12
- package/lib/server/plugins/pluginIds.js +6 -4
- package/lib/server/presets/index.js +12 -12
- package/lib/server/routes.js +9 -11
- package/lib/server/themes/alias.d.ts +1 -0
- package/lib/server/themes/alias.js +21 -12
- package/lib/server/themes/index.d.ts +1 -1
- package/lib/server/themes/index.js +22 -23
- package/lib/server/translations/translations.d.ts +6 -0
- package/lib/server/translations/translations.js +19 -26
- package/lib/server/translations/translationsExtractor.d.ts +7 -1
- package/lib/server/translations/translationsExtractor.js +66 -59
- package/lib/server/utils.d.ts +8 -2
- package/lib/server/utils.js +8 -10
- package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
- package/lib/server/versions/__tests/index.test.js +5 -5
- package/lib/server/versions/index.js +6 -6
- package/lib/webpack/base.js +14 -16
- package/lib/webpack/client.js +9 -18
- package/lib/webpack/plugins/CleanWebpackPlugin.js +4 -11
- package/lib/webpack/plugins/LogPlugin.js +5 -6
- package/lib/webpack/plugins/WaitPlugin.js +4 -4
- package/lib/webpack/server.js +9 -9
- package/lib/webpack/utils.d.ts +0 -22
- package/lib/webpack/utils.js +37 -134
- package/package.json +55 -50
- package/lib/.tsbuildinfo +0 -1
- package/lib/client/.tsbuildinfo +0 -1
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- package/lib/constants.d.ts +0 -18
- package/lib/constants.js +0 -23
- 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
package/lib/commands/build.js
CHANGED
|
@@ -7,28 +7,29 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
|
-
const
|
|
11
|
-
const copy_webpack_plugin_1 = tslib_1.__importDefault(require("copy-webpack-plugin"));
|
|
12
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
14
|
-
const react_loadable_ssr_addon_v5_slorber_1 = tslib_1.__importDefault(require("react-loadable-ssr-addon-v5-slorber"));
|
|
10
|
+
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
11
|
+
const copy_webpack_plugin_1 = (0, tslib_1.__importDefault)(require("copy-webpack-plugin"));
|
|
12
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
13
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
14
|
+
const react_loadable_ssr_addon_v5_slorber_1 = (0, tslib_1.__importDefault)(require("react-loadable-ssr-addon-v5-slorber"));
|
|
15
15
|
const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
|
|
16
|
-
const webpack_merge_1 = tslib_1.__importDefault(require("webpack-merge"));
|
|
17
|
-
const constants_1 = require("../constants");
|
|
16
|
+
const webpack_merge_1 = (0, tslib_1.__importDefault)(require("webpack-merge"));
|
|
18
17
|
const server_1 = require("../server");
|
|
19
18
|
const brokenLinks_1 = require("../server/brokenLinks");
|
|
20
|
-
const client_1 = tslib_1.__importDefault(require("../webpack/client"));
|
|
21
|
-
const server_2 = tslib_1.__importDefault(require("../webpack/server"));
|
|
19
|
+
const client_1 = (0, tslib_1.__importDefault)(require("../webpack/client"));
|
|
20
|
+
const server_2 = (0, tslib_1.__importDefault)(require("../webpack/server"));
|
|
22
21
|
const utils_1 = require("../webpack/utils");
|
|
23
|
-
const CleanWebpackPlugin_1 = tslib_1.__importDefault(require("../webpack/plugins/CleanWebpackPlugin"));
|
|
22
|
+
const CleanWebpackPlugin_1 = (0, tslib_1.__importDefault)(require("../webpack/plugins/CleanWebpackPlugin"));
|
|
24
23
|
const i18n_1 = require("../server/i18n");
|
|
25
24
|
const utils_2 = require("@docusaurus/utils");
|
|
26
25
|
async function build(siteDir, cliOptions = {},
|
|
27
26
|
// TODO what's the purpose of this arg ?
|
|
28
27
|
forceTerminate = true) {
|
|
28
|
+
['SIGINT', 'SIGTERM'].forEach((sig) => {
|
|
29
|
+
process.on(sig, () => process.exit());
|
|
30
|
+
});
|
|
29
31
|
async function tryToBuildLocale({ locale, isLastLocale, }) {
|
|
30
32
|
try {
|
|
31
|
-
// console.log(chalk.green(`Site successfully built in locale=${locale}`));
|
|
32
33
|
return await buildLocale({
|
|
33
34
|
siteDir,
|
|
34
35
|
locale,
|
|
@@ -38,17 +39,17 @@ forceTerminate = true) {
|
|
|
38
39
|
});
|
|
39
40
|
}
|
|
40
41
|
catch (e) {
|
|
41
|
-
|
|
42
|
+
logger_1.default.error `Unable to build website for locale name=${locale}.`;
|
|
42
43
|
throw e;
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
|
-
const context = await server_1.loadContext(siteDir, {
|
|
46
|
+
const context = await (0, server_1.loadContext)(siteDir, {
|
|
46
47
|
customOutDir: cliOptions.outDir,
|
|
47
48
|
customConfigFilePath: cliOptions.config,
|
|
48
49
|
locale: cliOptions.locale,
|
|
49
50
|
localizePath: cliOptions.locale ? false : undefined,
|
|
50
51
|
});
|
|
51
|
-
const i18n = await i18n_1.loadI18n(context.siteConfig, {
|
|
52
|
+
const i18n = await (0, i18n_1.loadI18n)(context.siteConfig, {
|
|
52
53
|
locale: cliOptions.locale,
|
|
53
54
|
});
|
|
54
55
|
if (cliOptions.locale) {
|
|
@@ -56,8 +57,7 @@ forceTerminate = true) {
|
|
|
56
57
|
}
|
|
57
58
|
else {
|
|
58
59
|
if (i18n.locales.length > 1) {
|
|
59
|
-
|
|
60
|
-
- ${i18n.locales.join('\n- ')}`));
|
|
60
|
+
logger_1.default.info `Website will be built for all these locales: ${i18n.locales}`;
|
|
61
61
|
}
|
|
62
62
|
// We need the default locale to always be the 1st in the list
|
|
63
63
|
// If we build it last, it would "erase" the localized sites built in subfolders
|
|
@@ -65,7 +65,7 @@ forceTerminate = true) {
|
|
|
65
65
|
i18n.defaultLocale,
|
|
66
66
|
...i18n.locales.filter((locale) => locale !== i18n.defaultLocale),
|
|
67
67
|
];
|
|
68
|
-
const results = await utils_2.mapAsyncSequencial(orderedLocales, (locale) => {
|
|
68
|
+
const results = await (0, utils_2.mapAsyncSequencial)(orderedLocales, (locale) => {
|
|
69
69
|
const isLastLocale = orderedLocales.indexOf(locale) === orderedLocales.length - 1;
|
|
70
70
|
return tryToBuildLocale({ locale, isLastLocale });
|
|
71
71
|
});
|
|
@@ -76,17 +76,17 @@ exports.default = build;
|
|
|
76
76
|
async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLastLocale, }) {
|
|
77
77
|
process.env.BABEL_ENV = 'production';
|
|
78
78
|
process.env.NODE_ENV = 'production';
|
|
79
|
-
|
|
80
|
-
const props = await server_1.load(siteDir, {
|
|
79
|
+
logger_1.default.info `name=${`[${locale}]`} Creating an optimized production build...`;
|
|
80
|
+
const props = await (0, server_1.load)(siteDir, {
|
|
81
81
|
customOutDir: cliOptions.outDir,
|
|
82
82
|
customConfigFilePath: cliOptions.config,
|
|
83
83
|
locale,
|
|
84
84
|
localizePath: cliOptions.locale ? false : undefined,
|
|
85
85
|
});
|
|
86
86
|
// Apply user webpack config.
|
|
87
|
-
const { outDir, generatedFilesDir, plugins, siteConfig: { baseUrl, onBrokenLinks }, routes, } = props;
|
|
87
|
+
const { outDir, generatedFilesDir, plugins, siteConfig: { baseUrl, onBrokenLinks, staticDirectories }, routes, } = props;
|
|
88
88
|
const clientManifestPath = path_1.default.join(generatedFilesDir, 'client-manifest.json');
|
|
89
|
-
let clientConfig = webpack_merge_1.default(client_1.default(props, cliOptions.minify), {
|
|
89
|
+
let clientConfig = (0, webpack_merge_1.default)((0, client_1.default)(props, cliOptions.minify), {
|
|
90
90
|
plugins: [
|
|
91
91
|
// Remove/clean build folders before building bundles.
|
|
92
92
|
new CleanWebpackPlugin_1.default({ verbose: false }),
|
|
@@ -99,38 +99,33 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
|
|
|
99
99
|
].filter(Boolean),
|
|
100
100
|
});
|
|
101
101
|
const allCollectedLinks = {};
|
|
102
|
-
let serverConfig = server_2.default({
|
|
102
|
+
let serverConfig = (0, server_2.default)({
|
|
103
103
|
props,
|
|
104
104
|
onLinksCollected: (staticPagePath, links) => {
|
|
105
105
|
allCollectedLinks[staticPagePath] = links;
|
|
106
106
|
},
|
|
107
107
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
],
|
|
119
|
-
}),
|
|
120
|
-
],
|
|
121
|
-
});
|
|
122
|
-
}
|
|
108
|
+
serverConfig = (0, webpack_merge_1.default)(serverConfig, {
|
|
109
|
+
plugins: [
|
|
110
|
+
new copy_webpack_plugin_1.default({
|
|
111
|
+
patterns: staticDirectories
|
|
112
|
+
.map((dir) => path_1.default.resolve(siteDir, dir))
|
|
113
|
+
.filter(fs_extra_1.default.existsSync)
|
|
114
|
+
.map((dir) => ({ from: dir, to: outDir })),
|
|
115
|
+
}),
|
|
116
|
+
],
|
|
117
|
+
});
|
|
123
118
|
// Plugin Lifecycle - configureWebpack and configurePostCss.
|
|
124
119
|
plugins.forEach((plugin) => {
|
|
125
120
|
var _a, _b;
|
|
126
121
|
const { configureWebpack, configurePostCss } = plugin;
|
|
127
122
|
if (configurePostCss) {
|
|
128
|
-
clientConfig = utils_1.applyConfigurePostCss(configurePostCss, clientConfig);
|
|
123
|
+
clientConfig = (0, utils_1.applyConfigurePostCss)(configurePostCss, clientConfig);
|
|
129
124
|
}
|
|
130
125
|
if (configureWebpack) {
|
|
131
|
-
clientConfig = utils_1.applyConfigureWebpack(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`. // TODO remove this implicit api: inject in callback instead
|
|
126
|
+
clientConfig = (0, utils_1.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`. // TODO remove this implicit api: inject in callback instead
|
|
132
127
|
clientConfig, false, (_a = props.siteConfig.webpack) === null || _a === void 0 ? void 0 : _a.jsLoader, plugin.content);
|
|
133
|
-
serverConfig = utils_1.applyConfigureWebpack(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`. // TODO remove this implicit api: inject in callback instead
|
|
128
|
+
serverConfig = (0, utils_1.applyConfigureWebpack)(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`. // TODO remove this implicit api: inject in callback instead
|
|
134
129
|
serverConfig, true, (_b = props.siteConfig.webpack) === null || _b === void 0 ? void 0 : _b.jsLoader, plugin.content);
|
|
135
130
|
}
|
|
136
131
|
});
|
|
@@ -140,7 +135,7 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
|
|
|
140
135
|
await fs_extra_1.default.unlink(clientManifestPath);
|
|
141
136
|
}
|
|
142
137
|
// Run webpack to build JS bundle (client) and static html files (server).
|
|
143
|
-
await utils_1.compile([clientConfig, serverConfig]);
|
|
138
|
+
await (0, utils_1.compile)([clientConfig, serverConfig]);
|
|
144
139
|
// Remove server.bundle.js because it is not needed.
|
|
145
140
|
if (serverConfig.output &&
|
|
146
141
|
serverConfig.output.filename &&
|
|
@@ -157,16 +152,16 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
|
|
|
157
152
|
}
|
|
158
153
|
await plugin.postBuild(props);
|
|
159
154
|
}));
|
|
160
|
-
await brokenLinks_1.handleBrokenLinks({
|
|
155
|
+
await (0, brokenLinks_1.handleBrokenLinks)({
|
|
161
156
|
allCollectedLinks,
|
|
162
157
|
routes,
|
|
163
158
|
onBrokenLinks,
|
|
164
159
|
outDir,
|
|
165
160
|
baseUrl,
|
|
166
161
|
});
|
|
167
|
-
|
|
162
|
+
logger_1.default.success `Generated static files in path=${path_1.default.relative(process.cwd(), outDir)}.`;
|
|
168
163
|
if (isLastLocale) {
|
|
169
|
-
|
|
164
|
+
logger_1.default.info `Use code=${'npm run serve'} command to test your build locally.`;
|
|
170
165
|
}
|
|
171
166
|
if (forceTerminate && isLastLocale && !cliOptions.bundleAnalyzer) {
|
|
172
167
|
process.exit(0);
|
package/lib/commands/clear.d.ts
CHANGED
package/lib/commands/clear.js
CHANGED
|
@@ -1,31 +1,30 @@
|
|
|
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
|
*/
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
11
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
12
|
+
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
13
|
+
const utils_1 = require("@docusaurus/utils");
|
|
14
|
+
async function removePath(fsPath) {
|
|
15
|
+
try {
|
|
16
|
+
fs_extra_1.default.remove(path_1.default.join(fsPath));
|
|
17
|
+
logger_1.default.success `Removed the path=${fsPath} directory.`;
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
logger_1.default.error `Could not remove path=${fsPath} directory.
|
|
21
|
+
${e}`;
|
|
22
|
+
}
|
|
24
23
|
}
|
|
25
24
|
async function clear(siteDir) {
|
|
26
25
|
return Promise.all([
|
|
27
|
-
removePath(path_1.default.join(siteDir,
|
|
28
|
-
removePath(path_1.default.join(siteDir,
|
|
26
|
+
removePath(path_1.default.join(siteDir, utils_1.GENERATED_FILES_DIR_NAME)),
|
|
27
|
+
removePath(path_1.default.join(siteDir, utils_1.DEFAULT_BUILD_DIR_NAME)),
|
|
29
28
|
removePath(path_1.default.join(siteDir, 'node_modules', '.cache')),
|
|
30
29
|
]);
|
|
31
30
|
}
|
|
@@ -1,3 +1,9 @@
|
|
|
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
|
+
*/
|
|
1
7
|
import { HostPortCLIOptions } from '@docusaurus/types';
|
|
2
8
|
export declare function getCLIOptionHost(hostOption: HostPortCLIOptions['host']): string;
|
|
3
9
|
export declare function getCLIOptionPort(portOption: HostPortCLIOptions['port'], host: string): Promise<number | null>;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCLIOptionPort = exports.getCLIOptionHost = 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
|
-
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.getCLIOptionPort = exports.getCLIOptionHost = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const choosePort_1 = (0, tslib_1.__importDefault)(require("../choosePort"));
|
|
12
|
+
const utils_1 = require("@docusaurus/utils");
|
|
13
13
|
function getCLIOptionHost(hostOption) {
|
|
14
14
|
return hostOption || 'localhost';
|
|
15
15
|
}
|
|
16
16
|
exports.getCLIOptionHost = getCLIOptionHost;
|
|
17
17
|
async function getCLIOptionPort(portOption, host) {
|
|
18
|
-
const basePort = portOption ? parseInt(portOption, 10) :
|
|
19
|
-
return choosePort_1.default(host, basePort);
|
|
18
|
+
const basePort = portOption ? parseInt(portOption, 10) : utils_1.DEFAULT_PORT;
|
|
19
|
+
return (0, choosePort_1.default)(host, basePort);
|
|
20
20
|
}
|
|
21
21
|
exports.getCLIOptionPort = getCLIOptionPort;
|
package/lib/commands/deploy.d.ts
CHANGED
|
@@ -5,4 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import { BuildCLIOptions } from '@docusaurus/types';
|
|
8
|
+
export declare function buildSshUrl(githubHost: string, organizationName: string, projectName: string, githubPort?: string): string;
|
|
9
|
+
export declare function buildHttpsUrl(gitCredentials: string, githubHost: string, organizationName: string, projectName: string, githubPort?: string): string;
|
|
10
|
+
export declare function hasSSHProtocol(sourceRepoUrl: string): boolean;
|
|
8
11
|
export default function deploy(siteDir: string, cliOptions?: Partial<BuildCLIOptions>): Promise<void>;
|
package/lib/commands/deploy.js
CHANGED
|
@@ -6,15 +6,15 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.hasSSHProtocol = exports.buildHttpsUrl = exports.buildSshUrl = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
10
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
11
|
-
const shelljs_1 = tslib_1.__importDefault(require("shelljs"));
|
|
12
|
-
const
|
|
11
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
12
|
+
const shelljs_1 = (0, tslib_1.__importDefault)(require("shelljs"));
|
|
13
|
+
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
13
14
|
const server_1 = require("../server");
|
|
14
|
-
const build_1 = tslib_1.__importDefault(require("./build"));
|
|
15
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
16
|
-
const os_1 = tslib_1.__importDefault(require("os"));
|
|
17
|
-
const buildRemoteBranchUrl_1 = require("./buildRemoteBranchUrl");
|
|
15
|
+
const build_1 = (0, tslib_1.__importDefault)(require("./build"));
|
|
16
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
17
|
+
const os_1 = (0, tslib_1.__importDefault)(require("os"));
|
|
18
18
|
// GIT_PASS env variable should not appear in logs
|
|
19
19
|
function obfuscateGitPass(str) {
|
|
20
20
|
const gitPass = process.env.GIT_PASS;
|
|
@@ -25,80 +25,126 @@ function obfuscateGitPass(str) {
|
|
|
25
25
|
function shellExecLog(cmd) {
|
|
26
26
|
try {
|
|
27
27
|
const result = shelljs_1.default.exec(cmd);
|
|
28
|
-
|
|
28
|
+
logger_1.default.info `code=${obfuscateGitPass(cmd)} subdue=${`code: ${result.code}`}`;
|
|
29
29
|
return result;
|
|
30
30
|
}
|
|
31
31
|
catch (e) {
|
|
32
|
-
|
|
32
|
+
logger_1.default.error `code=${obfuscateGitPass(cmd)}`;
|
|
33
33
|
throw e;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
+
function buildSshUrl(githubHost, organizationName, projectName, githubPort) {
|
|
37
|
+
if (githubPort) {
|
|
38
|
+
return `ssh://git@${githubHost}:${githubPort}/${organizationName}/${projectName}.git`;
|
|
39
|
+
}
|
|
40
|
+
return `git@${githubHost}:${organizationName}/${projectName}.git`;
|
|
41
|
+
}
|
|
42
|
+
exports.buildSshUrl = buildSshUrl;
|
|
43
|
+
function buildHttpsUrl(gitCredentials, githubHost, organizationName, projectName, githubPort) {
|
|
44
|
+
if (githubPort) {
|
|
45
|
+
return `https://${gitCredentials}@${githubHost}:${githubPort}/${organizationName}/${projectName}.git`;
|
|
46
|
+
}
|
|
47
|
+
return `https://${gitCredentials}@${githubHost}/${organizationName}/${projectName}.git`;
|
|
48
|
+
}
|
|
49
|
+
exports.buildHttpsUrl = buildHttpsUrl;
|
|
50
|
+
function hasSSHProtocol(sourceRepoUrl) {
|
|
51
|
+
try {
|
|
52
|
+
if (new URL(sourceRepoUrl).protocol === 'ssh:') {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// Fails when there isn't a protocol
|
|
59
|
+
return /^([\w-]+@)?[\w.-]+:[\w./_-]+(\.git)?/.test(sourceRepoUrl); // git@github.com:facebook/docusaurus.git
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.hasSSHProtocol = hasSSHProtocol;
|
|
36
63
|
async function deploy(siteDir, cliOptions = {}) {
|
|
37
|
-
const { outDir, siteConfig, siteConfigPath } = await server_1.loadContext(siteDir, {
|
|
64
|
+
const { outDir, siteConfig, siteConfigPath } = await (0, server_1.loadContext)(siteDir, {
|
|
38
65
|
customConfigFilePath: cliOptions.config,
|
|
39
66
|
customOutDir: cliOptions.outDir,
|
|
40
67
|
});
|
|
41
68
|
if (typeof siteConfig.trailingSlash === 'undefined') {
|
|
42
|
-
|
|
43
|
-
Docusaurus recommendation:
|
|
44
|
-
When deploying to GitHub Pages, it is better to use an explicit "trailingSlash" site config.
|
|
69
|
+
logger_1.default.warn(`When deploying to GitHub Pages, it is better to use an explicit "trailingSlash" site config.
|
|
45
70
|
Otherwise, GitHub Pages will add an extra trailing slash to your site urls only on direct-access (not when navigation) with a server redirect.
|
|
46
71
|
This behavior can have SEO impacts and create relative link issues.
|
|
47
|
-
`)
|
|
72
|
+
`);
|
|
48
73
|
}
|
|
49
|
-
|
|
74
|
+
logger_1.default.info('Deploy command invoked...');
|
|
50
75
|
if (!shelljs_1.default.which('git')) {
|
|
51
76
|
throw new Error('Git not installed or on the PATH!');
|
|
52
77
|
}
|
|
78
|
+
// Source repo is the repo from where the command is invoked
|
|
79
|
+
const sourceRepoUrl = shelljs_1.default
|
|
80
|
+
.exec('git config --get remote.origin.url', { silent: true })
|
|
81
|
+
.stdout.trim();
|
|
82
|
+
// The source branch; defaults to the currently checked out branch
|
|
83
|
+
const sourceBranch = process.env.CURRENT_BRANCH ||
|
|
84
|
+
shelljs_1.default.exec('git rev-parse --abbrev-ref HEAD', { silent: true }).stdout.trim();
|
|
53
85
|
const gitUser = process.env.GIT_USER;
|
|
54
|
-
|
|
55
|
-
|
|
86
|
+
let useSSH = process.env.USE_SSH !== undefined &&
|
|
87
|
+
process.env.USE_SSH.toLowerCase() === 'true';
|
|
88
|
+
if (!gitUser && !useSSH) {
|
|
89
|
+
// If USE_SSH is unspecified: try inferring from repo URL
|
|
90
|
+
if (process.env.USE_SSH === undefined && hasSSHProtocol(sourceRepoUrl)) {
|
|
91
|
+
useSSH = true;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
throw new Error('Please set the GIT_USER environment variable, or explicitly specify USE_SSH instead!');
|
|
95
|
+
}
|
|
56
96
|
}
|
|
57
|
-
// The branch that contains the latest docs changes that will be deployed.
|
|
58
|
-
const currentBranch = process.env.CURRENT_BRANCH ||
|
|
59
|
-
shelljs_1.default.exec('git rev-parse --abbrev-ref HEAD').stdout.trim();
|
|
60
97
|
const organizationName = process.env.ORGANIZATION_NAME ||
|
|
61
98
|
process.env.CIRCLE_PROJECT_USERNAME ||
|
|
62
99
|
siteConfig.organizationName;
|
|
63
100
|
if (!organizationName) {
|
|
64
101
|
throw new Error(`Missing project organization name. Did you forget to define "organizationName" in ${siteConfigPath}? You may also export it via the ORGANIZATION_NAME environment variable.`);
|
|
65
102
|
}
|
|
66
|
-
|
|
103
|
+
logger_1.default.info `organizationName: name=${organizationName}`;
|
|
67
104
|
const projectName = process.env.PROJECT_NAME ||
|
|
68
105
|
process.env.CIRCLE_PROJECT_REPONAME ||
|
|
69
106
|
siteConfig.projectName;
|
|
70
107
|
if (!projectName) {
|
|
71
108
|
throw new Error(`Missing project name. Did you forget to define "projectName" in ${siteConfigPath}? You may also export it via the PROJECT_NAME environment variable.`);
|
|
72
109
|
}
|
|
73
|
-
|
|
110
|
+
logger_1.default.info `projectName: name=${projectName}`;
|
|
74
111
|
// We never deploy on pull request.
|
|
75
112
|
const isPullRequest = process.env.CI_PULL_REQUEST || process.env.CIRCLE_PULL_REQUEST;
|
|
76
113
|
if (isPullRequest) {
|
|
77
114
|
shelljs_1.default.echo('Skipping deploy on a pull request.');
|
|
78
115
|
shelljs_1.default.exit(0);
|
|
79
116
|
}
|
|
80
|
-
// github.io indicates organization repos that deploy via
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
117
|
+
// github.io indicates organization repos that deploy via default branch. All others use gh-pages.
|
|
118
|
+
// Organization deploys looks like:
|
|
119
|
+
// - Git repo: https://github.com/<organization>/<organization>.github.io
|
|
120
|
+
// - Site url: https://<organization>.github.io
|
|
121
|
+
const isGitHubPagesOrganizationDeploy = projectName.includes('.github.io');
|
|
122
|
+
if (isGitHubPagesOrganizationDeploy &&
|
|
123
|
+
!process.env.DEPLOYMENT_BRANCH &&
|
|
124
|
+
!siteConfig.deploymentBranch) {
|
|
125
|
+
throw new Error(`For GitHub pages organization deployments, 'docusaurus deploy' does not assume anymore that 'master' is your default Git branch.
|
|
126
|
+
Please provide the branch name to deploy to as an environment variable, for example DEPLOYMENT_BRANCH=main or DEPLOYMENT_BRANCH=master .
|
|
127
|
+
You can also set the deploymentBranch property in docusaurus.config.js .`);
|
|
128
|
+
}
|
|
129
|
+
const deploymentBranch = process.env.DEPLOYMENT_BRANCH || siteConfig.deploymentBranch || 'gh-pages';
|
|
130
|
+
logger_1.default.info `deploymentBranch: name=${deploymentBranch}`;
|
|
84
131
|
const githubHost = process.env.GITHUB_HOST || siteConfig.githubHost || 'github.com';
|
|
85
132
|
const githubPort = process.env.GITHUB_PORT || siteConfig.githubPort;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
gitCredentials = `${gitCredentials}:${gitPass}`;
|
|
133
|
+
let deploymentRepoURL;
|
|
134
|
+
if (useSSH) {
|
|
135
|
+
deploymentRepoURL = buildSshUrl(githubHost, organizationName, projectName, githubPort);
|
|
90
136
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
137
|
+
else {
|
|
138
|
+
const gitPass = process.env.GIT_PASS;
|
|
139
|
+
const gitCredentials = gitPass ? `${gitUser}:${gitPass}` : gitUser;
|
|
140
|
+
deploymentRepoURL = buildHttpsUrl(gitCredentials, githubHost, organizationName, projectName, githubPort);
|
|
141
|
+
}
|
|
142
|
+
logger_1.default.info `Remote repo URL: name=${obfuscateGitPass(deploymentRepoURL)}`;
|
|
94
143
|
// Check if this is a cross-repo publish.
|
|
95
|
-
const
|
|
96
|
-
.exec('git config --get remote.origin.url')
|
|
97
|
-
.stdout.trim();
|
|
98
|
-
const crossRepoPublish = !currentRepoUrl.endsWith(`${organizationName}/${projectName}.git`);
|
|
144
|
+
const crossRepoPublish = !sourceRepoUrl.endsWith(`${organizationName}/${projectName}.git`);
|
|
99
145
|
// We don't allow deploying to the same branch unless it's a cross publish.
|
|
100
|
-
if (
|
|
101
|
-
throw new Error(`You cannot deploy from this branch (${
|
|
146
|
+
if (sourceBranch === deploymentBranch && !crossRepoPublish) {
|
|
147
|
+
throw new Error(`You cannot deploy from this branch (${sourceBranch}).` +
|
|
102
148
|
'\nYou will need to checkout to a different branch!');
|
|
103
149
|
}
|
|
104
150
|
// Save the commit hash that triggers publish-gh-pages before checking
|
|
@@ -107,42 +153,31 @@ This behavior can have SEO impacts and create relative link issues.
|
|
|
107
153
|
const runDeploy = async (outputDirectory) => {
|
|
108
154
|
const fromPath = outputDirectory;
|
|
109
155
|
const toPath = await fs_extra_1.default.mkdtemp(path_1.default.join(os_1.default.tmpdir(), `${projectName}-${deploymentBranch}`));
|
|
110
|
-
if (shellExecLog(`git clone ${remoteBranch} ${toPath}`).code !== 0) {
|
|
111
|
-
throw new Error(`Running "git clone" command in "${toPath}" failed.`);
|
|
112
|
-
}
|
|
113
156
|
shelljs_1.default.cd(toPath);
|
|
114
|
-
//
|
|
115
|
-
//
|
|
116
|
-
//
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
else if (shellExecLog(`git checkout -b ${deploymentBranch}`).code +
|
|
127
|
-
shellExecLog(`git branch --set-upstream-to=origin/${deploymentBranch}`).code !==
|
|
128
|
-
0) {
|
|
129
|
-
throw new Error(`Running "git checkout ${deploymentBranch}" command failed.`);
|
|
130
|
-
}
|
|
157
|
+
// Check out deployment branch when cloning repository, and then remove all
|
|
158
|
+
// the files in the directory. If the 'clone' command fails, assume that
|
|
159
|
+
// the deployment branch doesn't exist, and initialize git in an empty
|
|
160
|
+
// directory, check out a clean deployment branch and add remote.
|
|
161
|
+
if (shellExecLog(`git clone --depth 1 --branch ${deploymentBranch} ${deploymentRepoURL} ${toPath}`).code === 0) {
|
|
162
|
+
shellExecLog('git rm -rf .');
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
shellExecLog('git init');
|
|
166
|
+
shellExecLog(`git checkout -b ${deploymentBranch}`);
|
|
167
|
+
shellExecLog(`git remote add origin ${deploymentRepoURL}`);
|
|
131
168
|
}
|
|
132
|
-
shellExecLog('git rm -rf .');
|
|
133
169
|
try {
|
|
134
170
|
await fs_extra_1.default.copy(fromPath, toPath);
|
|
135
171
|
}
|
|
136
172
|
catch (error) {
|
|
137
173
|
throw new Error(`Copying build assets from "${fromPath}" to "${toPath}" failed with error "${error}".`);
|
|
138
174
|
}
|
|
139
|
-
shelljs_1.default.cd(toPath);
|
|
140
175
|
shellExecLog('git add --all');
|
|
141
176
|
const commitMessage = process.env.CUSTOM_COMMIT_MESSAGE ||
|
|
142
177
|
`Deploy website - based on ${currentCommit}`;
|
|
143
178
|
const commitResults = shellExecLog(`git commit -m "${commitMessage}"`);
|
|
144
179
|
if (shellExecLog(`git push --force origin ${deploymentBranch}`).code !== 0) {
|
|
145
|
-
throw new Error('Running "git push" command failed.');
|
|
180
|
+
throw new Error('Running "git push" command failed. Does the GitHub user account you are using have push access to the repository?');
|
|
146
181
|
}
|
|
147
182
|
else if (commitResults.code === 0) {
|
|
148
183
|
// The commit might return a non-zero value when site is up to date.
|
|
@@ -163,10 +198,10 @@ This behavior can have SEO impacts and create relative link issues.
|
|
|
163
198
|
if (!cliOptions.skipBuild) {
|
|
164
199
|
// Build static html files, then push to deploymentBranch branch of specified repo.
|
|
165
200
|
try {
|
|
166
|
-
await runDeploy(await build_1.default(siteDir, cliOptions, false));
|
|
201
|
+
await runDeploy(await (0, build_1.default)(siteDir, cliOptions, false));
|
|
167
202
|
}
|
|
168
203
|
catch (buildError) {
|
|
169
|
-
|
|
204
|
+
logger_1.default.error(buildError.message);
|
|
170
205
|
process.exit(1);
|
|
171
206
|
}
|
|
172
207
|
}
|
package/lib/commands/external.js
CHANGED
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
10
|
const server_1 = require("../server");
|
|
11
|
-
const init_1 = tslib_1.__importDefault(require("../server/plugins/init"));
|
|
11
|
+
const init_1 = (0, tslib_1.__importDefault)(require("../server/plugins/init"));
|
|
12
12
|
async function externalCommand(cli, siteDir) {
|
|
13
|
-
const context = await server_1.loadContext(siteDir);
|
|
14
|
-
const pluginConfigs = server_1.loadPluginConfigs(context);
|
|
15
|
-
const plugins = init_1.default({ pluginConfigs, context });
|
|
13
|
+
const context = await (0, server_1.loadContext)(siteDir);
|
|
14
|
+
const pluginConfigs = (0, server_1.loadPluginConfigs)(context);
|
|
15
|
+
const plugins = (0, init_1.default)({ pluginConfigs, context });
|
|
16
16
|
// Plugin Lifecycle - extendCli.
|
|
17
17
|
plugins.forEach((plugin) => {
|
|
18
18
|
const { extendCli } = plugin;
|
package/lib/commands/serve.js
CHANGED
|
@@ -7,34 +7,33 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const tslib_1 = require("tslib");
|
|
10
|
-
const http_1 = tslib_1.__importDefault(require("http"));
|
|
11
|
-
const serve_handler_1 = tslib_1.__importDefault(require("serve-handler"));
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
10
|
+
const http_1 = (0, tslib_1.__importDefault)(require("http"));
|
|
11
|
+
const serve_handler_1 = (0, tslib_1.__importDefault)(require("serve-handler"));
|
|
12
|
+
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
13
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
15
14
|
const server_1 = require("../server");
|
|
16
|
-
const build_1 = tslib_1.__importDefault(require("./build"));
|
|
15
|
+
const build_1 = (0, tslib_1.__importDefault)(require("./build"));
|
|
17
16
|
const commandUtils_1 = require("./commandUtils");
|
|
18
17
|
async function serve(siteDir, cliOptions) {
|
|
19
18
|
let dir = path_1.default.isAbsolute(cliOptions.dir)
|
|
20
19
|
? cliOptions.dir
|
|
21
20
|
: path_1.default.join(siteDir, cliOptions.dir);
|
|
22
21
|
if (cliOptions.build) {
|
|
23
|
-
dir = await build_1.default(siteDir, {
|
|
22
|
+
dir = await (0, build_1.default)(siteDir, {
|
|
24
23
|
config: cliOptions.config,
|
|
25
24
|
outDir: dir,
|
|
26
25
|
}, false);
|
|
27
26
|
}
|
|
28
|
-
const host = commandUtils_1.getCLIOptionHost(cliOptions.host);
|
|
29
|
-
const port = await commandUtils_1.getCLIOptionPort(cliOptions.port, host);
|
|
27
|
+
const host = (0, commandUtils_1.getCLIOptionHost)(cliOptions.host);
|
|
28
|
+
const port = await (0, commandUtils_1.getCLIOptionPort)(cliOptions.port, host);
|
|
30
29
|
if (port === null) {
|
|
31
30
|
process.exit();
|
|
32
31
|
}
|
|
33
|
-
const { siteConfig: { baseUrl, trailingSlash }, } = await server_1.loadSiteConfig({
|
|
32
|
+
const { siteConfig: { baseUrl, trailingSlash }, } = await (0, server_1.loadSiteConfig)({
|
|
34
33
|
siteDir,
|
|
35
34
|
customConfigFilePath: cliOptions.config,
|
|
36
35
|
});
|
|
37
|
-
const servingUrl = `http://${
|
|
36
|
+
const servingUrl = `http://${host}:${port}`;
|
|
38
37
|
const server = http_1.default.createServer((req, res) => {
|
|
39
38
|
var _a, _b;
|
|
40
39
|
// Automatically redirect requests to /baseUrl/
|
|
@@ -48,18 +47,13 @@ async function serve(siteDir, cliOptions) {
|
|
|
48
47
|
// Remove baseUrl before calling serveHandler
|
|
49
48
|
// Reason: /baseUrl/ should serve /build/index.html, not /build/baseUrl/index.html (does not exist)
|
|
50
49
|
req.url = (_b = req.url) === null || _b === void 0 ? void 0 : _b.replace(baseUrl, '/');
|
|
51
|
-
serve_handler_1.default(req, res, {
|
|
50
|
+
(0, serve_handler_1.default)(req, res, {
|
|
52
51
|
cleanUrls: true,
|
|
53
52
|
public: dir,
|
|
54
53
|
trailingSlash,
|
|
55
54
|
});
|
|
56
55
|
});
|
|
57
|
-
|
|
58
|
-
borderColor: 'green',
|
|
59
|
-
padding: 1,
|
|
60
|
-
margin: 1,
|
|
61
|
-
align: 'center',
|
|
62
|
-
}));
|
|
56
|
+
logger_1.default.success `Serving path=${cliOptions.dir} directory at path=${servingUrl + baseUrl}.`;
|
|
63
57
|
server.listen(port);
|
|
64
58
|
}
|
|
65
59
|
exports.default = serve;
|