@docusaurus/core 3.7.0-canary-6244 → 3.7.0-canary-6245
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/beforeCli.mjs +3 -3
- package/lib/commands/deploy.js +70 -28
- package/package.json +12 -12
package/bin/beforeCli.mjs
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import fs from 'fs-extra';
|
|
11
11
|
import path from 'path';
|
|
12
12
|
import {createRequire} from 'module';
|
|
13
|
-
import
|
|
13
|
+
import execa from 'execa';
|
|
14
14
|
import {logger} from '@docusaurus/logger';
|
|
15
15
|
import semver from 'semver';
|
|
16
16
|
import updateNotifier from 'update-notifier';
|
|
@@ -111,8 +111,8 @@ export default async function beforeCli() {
|
|
|
111
111
|
return undefined;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
const yarnVersionResult =
|
|
115
|
-
if (yarnVersionResult
|
|
114
|
+
const yarnVersionResult = await execa.command('yarn --version');
|
|
115
|
+
if (yarnVersionResult.exitCode === 0) {
|
|
116
116
|
const majorVersion = parseInt(
|
|
117
117
|
yarnVersionResult.stdout?.trim().split('.')[0] ?? '',
|
|
118
118
|
10,
|
package/lib/commands/deploy.js
CHANGED
|
@@ -12,7 +12,7 @@ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
|
12
12
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
13
13
|
const os_1 = tslib_1.__importDefault(require("os"));
|
|
14
14
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
15
|
-
const
|
|
15
|
+
const execa_1 = tslib_1.__importDefault(require("execa"));
|
|
16
16
|
const utils_1 = require("@docusaurus/utils");
|
|
17
17
|
const site_1 = require("../server/site");
|
|
18
18
|
const build_1 = require("./build/build");
|
|
@@ -21,19 +21,41 @@ function obfuscateGitPass(str) {
|
|
|
21
21
|
const gitPass = process.env.GIT_PASS;
|
|
22
22
|
return gitPass ? str.replace(gitPass, 'GIT_PASS') : str;
|
|
23
23
|
}
|
|
24
|
+
const debugMode = !!process.env.DOCUSAURUS_DEPLOY_DEBUG;
|
|
24
25
|
// Log executed commands so that user can figure out mistakes on his own
|
|
25
26
|
// for example: https://github.com/facebook/docusaurus/issues/3875
|
|
26
|
-
function
|
|
27
|
+
function exec(cmd, options) {
|
|
28
|
+
const log = options?.log ?? true;
|
|
29
|
+
const failfast = options?.failfast ?? false;
|
|
27
30
|
try {
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
// TODO migrate to execa(file,[...args]) instead
|
|
32
|
+
// Use async/await everything
|
|
33
|
+
// Avoid execa.command: the args need to be escaped manually
|
|
34
|
+
const result = execa_1.default.commandSync(cmd);
|
|
35
|
+
if (log || debugMode) {
|
|
36
|
+
logger_1.default.info `code=${obfuscateGitPass(cmd)} subdue=${`code: ${result.exitCode}`}`;
|
|
37
|
+
}
|
|
38
|
+
if (debugMode) {
|
|
39
|
+
console.log(result);
|
|
40
|
+
}
|
|
41
|
+
if (failfast && result.exitCode !== 0) {
|
|
42
|
+
throw new Error(`Command returned unexpected exitCode ${result.exitCode}`);
|
|
43
|
+
}
|
|
30
44
|
return result;
|
|
31
45
|
}
|
|
32
46
|
catch (err) {
|
|
33
|
-
logger_1.default.
|
|
34
|
-
|
|
47
|
+
throw new Error(logger_1.default.interpolate `Error while executing command code=${obfuscateGitPass(cmd)}
|
|
48
|
+
In CWD code=${process.cwd()}`, { cause: err });
|
|
35
49
|
}
|
|
36
50
|
}
|
|
51
|
+
// Execa escape args and add necessary quotes automatically
|
|
52
|
+
// When using Execa.command, the args containing spaces must be escaped manually
|
|
53
|
+
function escapeArg(arg) {
|
|
54
|
+
return arg.replaceAll(' ', '\\ ');
|
|
55
|
+
}
|
|
56
|
+
function hasGit() {
|
|
57
|
+
return exec('git --version').exitCode === 0;
|
|
58
|
+
}
|
|
37
59
|
async function deploy(siteDirParam = '.', cliOptions = {}) {
|
|
38
60
|
const siteDir = await fs_extra_1.default.realpath(siteDirParam);
|
|
39
61
|
const { outDir, siteConfig, siteConfigPath } = await (0, site_1.loadContext)({
|
|
@@ -48,16 +70,23 @@ This behavior can have SEO impacts and create relative link issues.
|
|
|
48
70
|
`);
|
|
49
71
|
}
|
|
50
72
|
logger_1.default.info('Deploy command invoked...');
|
|
51
|
-
if (!
|
|
52
|
-
throw new Error('Git not installed or
|
|
73
|
+
if (!hasGit()) {
|
|
74
|
+
throw new Error('Git not installed or not added to PATH!');
|
|
53
75
|
}
|
|
54
76
|
// Source repo is the repo from where the command is invoked
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
77
|
+
const { stdout } = exec('git remote get-url origin', {
|
|
78
|
+
log: false,
|
|
79
|
+
failfast: true,
|
|
80
|
+
});
|
|
81
|
+
const sourceRepoUrl = stdout.trim();
|
|
58
82
|
// The source branch; defaults to the currently checked out branch
|
|
59
83
|
const sourceBranch = process.env.CURRENT_BRANCH ??
|
|
60
|
-
|
|
84
|
+
exec('git rev-parse --abbrev-ref HEAD', {
|
|
85
|
+
log: false,
|
|
86
|
+
failfast: true,
|
|
87
|
+
})
|
|
88
|
+
?.stdout?.toString()
|
|
89
|
+
.trim();
|
|
61
90
|
const gitUser = process.env.GIT_USER;
|
|
62
91
|
let useSSH = process.env.USE_SSH !== undefined &&
|
|
63
92
|
process.env.USE_SSH.toLowerCase() === 'true';
|
|
@@ -87,8 +116,11 @@ This behavior can have SEO impacts and create relative link issues.
|
|
|
87
116
|
// We never deploy on pull request.
|
|
88
117
|
const isPullRequest = process.env.CI_PULL_REQUEST ?? process.env.CIRCLE_PULL_REQUEST;
|
|
89
118
|
if (isPullRequest) {
|
|
90
|
-
|
|
91
|
-
|
|
119
|
+
exec('echo "Skipping deploy on a pull request."', {
|
|
120
|
+
log: false,
|
|
121
|
+
failfast: true,
|
|
122
|
+
});
|
|
123
|
+
process.exit(0);
|
|
92
124
|
}
|
|
93
125
|
// github.io indicates organization repos that deploy via default branch. All
|
|
94
126
|
// others use gh-pages (either case can be configured actually, but we can
|
|
@@ -126,21 +158,24 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
|
|
|
126
158
|
}
|
|
127
159
|
// Save the commit hash that triggers publish-gh-pages before checking
|
|
128
160
|
// out to deployment branch.
|
|
129
|
-
const currentCommit =
|
|
161
|
+
const currentCommit = exec('git rev-parse HEAD')?.stdout?.toString().trim();
|
|
130
162
|
const runDeploy = async (outputDirectory) => {
|
|
131
163
|
const targetDirectory = cliOptions.targetDir ?? '.';
|
|
132
164
|
const fromPath = outputDirectory;
|
|
133
165
|
const toPath = await fs_extra_1.default.mkdtemp(path_1.default.join(os_1.default.tmpdir(), `${projectName}-${deploymentBranch}`));
|
|
134
|
-
|
|
166
|
+
process.chdir(toPath);
|
|
135
167
|
// Clones the repo into the temp folder and checks out the target branch.
|
|
136
168
|
// If the branch doesn't exist, it creates a new one based on the
|
|
137
169
|
// repository default branch.
|
|
138
|
-
if (
|
|
139
|
-
|
|
140
|
-
|
|
170
|
+
if (exec(`git clone --depth 1 --branch ${deploymentBranch} ${deploymentRepoURL} ${escapeArg(toPath)}`).exitCode !== 0) {
|
|
171
|
+
exec(`git clone --depth 1 ${deploymentRepoURL} ${escapeArg(toPath)}`);
|
|
172
|
+
exec(`git checkout -b ${deploymentBranch}`);
|
|
141
173
|
}
|
|
142
174
|
// Clear out any existing contents in the target directory
|
|
143
|
-
|
|
175
|
+
exec(`git rm -rf ${escapeArg(targetDirectory)}`, {
|
|
176
|
+
log: false,
|
|
177
|
+
failfast: true,
|
|
178
|
+
});
|
|
144
179
|
const targetPath = path_1.default.join(toPath, targetDirectory);
|
|
145
180
|
try {
|
|
146
181
|
await fs_extra_1.default.copy(fromPath, targetPath);
|
|
@@ -149,22 +184,24 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
|
|
|
149
184
|
logger_1.default.error `Copying build assets from path=${fromPath} to path=${targetPath} failed.`;
|
|
150
185
|
throw err;
|
|
151
186
|
}
|
|
152
|
-
|
|
187
|
+
exec('git add --all', { failfast: true });
|
|
153
188
|
const gitUserName = process.env.GIT_USER_NAME;
|
|
154
189
|
if (gitUserName) {
|
|
155
|
-
|
|
190
|
+
exec(`git config user.name ${escapeArg(gitUserName)}`, { failfast: true });
|
|
156
191
|
}
|
|
157
192
|
const gitUserEmail = process.env.GIT_USER_EMAIL;
|
|
158
193
|
if (gitUserEmail) {
|
|
159
|
-
|
|
194
|
+
exec(`git config user.email ${escapeArg(gitUserEmail)}`, {
|
|
195
|
+
failfast: true,
|
|
196
|
+
});
|
|
160
197
|
}
|
|
161
198
|
const commitMessage = process.env.CUSTOM_COMMIT_MESSAGE ??
|
|
162
199
|
`Deploy website - based on ${currentCommit}`;
|
|
163
|
-
const commitResults =
|
|
164
|
-
if (
|
|
200
|
+
const commitResults = exec(`git commit -m ${escapeArg(commitMessage)} --allow-empty`);
|
|
201
|
+
if (exec(`git push --force origin ${deploymentBranch}`).exitCode !== 0) {
|
|
165
202
|
throw new Error('Running "git push" command failed. Does the GitHub user account you are using have push access to the repository?');
|
|
166
203
|
}
|
|
167
|
-
else if (commitResults.
|
|
204
|
+
else if (commitResults.exitCode === 0) {
|
|
168
205
|
// The commit might return a non-zero value when site is up to date.
|
|
169
206
|
let websiteURL = '';
|
|
170
207
|
if (githubHost === 'github.com') {
|
|
@@ -176,8 +213,13 @@ You can also set the deploymentBranch property in docusaurus.config.js .`);
|
|
|
176
213
|
// GitHub enterprise hosting.
|
|
177
214
|
websiteURL = `https://${githubHost}/pages/${organizationName}/${projectName}/`;
|
|
178
215
|
}
|
|
179
|
-
|
|
180
|
-
|
|
216
|
+
try {
|
|
217
|
+
exec(`echo "Website is live at ${websiteURL}."`, { failfast: true });
|
|
218
|
+
process.exit(0);
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
throw new Error(`Failed to execute command: ${err}`);
|
|
222
|
+
}
|
|
181
223
|
}
|
|
182
224
|
};
|
|
183
225
|
if (!cliOptions.skipBuild) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/core",
|
|
3
3
|
"description": "Easy to Maintain Open Source Documentation Websites",
|
|
4
|
-
"version": "3.7.0-canary-
|
|
4
|
+
"version": "3.7.0-canary-6245",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
"url": "https://github.com/facebook/docusaurus/issues"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@docusaurus/babel": "3.7.0-canary-
|
|
37
|
-
"@docusaurus/bundler": "3.7.0-canary-
|
|
38
|
-
"@docusaurus/logger": "3.7.0-canary-
|
|
39
|
-
"@docusaurus/mdx-loader": "3.7.0-canary-
|
|
40
|
-
"@docusaurus/utils": "3.7.0-canary-
|
|
41
|
-
"@docusaurus/utils-common": "3.7.0-canary-
|
|
42
|
-
"@docusaurus/utils-validation": "3.7.0-canary-
|
|
36
|
+
"@docusaurus/babel": "3.7.0-canary-6245",
|
|
37
|
+
"@docusaurus/bundler": "3.7.0-canary-6245",
|
|
38
|
+
"@docusaurus/logger": "3.7.0-canary-6245",
|
|
39
|
+
"@docusaurus/mdx-loader": "3.7.0-canary-6245",
|
|
40
|
+
"@docusaurus/utils": "3.7.0-canary-6245",
|
|
41
|
+
"@docusaurus/utils-common": "3.7.0-canary-6245",
|
|
42
|
+
"@docusaurus/utils-validation": "3.7.0-canary-6245",
|
|
43
43
|
"boxen": "^6.2.1",
|
|
44
44
|
"chalk": "^4.1.2",
|
|
45
45
|
"chokidar": "^3.5.3",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"escape-html": "^1.0.3",
|
|
53
53
|
"eta": "^2.2.0",
|
|
54
54
|
"eval": "^0.1.8",
|
|
55
|
+
"execa": "5.1.1",
|
|
55
56
|
"fs-extra": "^11.1.1",
|
|
56
57
|
"html-tags": "^3.3.1",
|
|
57
58
|
"html-webpack-plugin": "^5.6.0",
|
|
@@ -68,7 +69,6 @@
|
|
|
68
69
|
"react-router-dom": "^5.3.4",
|
|
69
70
|
"semver": "^7.5.4",
|
|
70
71
|
"serve-handler": "^6.1.6",
|
|
71
|
-
"shelljs": "^0.8.5",
|
|
72
72
|
"tinypool": "^1.0.2",
|
|
73
73
|
"tslib": "^2.6.0",
|
|
74
74
|
"update-notifier": "^6.0.2",
|
|
@@ -78,8 +78,8 @@
|
|
|
78
78
|
"webpack-merge": "^6.0.1"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@docusaurus/module-type-aliases": "3.7.0-canary-
|
|
82
|
-
"@docusaurus/types": "3.7.0-canary-
|
|
81
|
+
"@docusaurus/module-type-aliases": "3.7.0-canary-6245",
|
|
82
|
+
"@docusaurus/types": "3.7.0-canary-6245",
|
|
83
83
|
"@total-typescript/shoehorn": "^0.1.2",
|
|
84
84
|
"@types/detect-port": "^1.3.3",
|
|
85
85
|
"@types/react-dom": "^18.2.7",
|
|
@@ -99,5 +99,5 @@
|
|
|
99
99
|
"engines": {
|
|
100
100
|
"node": ">=18.0"
|
|
101
101
|
},
|
|
102
|
-
"gitHead": "
|
|
102
|
+
"gitHead": "65621de892b3c3b011c9888712803039301672c9"
|
|
103
103
|
}
|