@docusaurus/core 2.0.0-beta.fbdeefcac → 2.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/bin/beforeCli.mjs +140 -0
- package/bin/{docusaurus.js → docusaurus.mjs} +79 -118
- package/lib/babel/preset.d.ts +8 -3
- package/lib/babel/preset.js +10 -8
- package/lib/client/App.d.ts +2 -3
- package/lib/client/App.js +31 -28
- package/lib/client/BaseUrlIssueBanner/index.d.ts +27 -0
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.js → BaseUrlIssueBanner/index.js} +25 -14
- package/lib/client/{baseUrlIssueBanner → BaseUrlIssueBanner}/styles.module.css +0 -0
- package/lib/client/ClientLifecyclesDispatcher.d.ts +16 -0
- package/lib/client/ClientLifecyclesDispatcher.js +39 -0
- package/lib/client/LinksCollector.d.ts +3 -3
- package/lib/client/LinksCollector.js +8 -13
- package/lib/client/PendingNavigation.d.ts +17 -3
- package/lib/client/PendingNavigation.js +47 -72
- package/lib/client/{baseUrlIssueBanner/BaseUrlIssueBanner.d.ts → SiteMetadataDefaults.d.ts} +1 -2
- package/lib/client/SiteMetadataDefaults.js +21 -0
- package/lib/{choosePort.d.ts → client/browserContext.d.ts} +5 -5
- package/lib/client/browserContext.js +22 -0
- package/lib/client/clientEntry.js +14 -9
- package/lib/client/docusaurus.d.ts +12 -6
- package/lib/client/docusaurus.js +30 -43
- package/lib/client/docusaurusContext.d.ts +12 -0
- package/lib/client/docusaurusContext.js +25 -0
- package/lib/client/exports/BrowserOnly.d.ts +3 -5
- package/lib/client/exports/BrowserOnly.js +14 -8
- package/lib/client/exports/ComponentCreator.d.ts +6 -2
- package/lib/client/exports/ComponentCreator.js +75 -42
- package/lib/client/exports/ErrorBoundary.d.ts +18 -0
- package/lib/client/exports/ErrorBoundary.js +37 -0
- package/lib/client/exports/ExecutionEnvironment.js +7 -8
- package/lib/client/exports/Head.d.ts +2 -3
- package/lib/client/exports/Head.js +3 -4
- package/lib/client/exports/Interpolate.d.ts +2 -2
- package/lib/client/exports/Interpolate.js +20 -49
- package/lib/client/exports/Link.d.ts +4 -10
- package/lib/client/exports/Link.js +38 -38
- package/lib/client/exports/Translate.d.ts +1 -1
- package/lib/client/exports/Translate.js +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 +11 -14
- package/lib/client/exports/useDocusaurusContext.d.ts +2 -3
- package/lib/client/exports/useDocusaurusContext.js +3 -9
- package/lib/client/exports/useGlobalData.d.ts +4 -3
- package/lib/client/exports/useGlobalData.js +6 -13
- package/lib/{server/versions/__tests/index.test.d.ts → client/exports/useIsBrowser.d.ts} +1 -1
- package/lib/client/exports/useIsBrowser.js +11 -0
- package/lib/client/exports/useRouteContext.d.ts +8 -0
- package/lib/client/exports/useRouteContext.js +15 -0
- package/lib/client/flat.d.ts +12 -2
- package/lib/client/flat.js +19 -15
- package/lib/client/normalizeLocation.d.ts +2 -5
- package/lib/client/normalizeLocation.js +14 -10
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +12 -32
- package/lib/client/preload.d.ts +3 -4
- package/lib/client/preload.js +5 -12
- package/lib/client/routeContext.d.ts +13 -0
- package/lib/client/routeContext.js +31 -0
- package/lib/client/serverEntry.d.ts +10 -0
- package/lib/client/serverEntry.js +108 -146
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +45 -0
- package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
- package/lib/client/theme-fallback/Layout/index.js +2 -26
- package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
- package/lib/client/theme-fallback/Loading/index.js +50 -116
- package/lib/{server/html-tags/htmlTags.d.ts → client/theme-fallback/NotFound/index.d.ts} +2 -1
- package/lib/client/theme-fallback/NotFound/index.js +19 -18
- package/lib/client/theme-fallback/Root/index.d.ts +10 -0
- package/lib/client/theme-fallback/Root/index.js +2 -6
- package/lib/client/{exports/context.js → theme-fallback/SiteMetadata/index.d.ts} +2 -2
- package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
- package/lib/commands/build.d.ts +6 -2
- package/lib/commands/build.js +81 -64
- package/lib/commands/clear.d.ts +7 -1
- package/lib/commands/clear.js +34 -21
- package/lib/commands/deploy.d.ts +5 -2
- package/lib/commands/deploy.js +94 -81
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +9 -11
- package/lib/commands/serve.d.ts +8 -2
- package/lib/commands/serve.js +29 -28
- package/lib/commands/start.d.ts +9 -2
- package/lib/commands/start.js +109 -101
- package/lib/commands/swizzle/actions.d.ts +23 -0
- package/lib/commands/swizzle/actions.js +106 -0
- package/lib/commands/swizzle/common.d.ts +33 -0
- package/lib/commands/swizzle/common.js +56 -0
- package/lib/commands/swizzle/components.d.ts +29 -0
- package/lib/commands/swizzle/components.js +200 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +84 -0
- package/lib/{server/client-modules/index.d.ts → commands/swizzle/context.d.ts} +2 -2
- package/lib/commands/swizzle/context.js +24 -0
- package/lib/commands/swizzle/index.d.ts +8 -0
- package/lib/commands/swizzle/index.js +119 -0
- package/lib/commands/swizzle/prompts.d.ts +12 -0
- package/lib/commands/swizzle/prompts.js +110 -0
- package/lib/{client/exports/context.d.ts → commands/swizzle/tables.d.ts} +3 -4
- package/lib/commands/swizzle/tables.js +113 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +106 -0
- package/lib/commands/writeHeadingIds.d.ts +2 -6
- package/lib/commands/writeHeadingIds.js +22 -81
- package/lib/commands/writeTranslations.d.ts +4 -5
- package/lib/commands/writeTranslations.js +46 -25
- package/lib/index.d.ts +9 -9
- package/lib/index.js +14 -14
- package/lib/server/brokenLinks.d.ts +4 -17
- package/lib/server/brokenLinks.js +67 -56
- package/lib/server/clientModules.d.ts +12 -0
- package/lib/server/clientModules.js +20 -0
- package/lib/server/config.d.ts +5 -2
- package/lib/server/config.js +29 -6
- package/lib/server/configValidation.d.ts +4 -4
- package/lib/server/configValidation.js +86 -41
- package/lib/server/getHostPort.d.ts +14 -0
- package/lib/server/getHostPort.js +79 -0
- package/lib/server/htmlTags.d.ts +12 -0
- package/lib/server/htmlTags.js +62 -0
- package/lib/server/i18n.d.ts +3 -13
- package/lib/server/i18n.js +21 -55
- package/lib/server/index.d.ts +28 -13
- package/lib/server/index.js +83 -165
- package/lib/server/plugins/configs.d.ts +51 -0
- package/lib/server/plugins/configs.js +101 -0
- package/lib/server/plugins/index.d.ts +9 -8
- package/lib/server/plugins/index.js +73 -137
- package/lib/server/plugins/init.d.ts +6 -5
- package/lib/server/plugins/init.js +44 -109
- package/lib/server/plugins/moduleShorthand.d.ts +9 -0
- package/lib/server/plugins/moduleShorthand.js +46 -0
- package/lib/server/plugins/pluginIds.d.ts +5 -1
- package/lib/server/plugins/pluginIds.js +12 -7
- package/lib/server/plugins/presets.d.ts +12 -0
- package/lib/server/plugins/presets.js +49 -0
- package/lib/server/plugins/routeConfig.d.ts +11 -0
- package/lib/server/plugins/routeConfig.js +54 -0
- package/lib/server/plugins/synthetic.d.ts +20 -0
- package/lib/server/plugins/synthetic.js +111 -0
- package/lib/server/routes.d.ts +39 -7
- package/lib/server/routes.js +182 -95
- package/lib/server/siteMetadata.d.ts +12 -0
- package/lib/server/siteMetadata.js +81 -0
- package/lib/server/translations/translations.d.ts +14 -19
- package/lib/server/translations/translations.js +40 -72
- package/lib/server/translations/translationsExtractor.d.ts +10 -4
- package/lib/server/translations/translationsExtractor.js +158 -122
- package/lib/server/utils.d.ts +9 -3
- package/lib/server/utils.js +7 -9
- package/lib/webpack/aliases/index.d.ts +34 -0
- package/lib/webpack/aliases/index.js +106 -0
- package/lib/webpack/base.d.ts +3 -4
- package/lib/webpack/base.js +45 -57
- package/lib/webpack/client.d.ts +3 -3
- package/lib/webpack/client.js +12 -19
- package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +13 -3
- package/lib/webpack/plugins/ChunkAssetPlugin.js +24 -17
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +6 -25
- package/lib/webpack/plugins/CleanWebpackPlugin.js +33 -17
- package/lib/webpack/plugins/LogPlugin.d.ts +1 -1
- package/lib/webpack/plugins/LogPlugin.js +4 -5
- package/lib/webpack/plugins/WaitPlugin.d.ts +3 -3
- package/lib/webpack/plugins/WaitPlugin.js +1 -1
- package/lib/webpack/server.d.ts +5 -5
- package/lib/webpack/server.js +21 -12
- package/lib/{client → webpack}/templates/index.html.template.ejs +0 -0
- package/lib/webpack/templates/ssr.html.template.d.ts +8 -0
- package/lib/{client → webpack}/templates/ssr.html.template.js +3 -2
- package/lib/webpack/utils.d.ts +15 -31
- package/lib/webpack/utils.js +61 -182
- package/package.json +81 -77
- package/bin/beforeCli.js +0 -100
- package/lib/.tsbuildinfo +0 -1
- package/lib/choosePort.js +0 -105
- package/lib/client/.eslintrc.js +0 -29
- package/lib/client/.tsbuildinfo +0 -1
- package/lib/client/client-lifecycles-dispatcher.d.ts +0 -12
- package/lib/client/client-lifecycles-dispatcher.js +0 -27
- package/lib/client/nprogress.css +0 -36
- package/lib/commands/buildRemoteBranchUrl.d.ts +0 -7
- package/lib/commands/buildRemoteBranchUrl.js +0 -27
- package/lib/commands/commandUtils.d.ts +0 -3
- package/lib/commands/commandUtils.js +0 -21
- package/lib/commands/swizzle.d.ts +0 -9
- package/lib/commands/swizzle.js +0 -245
- package/lib/constants.d.ts +0 -18
- package/lib/constants.js +0 -23
- package/lib/server/client-modules/index.js +0 -14
- package/lib/server/duplicateRoutes.d.ts +0 -10
- package/lib/server/duplicateRoutes.js +0 -38
- package/lib/server/html-tags/htmlTags.js +0 -40
- package/lib/server/html-tags/index.d.ts +0 -9
- package/lib/server/html-tags/index.js +0 -43
- package/lib/server/loadSetup.d.ts +0 -9
- package/lib/server/loadSetup.js +0 -25
- package/lib/server/plugins/applyRouteTrailingSlash.d.ts +0 -9
- package/lib/server/plugins/applyRouteTrailingSlash.js +0 -19
- package/lib/server/presets/index.d.ts +0 -11
- package/lib/server/presets/index.js +0 -48
- package/lib/server/themes/alias.d.ts +0 -8
- package/lib/server/themes/alias.js +0 -40
- package/lib/server/themes/index.d.ts +0 -12
- package/lib/server/themes/index.js +0 -47
- package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
- package/lib/server/versions/__fixtures__/package.json +0 -3
- package/lib/server/versions/__tests/index.test.js +0 -25
- package/lib/server/versions/index.d.ts +0 -10
- package/lib/server/versions/index.js +0 -50
- package/lib/webpack/react-dev-utils-webpack5/README.md +0 -11
- package/lib/webpack/react-dev-utils-webpack5/evalSourceMapMiddleware.js +0 -57
- package/lib/webpack/react-dev-utils-webpack5/formatWebpackMessages.js +0 -138
- package/lib/webpack/react-dev-utils-webpack5/webpackHotDevClient.js +0 -285
- package/lib/webpack/sharedModuleAliases.d.ts +0 -10
- package/lib/webpack/sharedModuleAliases.js +0 -18
- package/tsconfig.client.json +0 -13
- package/tsconfig.json +0 -13
package/lib/commands/deploy.js
CHANGED
|
@@ -6,15 +6,16 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.deploy = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
10
11
|
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"));
|
|
13
|
-
const server_1 = require("../server");
|
|
14
|
-
const build_1 = tslib_1.__importDefault(require("./build"));
|
|
15
12
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
16
13
|
const os_1 = tslib_1.__importDefault(require("os"));
|
|
17
|
-
const
|
|
14
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
15
|
+
const shelljs_1 = tslib_1.__importDefault(require("shelljs"));
|
|
16
|
+
const utils_1 = require("@docusaurus/utils");
|
|
17
|
+
const server_1 = require("../server");
|
|
18
|
+
const build_1 = require("./build");
|
|
18
19
|
// GIT_PASS env variable should not appear in logs
|
|
19
20
|
function obfuscateGitPass(str) {
|
|
20
21
|
const gitPass = process.env.GIT_PASS;
|
|
@@ -25,80 +26,102 @@ function obfuscateGitPass(str) {
|
|
|
25
26
|
function shellExecLog(cmd) {
|
|
26
27
|
try {
|
|
27
28
|
const result = shelljs_1.default.exec(cmd);
|
|
28
|
-
|
|
29
|
+
logger_1.default.info `code=${obfuscateGitPass(cmd)} subdue=${`code: ${result.code}`}`;
|
|
29
30
|
return result;
|
|
30
31
|
}
|
|
31
|
-
catch (
|
|
32
|
-
|
|
33
|
-
throw
|
|
32
|
+
catch (err) {
|
|
33
|
+
logger_1.default.error `code=${obfuscateGitPass(cmd)}`;
|
|
34
|
+
throw err;
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
|
-
async function deploy(
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
async function deploy(siteDirParam = '.', cliOptions = {}) {
|
|
38
|
+
const siteDir = await fs_extra_1.default.realpath(siteDirParam);
|
|
39
|
+
const { outDir, siteConfig, siteConfigPath } = await (0, server_1.loadContext)({
|
|
40
|
+
siteDir,
|
|
41
|
+
config: cliOptions.config,
|
|
42
|
+
outDir: cliOptions.outDir,
|
|
40
43
|
});
|
|
41
44
|
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.
|
|
45
|
+
logger_1.default.warn(`When deploying to GitHub Pages, it is better to use an explicit "trailingSlash" site config.
|
|
45
46
|
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
47
|
This behavior can have SEO impacts and create relative link issues.
|
|
47
|
-
`)
|
|
48
|
+
`);
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
+
logger_1.default.info('Deploy command invoked...');
|
|
50
51
|
if (!shelljs_1.default.which('git')) {
|
|
51
52
|
throw new Error('Git not installed or on the PATH!');
|
|
52
53
|
}
|
|
54
|
+
// Source repo is the repo from where the command is invoked
|
|
55
|
+
const sourceRepoUrl = shelljs_1.default
|
|
56
|
+
.exec('git config --get remote.origin.url', { silent: true })
|
|
57
|
+
.stdout.trim();
|
|
58
|
+
// The source branch; defaults to the currently checked out branch
|
|
59
|
+
const sourceBranch = process.env.CURRENT_BRANCH ??
|
|
60
|
+
shelljs_1.default.exec('git rev-parse --abbrev-ref HEAD', { silent: true }).stdout.trim();
|
|
53
61
|
const gitUser = process.env.GIT_USER;
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
let useSSH = process.env.USE_SSH !== undefined &&
|
|
63
|
+
process.env.USE_SSH.toLowerCase() === 'true';
|
|
64
|
+
if (!gitUser && !useSSH) {
|
|
65
|
+
// If USE_SSH is unspecified: try inferring from repo URL
|
|
66
|
+
if (process.env.USE_SSH === undefined && (0, utils_1.hasSSHProtocol)(sourceRepoUrl)) {
|
|
67
|
+
useSSH = true;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
throw new Error('Please set the GIT_USER environment variable, or explicitly specify USE_SSH instead!');
|
|
71
|
+
}
|
|
56
72
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
shelljs_1.default.exec('git rev-parse --abbrev-ref HEAD').stdout.trim();
|
|
60
|
-
const organizationName = process.env.ORGANIZATION_NAME ||
|
|
61
|
-
process.env.CIRCLE_PROJECT_USERNAME ||
|
|
73
|
+
const organizationName = process.env.ORGANIZATION_NAME ??
|
|
74
|
+
process.env.CIRCLE_PROJECT_USERNAME ??
|
|
62
75
|
siteConfig.organizationName;
|
|
63
76
|
if (!organizationName) {
|
|
64
77
|
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
78
|
}
|
|
66
|
-
|
|
67
|
-
const projectName = process.env.PROJECT_NAME
|
|
68
|
-
process.env.CIRCLE_PROJECT_REPONAME
|
|
79
|
+
logger_1.default.info `organizationName: name=${organizationName}`;
|
|
80
|
+
const projectName = process.env.PROJECT_NAME ??
|
|
81
|
+
process.env.CIRCLE_PROJECT_REPONAME ??
|
|
69
82
|
siteConfig.projectName;
|
|
70
83
|
if (!projectName) {
|
|
71
84
|
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
85
|
}
|
|
73
|
-
|
|
86
|
+
logger_1.default.info `projectName: name=${projectName}`;
|
|
74
87
|
// We never deploy on pull request.
|
|
75
|
-
const isPullRequest = process.env.CI_PULL_REQUEST
|
|
88
|
+
const isPullRequest = process.env.CI_PULL_REQUEST ?? process.env.CIRCLE_PULL_REQUEST;
|
|
76
89
|
if (isPullRequest) {
|
|
77
90
|
shelljs_1.default.echo('Skipping deploy on a pull request.');
|
|
78
91
|
shelljs_1.default.exit(0);
|
|
79
92
|
}
|
|
80
|
-
// github.io indicates organization repos that deploy via
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
93
|
+
// github.io indicates organization repos that deploy via default branch. All
|
|
94
|
+
// others use gh-pages (either case can be configured actually, but we can
|
|
95
|
+
// make educated guesses). Organization deploys look like:
|
|
96
|
+
// - Git repo: https://github.com/<organization>/<organization>.github.io
|
|
97
|
+
// - Site url: https://<organization>.github.io
|
|
98
|
+
const isGitHubPagesOrganizationDeploy = projectName.includes('.github.io');
|
|
99
|
+
if (isGitHubPagesOrganizationDeploy &&
|
|
100
|
+
!process.env.DEPLOYMENT_BRANCH &&
|
|
101
|
+
!siteConfig.deploymentBranch) {
|
|
102
|
+
throw new Error(`For GitHub pages organization deployments, 'docusaurus deploy' does not assume anymore that 'master' is your default Git branch.
|
|
103
|
+
Please provide the branch name to deploy to as an environment variable, for example DEPLOYMENT_BRANCH=main or DEPLOYMENT_BRANCH=master .
|
|
104
|
+
You can also set the deploymentBranch property in docusaurus.config.js .`);
|
|
105
|
+
}
|
|
106
|
+
const deploymentBranch = process.env.DEPLOYMENT_BRANCH ?? siteConfig.deploymentBranch ?? 'gh-pages';
|
|
107
|
+
logger_1.default.info `deploymentBranch: name=${deploymentBranch}`;
|
|
108
|
+
const githubHost = process.env.GITHUB_HOST ?? siteConfig.githubHost ?? 'github.com';
|
|
109
|
+
const githubPort = process.env.GITHUB_PORT ?? siteConfig.githubPort;
|
|
110
|
+
let deploymentRepoURL;
|
|
111
|
+
if (useSSH) {
|
|
112
|
+
deploymentRepoURL = (0, utils_1.buildSshUrl)(githubHost, organizationName, projectName, githubPort);
|
|
90
113
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
114
|
+
else {
|
|
115
|
+
const gitPass = process.env.GIT_PASS;
|
|
116
|
+
const gitCredentials = gitPass ? `${gitUser}:${gitPass}` : gitUser;
|
|
117
|
+
deploymentRepoURL = (0, utils_1.buildHttpsUrl)(gitCredentials, githubHost, organizationName, projectName, githubPort);
|
|
118
|
+
}
|
|
119
|
+
logger_1.default.info `Remote repo URL: name=${obfuscateGitPass(deploymentRepoURL)}`;
|
|
94
120
|
// 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`);
|
|
121
|
+
const crossRepoPublish = !sourceRepoUrl.endsWith(`${organizationName}/${projectName}.git`);
|
|
99
122
|
// 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 (${
|
|
123
|
+
if (sourceBranch === deploymentBranch && !crossRepoPublish) {
|
|
124
|
+
throw new Error(`You cannot deploy from this branch (${sourceBranch}).` +
|
|
102
125
|
'\nYou will need to checkout to a different branch!');
|
|
103
126
|
}
|
|
104
127
|
// Save the commit hash that triggers publish-gh-pages before checking
|
|
@@ -107,42 +130,32 @@ This behavior can have SEO impacts and create relative link issues.
|
|
|
107
130
|
const runDeploy = async (outputDirectory) => {
|
|
108
131
|
const fromPath = outputDirectory;
|
|
109
132
|
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
133
|
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
|
-
}
|
|
134
|
+
// Check out deployment branch when cloning repository, and then remove all
|
|
135
|
+
// the files in the directory. If the 'clone' command fails, assume that
|
|
136
|
+
// the deployment branch doesn't exist, and initialize git in an empty
|
|
137
|
+
// directory, check out a clean deployment branch and add remote.
|
|
138
|
+
if (shellExecLog(`git clone --depth 1 --branch ${deploymentBranch} ${deploymentRepoURL} "${toPath}"`).code === 0) {
|
|
139
|
+
shellExecLog('git rm -rf .');
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
shellExecLog('git init');
|
|
143
|
+
shellExecLog(`git checkout -b ${deploymentBranch}`);
|
|
144
|
+
shellExecLog(`git remote add origin ${deploymentRepoURL}`);
|
|
131
145
|
}
|
|
132
|
-
shellExecLog('git rm -rf .');
|
|
133
146
|
try {
|
|
134
147
|
await fs_extra_1.default.copy(fromPath, toPath);
|
|
135
148
|
}
|
|
136
|
-
catch (
|
|
137
|
-
|
|
149
|
+
catch (err) {
|
|
150
|
+
logger_1.default.error `Copying build assets from path=${fromPath} to path=${toPath} failed.`;
|
|
151
|
+
throw err;
|
|
138
152
|
}
|
|
139
|
-
shelljs_1.default.cd(toPath);
|
|
140
153
|
shellExecLog('git add --all');
|
|
141
|
-
const commitMessage = process.env.CUSTOM_COMMIT_MESSAGE
|
|
154
|
+
const commitMessage = process.env.CUSTOM_COMMIT_MESSAGE ??
|
|
142
155
|
`Deploy website - based on ${currentCommit}`;
|
|
143
156
|
const commitResults = shellExecLog(`git commit -m "${commitMessage}"`);
|
|
144
157
|
if (shellExecLog(`git push --force origin ${deploymentBranch}`).code !== 0) {
|
|
145
|
-
throw new Error('Running "git push" command failed.');
|
|
158
|
+
throw new Error('Running "git push" command failed. Does the GitHub user account you are using have push access to the repository?');
|
|
146
159
|
}
|
|
147
160
|
else if (commitResults.code === 0) {
|
|
148
161
|
// The commit might return a non-zero value when site is up to date.
|
|
@@ -161,13 +174,13 @@ This behavior can have SEO impacts and create relative link issues.
|
|
|
161
174
|
}
|
|
162
175
|
};
|
|
163
176
|
if (!cliOptions.skipBuild) {
|
|
164
|
-
// Build
|
|
177
|
+
// Build site, then push to deploymentBranch branch of specified repo.
|
|
165
178
|
try {
|
|
166
|
-
await
|
|
179
|
+
await (0, build_1.build)(siteDir, cliOptions, false).then(runDeploy);
|
|
167
180
|
}
|
|
168
|
-
catch (
|
|
169
|
-
|
|
170
|
-
|
|
181
|
+
catch (err) {
|
|
182
|
+
logger_1.default.error('Deployment of the build output failed.');
|
|
183
|
+
throw err;
|
|
171
184
|
}
|
|
172
185
|
}
|
|
173
186
|
else {
|
|
@@ -175,4 +188,4 @@ This behavior can have SEO impacts and create relative link issues.
|
|
|
175
188
|
await runDeploy(outDir);
|
|
176
189
|
}
|
|
177
190
|
}
|
|
178
|
-
exports.
|
|
191
|
+
exports.deploy = deploy;
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
8
|
-
export
|
|
7
|
+
import type { CommanderStatic } from 'commander';
|
|
8
|
+
export declare function externalCommand(cli: CommanderStatic): Promise<void>;
|
package/lib/commands/external.js
CHANGED
|
@@ -6,20 +6,18 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.externalCommand = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
11
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
10
12
|
const server_1 = require("../server");
|
|
11
|
-
const init_1 =
|
|
12
|
-
async function externalCommand(cli
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const plugins = init_1.
|
|
13
|
+
const init_1 = require("../server/plugins/init");
|
|
14
|
+
async function externalCommand(cli) {
|
|
15
|
+
const siteDir = await fs_extra_1.default.realpath('.');
|
|
16
|
+
const context = await (0, server_1.loadContext)({ siteDir });
|
|
17
|
+
const plugins = await (0, init_1.initPlugins)(context);
|
|
16
18
|
// Plugin Lifecycle - extendCli.
|
|
17
19
|
plugins.forEach((plugin) => {
|
|
18
|
-
|
|
19
|
-
if (!extendCli) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
extendCli(cli);
|
|
20
|
+
plugin.extendCli?.(cli);
|
|
23
21
|
});
|
|
24
22
|
}
|
|
25
|
-
exports.
|
|
23
|
+
exports.externalCommand = externalCommand;
|
package/lib/commands/serve.d.ts
CHANGED
|
@@ -4,5 +4,11 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import { type HostPortOptions } from '../server/getHostPort';
|
|
8
|
+
import type { LoadContextOptions } from '../server';
|
|
9
|
+
export declare type ServeCLIOptions = HostPortOptions & Pick<LoadContextOptions, 'config'> & {
|
|
10
|
+
dir?: string;
|
|
11
|
+
build?: boolean;
|
|
12
|
+
open?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare function serve(siteDirParam?: string, cliOptions?: Partial<ServeCLIOptions>): Promise<void>;
|
package/lib/commands/serve.js
CHANGED
|
@@ -6,60 +6,61 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.serve = void 0;
|
|
9
10
|
const tslib_1 = require("tslib");
|
|
11
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
10
12
|
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
13
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
15
|
+
const utils_1 = require("@docusaurus/utils");
|
|
16
|
+
const serve_handler_1 = tslib_1.__importDefault(require("serve-handler"));
|
|
17
|
+
const openBrowser_1 = tslib_1.__importDefault(require("react-dev-utils/openBrowser"));
|
|
18
|
+
const config_1 = require("../server/config");
|
|
19
|
+
const build_1 = require("./build");
|
|
20
|
+
const getHostPort_1 = require("../server/getHostPort");
|
|
21
|
+
async function serve(siteDirParam = '.', cliOptions = {}) {
|
|
22
|
+
const siteDir = await fs_extra_1.default.realpath(siteDirParam);
|
|
23
|
+
const buildDir = cliOptions.dir ?? utils_1.DEFAULT_BUILD_DIR_NAME;
|
|
24
|
+
let dir = path_1.default.resolve(siteDir, buildDir);
|
|
22
25
|
if (cliOptions.build) {
|
|
23
|
-
dir = await build_1.
|
|
26
|
+
dir = await (0, build_1.build)(siteDir, {
|
|
24
27
|
config: cliOptions.config,
|
|
25
28
|
outDir: dir,
|
|
26
29
|
}, false);
|
|
27
30
|
}
|
|
28
|
-
const host =
|
|
29
|
-
const port = await commandUtils_1.getCLIOptionPort(cliOptions.port, host);
|
|
31
|
+
const { host, port } = await (0, getHostPort_1.getHostPort)(cliOptions);
|
|
30
32
|
if (port === null) {
|
|
31
33
|
process.exit();
|
|
32
34
|
}
|
|
33
|
-
const { siteConfig: { baseUrl, trailingSlash }, } = await
|
|
35
|
+
const { siteConfig: { baseUrl, trailingSlash }, } = await (0, config_1.loadSiteConfig)({
|
|
34
36
|
siteDir,
|
|
35
37
|
customConfigFilePath: cliOptions.config,
|
|
36
38
|
});
|
|
37
|
-
const servingUrl = `http://${
|
|
39
|
+
const servingUrl = `http://${host}:${port}`;
|
|
38
40
|
const server = http_1.default.createServer((req, res) => {
|
|
39
|
-
var _a, _b;
|
|
40
41
|
// Automatically redirect requests to /baseUrl/
|
|
41
|
-
if (!
|
|
42
|
+
if (!req.url?.startsWith(baseUrl)) {
|
|
42
43
|
res.writeHead(302, {
|
|
43
44
|
Location: baseUrl,
|
|
44
45
|
});
|
|
45
46
|
res.end();
|
|
46
47
|
return;
|
|
47
48
|
}
|
|
48
|
-
// Remove baseUrl before calling serveHandler
|
|
49
|
-
//
|
|
50
|
-
req.url =
|
|
51
|
-
serve_handler_1.default(req, res, {
|
|
49
|
+
// Remove baseUrl before calling serveHandler, because /baseUrl/ should
|
|
50
|
+
// serve /build/index.html, not /build/baseUrl/index.html (does not exist)
|
|
51
|
+
req.url = req.url.replace(baseUrl, '/');
|
|
52
|
+
(0, serve_handler_1.default)(req, res, {
|
|
52
53
|
cleanUrls: true,
|
|
53
54
|
public: dir,
|
|
54
55
|
trailingSlash,
|
|
56
|
+
directoryListing: false,
|
|
55
57
|
});
|
|
56
58
|
});
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
padding: 1,
|
|
60
|
-
margin: 1,
|
|
61
|
-
align: 'center',
|
|
62
|
-
}));
|
|
59
|
+
const url = servingUrl + baseUrl;
|
|
60
|
+
logger_1.default.success `Serving path=${buildDir} directory at: url=${url}`;
|
|
63
61
|
server.listen(port);
|
|
62
|
+
if (cliOptions.open && !process.env.CI) {
|
|
63
|
+
(0, openBrowser_1.default)(url);
|
|
64
|
+
}
|
|
64
65
|
}
|
|
65
|
-
exports.
|
|
66
|
+
exports.serve = serve;
|
package/lib/commands/start.d.ts
CHANGED
|
@@ -4,5 +4,12 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import { type LoadContextOptions } from '../server';
|
|
8
|
+
import { type HostPortOptions } from '../server/getHostPort';
|
|
9
|
+
export declare type StartCLIOptions = HostPortOptions & Pick<LoadContextOptions, 'locale' | 'config'> & {
|
|
10
|
+
hotOnly?: boolean;
|
|
11
|
+
open?: boolean;
|
|
12
|
+
poll?: boolean | number;
|
|
13
|
+
minify?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare function start(siteDirParam?: string, cliOptions?: Partial<StartCLIOptions>): Promise<void>;
|