@docusaurus/plugin-content-docs 0.0.0-4565 → 0.0.0-4566
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/lib/lastUpdate.js +13 -34
- package/package.json +10 -10
- package/src/lastUpdate.ts +13 -47
package/lib/lastUpdate.js
CHANGED
|
@@ -8,52 +8,31 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.getFileLastUpdate = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const shelljs_1 = (0, tslib_1.__importDefault)(require("shelljs"));
|
|
12
11
|
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
13
|
-
const
|
|
14
|
-
const GIT_COMMIT_TIMESTAMP_AUTHOR_REGEX = /^(?<timestamp>\d+),(?<author>.+)$/;
|
|
12
|
+
const utils_1 = require("@docusaurus/utils");
|
|
15
13
|
let showedGitRequirementError = false;
|
|
16
14
|
async function getFileLastUpdate(filePath) {
|
|
17
15
|
if (!filePath) {
|
|
18
16
|
return null;
|
|
19
17
|
}
|
|
20
|
-
function getTimestampAndAuthor(str) {
|
|
21
|
-
var _a;
|
|
22
|
-
if (!str) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
const temp = (_a = str.match(GIT_COMMIT_TIMESTAMP_AUTHOR_REGEX)) === null || _a === void 0 ? void 0 : _a.groups;
|
|
26
|
-
return temp
|
|
27
|
-
? { timestamp: Number(temp.timestamp), author: temp.author }
|
|
28
|
-
: null;
|
|
29
|
-
}
|
|
30
18
|
// Wrap in try/catch in case the shell commands fail
|
|
31
19
|
// (e.g. project doesn't use Git, etc).
|
|
32
20
|
try {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
logger_1.default.warn('Sorry, the docs plugin last update options require Git.');
|
|
37
|
-
}
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
if (!shelljs_1.default.test('-f', filePath)) {
|
|
41
|
-
throw new Error(`Retrieval of git history failed at "${filePath}" because the file does not exist.`);
|
|
42
|
-
}
|
|
43
|
-
const fileBasename = path_1.default.basename(filePath);
|
|
44
|
-
const fileDirname = path_1.default.dirname(filePath);
|
|
45
|
-
const result = shelljs_1.default.exec(`git log --max-count=1 --format=%ct,%an -- "${fileBasename}"`, {
|
|
46
|
-
cwd: fileDirname,
|
|
47
|
-
silent: true,
|
|
21
|
+
const result = (0, utils_1.getFileCommitDate)(filePath, {
|
|
22
|
+
age: 'newest',
|
|
23
|
+
includeAuthor: true,
|
|
48
24
|
});
|
|
49
|
-
|
|
50
|
-
throw new Error(`Retrieval of git history failed at "${filePath}" with exit code ${result.code}: ${result.stderr}`);
|
|
51
|
-
}
|
|
52
|
-
return getTimestampAndAuthor(result.stdout.trim());
|
|
25
|
+
return { timestamp: result.timestamp, author: result.author };
|
|
53
26
|
}
|
|
54
27
|
catch (e) {
|
|
55
|
-
|
|
28
|
+
if (e instanceof utils_1.GitNotFoundError && !showedGitRequirementError) {
|
|
29
|
+
logger_1.default.warn('Sorry, the docs plugin last update options require Git.');
|
|
30
|
+
showedGitRequirementError = true;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
logger_1.default.error(e);
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
56
36
|
}
|
|
57
|
-
return null;
|
|
58
37
|
}
|
|
59
38
|
exports.getFileLastUpdate = getFileLastUpdate;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-content-docs",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4566",
|
|
4
4
|
"description": "Docs plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -23,30 +23,30 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@docusaurus/core": "0.0.0-
|
|
27
|
-
"@docusaurus/logger": "0.0.0-
|
|
28
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
29
|
-
"@docusaurus/utils": "0.0.0-
|
|
30
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
26
|
+
"@docusaurus/core": "0.0.0-4566",
|
|
27
|
+
"@docusaurus/logger": "0.0.0-4566",
|
|
28
|
+
"@docusaurus/mdx-loader": "0.0.0-4566",
|
|
29
|
+
"@docusaurus/utils": "0.0.0-4566",
|
|
30
|
+
"@docusaurus/utils-validation": "0.0.0-4566",
|
|
31
31
|
"combine-promises": "^1.1.0",
|
|
32
32
|
"fs-extra": "^10.0.0",
|
|
33
33
|
"import-fresh": "^3.2.2",
|
|
34
34
|
"js-yaml": "^4.0.0",
|
|
35
35
|
"lodash": "^4.17.20",
|
|
36
36
|
"remark-admonitions": "^1.2.1",
|
|
37
|
-
"shelljs": "^0.8.4",
|
|
38
37
|
"tslib": "^2.3.1",
|
|
39
38
|
"utility-types": "^3.10.0",
|
|
40
39
|
"webpack": "^5.68.0"
|
|
41
40
|
},
|
|
42
41
|
"devDependencies": {
|
|
43
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
44
|
-
"@docusaurus/types": "0.0.0-
|
|
42
|
+
"@docusaurus/module-type-aliases": "0.0.0-4566",
|
|
43
|
+
"@docusaurus/types": "0.0.0-4566",
|
|
45
44
|
"@types/js-yaml": "^4.0.0",
|
|
46
45
|
"@types/picomatch": "^2.2.1",
|
|
47
46
|
"commander": "^5.1.0",
|
|
48
47
|
"escape-string-regexp": "^4.0.0",
|
|
49
48
|
"picomatch": "^2.1.1",
|
|
49
|
+
"shelljs": "^0.8.4",
|
|
50
50
|
"utility-types": "^3.10.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"engines": {
|
|
57
57
|
"node": ">=14"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "9f29e9998cf84adba25ceabd263fb637537d0033"
|
|
60
60
|
}
|
package/src/lastUpdate.ts
CHANGED
|
@@ -5,14 +5,11 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import shell from 'shelljs';
|
|
9
8
|
import logger from '@docusaurus/logger';
|
|
10
|
-
import
|
|
9
|
+
import {getFileCommitDate, GitNotFoundError} from '@docusaurus/utils';
|
|
11
10
|
|
|
12
11
|
type FileLastUpdateData = {timestamp?: number; author?: string};
|
|
13
12
|
|
|
14
|
-
const GIT_COMMIT_TIMESTAMP_AUTHOR_REGEX = /^(?<timestamp>\d+),(?<author>.+)$/;
|
|
15
|
-
|
|
16
13
|
let showedGitRequirementError = false;
|
|
17
14
|
|
|
18
15
|
export async function getFileLastUpdate(
|
|
@@ -21,53 +18,22 @@ export async function getFileLastUpdate(
|
|
|
21
18
|
if (!filePath) {
|
|
22
19
|
return null;
|
|
23
20
|
}
|
|
24
|
-
function getTimestampAndAuthor(str: string): FileLastUpdateData | null {
|
|
25
|
-
if (!str) {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const temp = str.match(GIT_COMMIT_TIMESTAMP_AUTHOR_REGEX)?.groups;
|
|
30
|
-
return temp
|
|
31
|
-
? {timestamp: Number(temp.timestamp), author: temp.author}
|
|
32
|
-
: null;
|
|
33
|
-
}
|
|
34
21
|
|
|
35
22
|
// Wrap in try/catch in case the shell commands fail
|
|
36
23
|
// (e.g. project doesn't use Git, etc).
|
|
37
24
|
try {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (!shell.test('-f', filePath)) {
|
|
48
|
-
throw new Error(
|
|
49
|
-
`Retrieval of git history failed at "${filePath}" because the file does not exist.`,
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const fileBasename = path.basename(filePath);
|
|
54
|
-
const fileDirname = path.dirname(filePath);
|
|
55
|
-
const result = shell.exec(
|
|
56
|
-
`git log --max-count=1 --format=%ct,%an -- "${fileBasename}"`,
|
|
57
|
-
{
|
|
58
|
-
cwd: fileDirname, // this is needed: https://github.com/facebook/docusaurus/pull/5048
|
|
59
|
-
silent: true,
|
|
60
|
-
},
|
|
61
|
-
);
|
|
62
|
-
if (result.code !== 0) {
|
|
63
|
-
throw new Error(
|
|
64
|
-
`Retrieval of git history failed at "${filePath}" with exit code ${result.code}: ${result.stderr}`,
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
return getTimestampAndAuthor(result.stdout.trim());
|
|
25
|
+
const result = getFileCommitDate(filePath, {
|
|
26
|
+
age: 'newest',
|
|
27
|
+
includeAuthor: true,
|
|
28
|
+
});
|
|
29
|
+
return {timestamp: result.timestamp, author: result.author};
|
|
68
30
|
} catch (e) {
|
|
69
|
-
|
|
31
|
+
if (e instanceof GitNotFoundError && !showedGitRequirementError) {
|
|
32
|
+
logger.warn('Sorry, the docs plugin last update options require Git.');
|
|
33
|
+
showedGitRequirementError = true;
|
|
34
|
+
} else {
|
|
35
|
+
logger.error(e);
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
70
38
|
}
|
|
71
|
-
|
|
72
|
-
return null;
|
|
73
39
|
}
|