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