@docusaurus/utils 0.0.0-4742 → 0.0.0-4747
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/gitUtils.d.ts +14 -5
- package/lib/gitUtils.d.ts.map +1 -1
- package/lib/gitUtils.js +14 -11
- package/lib/gitUtils.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -2
- package/lib/index.js.map +1 -1
- package/package.json +4 -4
- package/src/gitUtils.ts +34 -16
- package/src/index.ts +5 -1
package/lib/gitUtils.d.ts
CHANGED
|
@@ -6,12 +6,21 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class GitNotFoundError extends Error {
|
|
8
8
|
}
|
|
9
|
-
export declare
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
export declare class FileNotTrackedError extends Error {
|
|
10
|
+
}
|
|
11
|
+
export declare function getFileCommitDate(file: string, args: {
|
|
12
|
+
age?: 'oldest' | 'newest';
|
|
13
|
+
includeAuthor?: false;
|
|
14
|
+
}): {
|
|
15
|
+
date: Date;
|
|
16
|
+
timestamp: number;
|
|
17
|
+
};
|
|
18
|
+
export declare function getFileCommitDate(file: string, args: {
|
|
19
|
+
age?: 'oldest' | 'newest';
|
|
20
|
+
includeAuthor: true;
|
|
21
|
+
}): {
|
|
13
22
|
date: Date;
|
|
14
23
|
timestamp: number;
|
|
15
|
-
author
|
|
24
|
+
author: string;
|
|
16
25
|
};
|
|
17
26
|
//# sourceMappingURL=gitUtils.d.ts.map
|
package/lib/gitUtils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitUtils.d.ts","sourceRoot":"","sources":["../src/gitUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,qBAAa,gBAAiB,SAAQ,KAAK;CAAG;AAE9C,
|
|
1
|
+
{"version":3,"file":"gitUtils.d.ts","sourceRoot":"","sources":["../src/gitUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,qBAAa,gBAAiB,SAAQ,KAAK;CAAG;AAE9C,qBAAa,mBAAoB,SAAQ,KAAK;CAAG;AAEjD,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE;IAAC,GAAG,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAAC,aAAa,CAAC,EAAE,KAAK,CAAA;CAAC,GACvD;IACD,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AACF,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE;IAAC,GAAG,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAAC,aAAa,EAAE,IAAI,CAAA;CAAC,GACrD;IACD,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC"}
|
package/lib/gitUtils.js
CHANGED
|
@@ -6,22 +6,25 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.getFileCommitDate = exports.GitNotFoundError = void 0;
|
|
9
|
+
exports.getFileCommitDate = exports.FileNotTrackedError = exports.GitNotFoundError = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
12
|
const shelljs_1 = tslib_1.__importDefault(require("shelljs"));
|
|
13
13
|
class GitNotFoundError extends Error {
|
|
14
14
|
}
|
|
15
15
|
exports.GitNotFoundError = GitNotFoundError;
|
|
16
|
-
|
|
16
|
+
class FileNotTrackedError extends Error {
|
|
17
|
+
}
|
|
18
|
+
exports.FileNotTrackedError = FileNotTrackedError;
|
|
19
|
+
function getFileCommitDate(file, { age = 'oldest', includeAuthor = false, }) {
|
|
17
20
|
if (!shelljs_1.default.which('git')) {
|
|
18
21
|
throw new GitNotFoundError(`Failed to retrieve git history for "${file}" because git is not installed.`);
|
|
19
22
|
}
|
|
20
23
|
if (!shelljs_1.default.test('-f', file)) {
|
|
21
24
|
throw new Error(`Failed to retrieve git history for "${file}" because the file does not exist.`);
|
|
22
25
|
}
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
// Commit time and author name; not using author time so that amended commits
|
|
27
|
+
// can have their dates updated
|
|
25
28
|
let formatArg = '--format=%ct';
|
|
26
29
|
if (includeAuthor) {
|
|
27
30
|
formatArg += ',%an';
|
|
@@ -32,9 +35,9 @@ const getFileCommitDate = (file, { age = 'oldest', includeAuthor = false, }) =>
|
|
|
32
35
|
// --diff-filter=A ensures we only get the commit which (A)dded the file
|
|
33
36
|
extraArgs += ' --follow --diff-filter=A';
|
|
34
37
|
}
|
|
35
|
-
const result = shelljs_1.default.exec(`git log ${extraArgs} ${formatArg} -- "${
|
|
38
|
+
const result = shelljs_1.default.exec(`git log ${extraArgs} ${formatArg} -- "${path_1.default.basename(file)}"`, {
|
|
36
39
|
// cwd is important, see: https://github.com/facebook/docusaurus/pull/5048
|
|
37
|
-
cwd:
|
|
40
|
+
cwd: path_1.default.dirname(file),
|
|
38
41
|
silent: true,
|
|
39
42
|
});
|
|
40
43
|
if (result.code !== 0) {
|
|
@@ -45,11 +48,11 @@ const getFileCommitDate = (file, { age = 'oldest', includeAuthor = false, }) =>
|
|
|
45
48
|
regex = /^(?<timestamp>\d+),(?<author>.+)$/;
|
|
46
49
|
}
|
|
47
50
|
const output = result.stdout.trim();
|
|
51
|
+
if (!output) {
|
|
52
|
+
throw new FileNotTrackedError(`Failed to retrieve the git history for file "${file}" because the file is not tracked by git.`);
|
|
53
|
+
}
|
|
48
54
|
const match = output.match(regex);
|
|
49
|
-
if (!match
|
|
50
|
-
!match.groups ||
|
|
51
|
-
!match.groups.timestamp ||
|
|
52
|
-
(includeAuthor && !match.groups.author)) {
|
|
55
|
+
if (!match) {
|
|
53
56
|
throw new Error(`Failed to retrieve the git history for file "${file}" with unexpected output: ${output}`);
|
|
54
57
|
}
|
|
55
58
|
const timestamp = Number(match.groups.timestamp);
|
|
@@ -58,6 +61,6 @@ const getFileCommitDate = (file, { age = 'oldest', includeAuthor = false, }) =>
|
|
|
58
61
|
return { date, timestamp, author: match.groups.author };
|
|
59
62
|
}
|
|
60
63
|
return { date, timestamp };
|
|
61
|
-
}
|
|
64
|
+
}
|
|
62
65
|
exports.getFileCommitDate = getFileCommitDate;
|
|
63
66
|
//# sourceMappingURL=gitUtils.js.map
|
package/lib/gitUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gitUtils.js","sourceRoot":"","sources":["../src/gitUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wDAAwB;AACxB,8DAA4B;AAE5B,MAAa,gBAAiB,SAAQ,KAAK;CAAG;AAA9C,4CAA8C;
|
|
1
|
+
{"version":3,"file":"gitUtils.js","sourceRoot":"","sources":["../src/gitUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wDAAwB;AACxB,8DAA4B;AAE5B,MAAa,gBAAiB,SAAQ,KAAK;CAAG;AAA9C,4CAA8C;AAE9C,MAAa,mBAAoB,SAAQ,KAAK;CAAG;AAAjD,kDAAiD;AAiBjD,SAAgB,iBAAiB,CAC/B,IAAY,EACZ,EACE,GAAG,GAAG,QAAQ,EACd,aAAa,GAAG,KAAK,GAItB;IAMD,IAAI,CAAC,iBAAK,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;QACvB,MAAM,IAAI,gBAAgB,CACxB,uCAAuC,IAAI,iCAAiC,CAC7E,CAAC;KACH;IAED,IAAI,CAAC,iBAAK,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;QAC3B,MAAM,IAAI,KAAK,CACb,uCAAuC,IAAI,oCAAoC,CAChF,CAAC;KACH;IAED,6EAA6E;I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,IAAI,CAAC,CAAC;IAExC,IAAI,aAAa,EAAE;QACjB,OAAO,EAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,MAAO,CAAC,MAAO,EAAC,CAAC;KACzD;IACD,OAAO,EAAC,IAAI,EAAE,SAAS,EAAC,CAAC;AAC3B,CAAC;AAjFD,8CAiFC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export { NODE_MAJOR_VERSION, NODE_MINOR_VERSION, DEFAULT_BUILD_DIR_NAME, DEFAULT_CONFIG_FILE_NAME, BABEL_CONFIG_FILE_NAME, GENERATED_FILES_DIR_NAME, SRC_DIR_NAME, STATIC_DIR_NAME, OUTPUT_STATIC_ASSETS_DIR_NAME, THEME_PATH, DEFAULT_PORT, DEFAULT_PLUGIN_ID, WEBPACK_URL_LOADER_LIMIT, } from './constants';
|
|
8
8
|
export { generate, genChunkName, readOutputHTMLFile } from './emitUtils';
|
|
9
|
-
export { getFileCommitDate, GitNotFoundError } from './gitUtils';
|
|
9
|
+
export { getFileCommitDate, FileNotTrackedError, GitNotFoundError, } from './gitUtils';
|
|
10
10
|
export { mergeTranslations, updateTranslationFileMessages, getPluginI18nPath, } from './i18nUtils';
|
|
11
11
|
export { removeSuffix, removePrefix, getElementsAround, mapAsyncSequential, findAsyncSequential, reportMessage, } from './jsUtils';
|
|
12
12
|
export { normalizeUrl, getEditUrl, fileToPath, encodePath, isValidPathname, resolvePathname, addLeadingSlash, addTrailingSlash, removeTrailingSlash, hasSSHProtocol, buildHttpsUrl, buildSshUrl, } from './urlUtils';
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,EACxB,YAAY,EACZ,eAAe,EACf,6BAA6B,EAC7B,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,QAAQ,EAAE,YAAY,EAAE,kBAAkB,EAAC,MAAM,aAAa,CAAC;AACvE,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,EACxB,YAAY,EACZ,eAAe,EACf,6BAA6B,EAC7B,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,QAAQ,EAAE,YAAY,EAAE,kBAAkB,EAAC,MAAM,aAAa,CAAC;AACvE,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,iBAAiB,EACjB,6BAA6B,EAC7B,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,GACd,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,YAAY,EACZ,UAAU,EACV,UAAU,EACV,UAAU,EACV,eAAe,EACf,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,KAAK,GAAG,EACR,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,uBAAuB,EACvB,wBAAwB,EACxB,gBAAgB,GACjB,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,gBAAgB,EAChB,yBAAyB,EACzB,mBAAmB,EACnB,sBAAsB,EACtB,KAAK,qBAAqB,GAC3B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,0BAA0B,EAC/B,KAAK,0BAA0B,EAC/B,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAC,KAAK,cAAc,EAAE,KAAK,OAAO,EAAE,aAAa,EAAC,MAAM,WAAW,CAAC;AAC3E,OAAO,EACL,aAAa,EACb,SAAS,EACT,SAAS,EACT,yBAAyB,EACzB,eAAe,EACf,UAAU,EACV,wBAAwB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAC,MAAM,aAAa,CAAC;AAC1D,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,aAAa,EACb,6BAA6B,GAC9B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AAClD,OAAO,EACL,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,iBAAiB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
10
|
-
exports.getFolderContainingFile = exports.findFolderContainingFile = exports.getContentPathList = exports.getDataFileData = exports.getDataFilePath = exports.getFileLoaderUtils = exports.createAbsoluteFilePathMatcher = exports.createMatcher = exports.GlobExcludeDefault = exports.Globby = exports.docuHash = exports.simpleHash = exports.md5Hash = exports.addTrailingPathSeparator = exports.escapePath = exports.aliasedSitePath = exports.toMessageRelativeFilePath = exports.posixPath = exports.shortName = exports.isNameTooLong = void 0;
|
|
9
|
+
exports.replaceMarkdownLinks = exports.writeMarkdownHeadingId = exports.parseMarkdownString = exports.parseMarkdownContentTitle = exports.parseFrontMatter = exports.createExcerpt = exports.parseMarkdownHeadingId = exports.groupTaggedItems = exports.normalizeFrontMatterTags = exports.normalizeFrontMatterTag = exports.buildSshUrl = exports.buildHttpsUrl = exports.hasSSHProtocol = exports.removeTrailingSlash = exports.addTrailingSlash = exports.addLeadingSlash = exports.resolvePathname = exports.isValidPathname = exports.encodePath = exports.fileToPath = exports.getEditUrl = exports.normalizeUrl = exports.reportMessage = exports.findAsyncSequential = exports.mapAsyncSequential = exports.getElementsAround = exports.removePrefix = exports.removeSuffix = exports.getPluginI18nPath = exports.updateTranslationFileMessages = exports.mergeTranslations = exports.GitNotFoundError = exports.FileNotTrackedError = exports.getFileCommitDate = exports.readOutputHTMLFile = exports.genChunkName = exports.generate = exports.WEBPACK_URL_LOADER_LIMIT = exports.DEFAULT_PLUGIN_ID = exports.DEFAULT_PORT = exports.THEME_PATH = exports.OUTPUT_STATIC_ASSETS_DIR_NAME = exports.STATIC_DIR_NAME = exports.SRC_DIR_NAME = exports.GENERATED_FILES_DIR_NAME = exports.BABEL_CONFIG_FILE_NAME = exports.DEFAULT_CONFIG_FILE_NAME = exports.DEFAULT_BUILD_DIR_NAME = exports.NODE_MINOR_VERSION = exports.NODE_MAJOR_VERSION = void 0;
|
|
10
|
+
exports.getFolderContainingFile = exports.findFolderContainingFile = exports.getContentPathList = exports.getDataFileData = exports.getDataFilePath = exports.getFileLoaderUtils = exports.createAbsoluteFilePathMatcher = exports.createMatcher = exports.GlobExcludeDefault = exports.Globby = exports.docuHash = exports.simpleHash = exports.md5Hash = exports.addTrailingPathSeparator = exports.escapePath = exports.aliasedSitePath = exports.toMessageRelativeFilePath = exports.posixPath = exports.shortName = exports.isNameTooLong = exports.createSlugger = void 0;
|
|
11
11
|
var constants_1 = require("./constants");
|
|
12
12
|
Object.defineProperty(exports, "NODE_MAJOR_VERSION", { enumerable: true, get: function () { return constants_1.NODE_MAJOR_VERSION; } });
|
|
13
13
|
Object.defineProperty(exports, "NODE_MINOR_VERSION", { enumerable: true, get: function () { return constants_1.NODE_MINOR_VERSION; } });
|
|
@@ -28,6 +28,7 @@ Object.defineProperty(exports, "genChunkName", { enumerable: true, get: function
|
|
|
28
28
|
Object.defineProperty(exports, "readOutputHTMLFile", { enumerable: true, get: function () { return emitUtils_1.readOutputHTMLFile; } });
|
|
29
29
|
var gitUtils_1 = require("./gitUtils");
|
|
30
30
|
Object.defineProperty(exports, "getFileCommitDate", { enumerable: true, get: function () { return gitUtils_1.getFileCommitDate; } });
|
|
31
|
+
Object.defineProperty(exports, "FileNotTrackedError", { enumerable: true, get: function () { return gitUtils_1.FileNotTrackedError; } });
|
|
31
32
|
Object.defineProperty(exports, "GitNotFoundError", { enumerable: true, get: function () { return gitUtils_1.GitNotFoundError; } });
|
|
32
33
|
var i18nUtils_1 = require("./i18nUtils");
|
|
33
34
|
Object.defineProperty(exports, "mergeTranslations", { enumerable: true, get: function () { return i18nUtils_1.mergeTranslations; } });
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,yCAcqB;AAbnB,+GAAA,kBAAkB,OAAA;AAClB,+GAAA,kBAAkB,OAAA;AAClB,mHAAA,sBAAsB,OAAA;AACtB,qHAAA,wBAAwB,OAAA;AACxB,mHAAA,sBAAsB,OAAA;AACtB,qHAAA,wBAAwB,OAAA;AACxB,yGAAA,YAAY,OAAA;AACZ,4GAAA,eAAe,OAAA;AACf,0HAAA,6BAA6B,OAAA;AAC7B,uGAAA,UAAU,OAAA;AACV,yGAAA,YAAY,OAAA;AACZ,8GAAA,iBAAiB,OAAA;AACjB,qHAAA,wBAAwB,OAAA;AAE1B,yCAAuE;AAA/D,qGAAA,QAAQ,OAAA;AAAE,yGAAA,YAAY,OAAA;AAAE,+GAAA,kBAAkB,OAAA;AAClD,
|
|
1
|
+
{"version":3,"file":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d,+GAAA,uBAAuB,OAAA;AACvB,gHAAA,wBAAwB,OAAA;AACxB,wGAAA,gBAAgB,OAAA;AAElB,iDAQyB;AAPvB,uHAAA,sBAAsB,OAAA;AACtB,8GAAA,aAAa,OAAA;AACb,iHAAA,gBAAgB,OAAA;AAChB,0HAAA,yBAAyB,OAAA;AACzB,oHAAA,mBAAmB,OAAA;AACnB,uHAAA,sBAAsB,OAAA;AAGxB,iDAMyB;AADvB,qHAAA,oBAAoB,OAAA;AAEtB,qCAA2E;AAAhC,wGAAA,aAAa,OAAA;AACxD,yCAQqB;AAPnB,0GAAA,aAAa,OAAA;AACb,sGAAA,SAAS,OAAA;AACT,sGAAA,SAAS,OAAA;AACT,sHAAA,yBAAyB,OAAA;AACzB,4GAAA,eAAe,OAAA;AACf,uGAAA,UAAU,OAAA;AACV,qHAAA,wBAAwB,OAAA;AAE1B,yCAA0D;AAAlD,oGAAA,OAAO,OAAA;AAAE,uGAAA,UAAU,OAAA;AAAE,qGAAA,QAAQ,OAAA;AACrC,yCAKqB;AAJnB,mGAAA,MAAM,OAAA;AACN,+GAAA,kBAAkB,OAAA;AAClB,0GAAA,aAAa,OAAA;AACb,0HAAA,6BAA6B,OAAA;AAE/B,+CAAkD;AAA1C,kHAAA,kBAAkB,OAAA;AAC1B,iDAMyB;AALvB,gHAAA,eAAe,OAAA;AACf,gHAAA,eAAe,OAAA;AACf,mHAAA,kBAAkB,OAAA;AAClB,yHAAA,wBAAwB,OAAA;AACxB,wHAAA,uBAAuB,OAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/utils",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4747",
|
|
4
4
|
"description": "Node utility functions for Docusaurus packages.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/logger": "0.0.0-
|
|
21
|
+
"@docusaurus/logger": "0.0.0-4747",
|
|
22
22
|
"@svgr/webpack": "^6.2.1",
|
|
23
23
|
"file-loader": "^6.2.0",
|
|
24
24
|
"fs-extra": "^10.0.1",
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
"node": ">=14"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@docusaurus/types": "0.0.0-
|
|
41
|
+
"@docusaurus/types": "0.0.0-4747",
|
|
42
42
|
"@types/dedent": "^0.7.0",
|
|
43
43
|
"@types/github-slugger": "^1.3.0",
|
|
44
44
|
"@types/micromatch": "^4.0.2",
|
|
45
45
|
"@types/react-dom": "^17.0.14",
|
|
46
46
|
"dedent": "^0.7.0"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "ea3674ced376fb76245f4a371cb3894a64ee90b6"
|
|
49
49
|
}
|
package/src/gitUtils.ts
CHANGED
|
@@ -10,7 +10,24 @@ import shell from 'shelljs';
|
|
|
10
10
|
|
|
11
11
|
export class GitNotFoundError extends Error {}
|
|
12
12
|
|
|
13
|
-
export
|
|
13
|
+
export class FileNotTrackedError extends Error {}
|
|
14
|
+
|
|
15
|
+
export function getFileCommitDate(
|
|
16
|
+
file: string,
|
|
17
|
+
args: {age?: 'oldest' | 'newest'; includeAuthor?: false},
|
|
18
|
+
): {
|
|
19
|
+
date: Date;
|
|
20
|
+
timestamp: number;
|
|
21
|
+
};
|
|
22
|
+
export function getFileCommitDate(
|
|
23
|
+
file: string,
|
|
24
|
+
args: {age?: 'oldest' | 'newest'; includeAuthor: true},
|
|
25
|
+
): {
|
|
26
|
+
date: Date;
|
|
27
|
+
timestamp: number;
|
|
28
|
+
author: string;
|
|
29
|
+
};
|
|
30
|
+
export function getFileCommitDate(
|
|
14
31
|
file: string,
|
|
15
32
|
{
|
|
16
33
|
age = 'oldest',
|
|
@@ -23,7 +40,7 @@ export const getFileCommitDate = (
|
|
|
23
40
|
date: Date;
|
|
24
41
|
timestamp: number;
|
|
25
42
|
author?: string;
|
|
26
|
-
}
|
|
43
|
+
} {
|
|
27
44
|
if (!shell.which('git')) {
|
|
28
45
|
throw new GitNotFoundError(
|
|
29
46
|
`Failed to retrieve git history for "${file}" because git is not installed.`,
|
|
@@ -36,9 +53,8 @@ export const getFileCommitDate = (
|
|
|
36
53
|
);
|
|
37
54
|
}
|
|
38
55
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
56
|
+
// Commit time and author name; not using author time so that amended commits
|
|
57
|
+
// can have their dates updated
|
|
42
58
|
let formatArg = '--format=%ct';
|
|
43
59
|
if (includeAuthor) {
|
|
44
60
|
formatArg += ',%an';
|
|
@@ -52,10 +68,10 @@ export const getFileCommitDate = (
|
|
|
52
68
|
}
|
|
53
69
|
|
|
54
70
|
const result = shell.exec(
|
|
55
|
-
`git log ${extraArgs} ${formatArg} -- "${
|
|
71
|
+
`git log ${extraArgs} ${formatArg} -- "${path.basename(file)}"`,
|
|
56
72
|
{
|
|
57
73
|
// cwd is important, see: https://github.com/facebook/docusaurus/pull/5048
|
|
58
|
-
cwd:
|
|
74
|
+
cwd: path.dirname(file),
|
|
59
75
|
silent: true,
|
|
60
76
|
},
|
|
61
77
|
);
|
|
@@ -70,24 +86,26 @@ export const getFileCommitDate = (
|
|
|
70
86
|
}
|
|
71
87
|
|
|
72
88
|
const output = result.stdout.trim();
|
|
89
|
+
|
|
90
|
+
if (!output) {
|
|
91
|
+
throw new FileNotTrackedError(
|
|
92
|
+
`Failed to retrieve the git history for file "${file}" because the file is not tracked by git.`,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
73
96
|
const match = output.match(regex);
|
|
74
97
|
|
|
75
|
-
if (
|
|
76
|
-
!match ||
|
|
77
|
-
!match.groups ||
|
|
78
|
-
!match.groups.timestamp ||
|
|
79
|
-
(includeAuthor && !match.groups.author)
|
|
80
|
-
) {
|
|
98
|
+
if (!match) {
|
|
81
99
|
throw new Error(
|
|
82
100
|
`Failed to retrieve the git history for file "${file}" with unexpected output: ${output}`,
|
|
83
101
|
);
|
|
84
102
|
}
|
|
85
103
|
|
|
86
|
-
const timestamp = Number(match.groups
|
|
104
|
+
const timestamp = Number(match.groups!.timestamp);
|
|
87
105
|
const date = new Date(timestamp * 1000);
|
|
88
106
|
|
|
89
107
|
if (includeAuthor) {
|
|
90
|
-
return {date, timestamp, author: match.groups
|
|
108
|
+
return {date, timestamp, author: match.groups!.author!};
|
|
91
109
|
}
|
|
92
110
|
return {date, timestamp};
|
|
93
|
-
}
|
|
111
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -21,7 +21,11 @@ export {
|
|
|
21
21
|
WEBPACK_URL_LOADER_LIMIT,
|
|
22
22
|
} from './constants';
|
|
23
23
|
export {generate, genChunkName, readOutputHTMLFile} from './emitUtils';
|
|
24
|
-
export {
|
|
24
|
+
export {
|
|
25
|
+
getFileCommitDate,
|
|
26
|
+
FileNotTrackedError,
|
|
27
|
+
GitNotFoundError,
|
|
28
|
+
} from './gitUtils';
|
|
25
29
|
export {
|
|
26
30
|
mergeTranslations,
|
|
27
31
|
updateTranslationFileMessages,
|