@docusaurus/utils 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/lib/constants.d.ts +73 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +78 -0
- package/lib/constants.js.map +1 -0
- package/lib/dataFileUtils.d.ts +60 -0
- package/lib/dataFileUtils.d.ts.map +1 -0
- package/lib/dataFileUtils.js +91 -0
- package/lib/dataFileUtils.js.map +1 -0
- package/lib/emitUtils.d.ts +32 -0
- package/lib/emitUtils.d.ts.map +1 -0
- package/lib/emitUtils.js +80 -0
- package/lib/emitUtils.js.map +1 -0
- package/lib/gitUtils.d.ts +66 -0
- package/lib/gitUtils.d.ts.map +1 -0
- package/lib/gitUtils.js +63 -0
- package/lib/gitUtils.js.map +1 -0
- package/lib/globUtils.d.ts +40 -0
- package/lib/globUtils.d.ts.map +1 -0
- package/lib/globUtils.js +71 -0
- package/lib/globUtils.js.map +1 -0
- package/lib/hashUtils.d.ts +6 -4
- package/lib/hashUtils.d.ts.map +1 -0
- package/lib/hashUtils.js +13 -10
- package/lib/hashUtils.js.map +1 -0
- package/lib/i18nUtils.d.ts +53 -0
- package/lib/i18nUtils.d.ts.map +1 -0
- package/lib/i18nUtils.js +70 -0
- package/lib/i18nUtils.js.map +1 -0
- package/lib/index.d.ts +16 -75
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +91 -395
- package/lib/index.js.map +1 -0
- package/lib/jsUtils.d.ts +28 -0
- package/lib/jsUtils.d.ts.map +1 -0
- package/lib/jsUtils.js +57 -0
- package/lib/jsUtils.js.map +1 -0
- package/lib/markdownLinks.d.ts +49 -5
- package/lib/markdownLinks.d.ts.map +1 -0
- package/lib/markdownLinks.js +57 -13
- package/lib/markdownLinks.js.map +1 -0
- package/lib/markdownUtils.d.ts +112 -0
- package/lib/markdownUtils.d.ts.map +1 -0
- package/lib/markdownUtils.js +271 -0
- package/lib/markdownUtils.js.map +1 -0
- package/lib/pathUtils.d.ts +45 -1
- package/lib/pathUtils.d.ts.map +1 -0
- package/lib/pathUtils.js +92 -12
- package/lib/pathUtils.js.map +1 -0
- package/lib/shellUtils.d.ts +8 -0
- package/lib/shellUtils.d.ts.map +1 -0
- package/lib/shellUtils.js +21 -0
- package/lib/shellUtils.js.map +1 -0
- package/lib/slugger.d.ts +24 -0
- package/lib/slugger.d.ts.map +1 -0
- package/lib/slugger.js +23 -0
- package/lib/slugger.js.map +1 -0
- package/lib/tags.d.ts +59 -0
- package/lib/tags.d.ts.map +1 -0
- package/lib/tags.js +91 -0
- package/lib/tags.js.map +1 -0
- package/lib/urlUtils.d.ts +66 -0
- package/lib/urlUtils.d.ts.map +1 -0
- package/lib/urlUtils.js +207 -0
- package/lib/urlUtils.js.map +1 -0
- package/lib/webpackUtils.d.ts +35 -0
- package/lib/webpackUtils.d.ts.map +1 -0
- package/lib/webpackUtils.js +115 -0
- package/lib/webpackUtils.js.map +1 -0
- package/package.json +28 -10
- package/src/constants.ts +98 -0
- package/src/dataFileUtils.ts +122 -0
- package/src/deps.d.ts +10 -0
- package/src/emitUtils.ts +99 -0
- package/src/gitUtils.ts +146 -0
- package/src/globUtils.ts +85 -0
- package/src/hashUtils.ts +9 -8
- package/src/i18nUtils.ts +114 -0
- package/src/index.ts +97 -502
- package/src/jsUtils.ts +59 -0
- package/src/markdownLinks.ts +101 -30
- package/src/markdownUtils.ts +357 -0
- package/src/pathUtils.ts +93 -12
- package/src/shellUtils.ts +18 -0
- package/src/slugger.ts +36 -0
- package/src/tags.ts +130 -0
- package/src/urlUtils.ts +234 -0
- package/src/webpackUtils.ts +153 -0
- package/lib/.tsbuildinfo +0 -1
- package/lib/codeTranslationsUtils.d.ts +0 -11
- package/lib/codeTranslationsUtils.js +0 -50
- package/lib/escapePath.d.ts +0 -17
- package/lib/escapePath.js +0 -25
- package/lib/markdownParser.d.ts +0 -30
- package/lib/markdownParser.js +0 -140
- package/lib/posixPath.d.ts +0 -14
- package/lib/posixPath.js +0 -28
- package/src/__tests__/__fixtures__/defaultCodeTranslations/en.json +0 -4
- package/src/__tests__/__fixtures__/defaultCodeTranslations/fr-FR.json +0 -5
- package/src/__tests__/__fixtures__/defaultCodeTranslations/fr.json +0 -4
- package/src/__tests__/__snapshots__/index.test.ts.snap +0 -8
- package/src/__tests__/codeTranslationsUtils.test.ts +0 -112
- package/src/__tests__/escapePath.test.ts +0 -25
- package/src/__tests__/hashUtils.test.ts +0 -51
- package/src/__tests__/index.test.ts +0 -631
- package/src/__tests__/markdownParser.test.ts +0 -817
- package/src/__tests__/pathUtils.test.ts +0 -63
- package/src/__tests__/posixPath.test.ts +0 -25
- package/src/codeTranslationsUtils.ts +0 -56
- package/src/escapePath.ts +0 -23
- package/src/markdownParser.ts +0 -182
- package/src/posixPath.ts +0 -27
- package/tsconfig.json +0 -9
package/lib/globUtils.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createAbsoluteFilePathMatcher = exports.createMatcher = exports.GlobExcludeDefault = exports.Globby = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
// Globby/Micromatch are the 2 libs we use in Docusaurus consistently
|
|
12
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
13
|
+
const micromatch_1 = tslib_1.__importDefault(require("micromatch")); // Note: Micromatch is used by Globby
|
|
14
|
+
/** A re-export of the globby instance. */
|
|
15
|
+
var globby_1 = require("globby");
|
|
16
|
+
Object.defineProperty(exports, "Globby", { enumerable: true, get: function () { return tslib_1.__importDefault(globby_1).default; } });
|
|
17
|
+
/**
|
|
18
|
+
* The default glob patterns we ignore when sourcing content.
|
|
19
|
+
* - Ignore files and folders starting with `_` recursively
|
|
20
|
+
* - Ignore tests
|
|
21
|
+
*/
|
|
22
|
+
exports.GlobExcludeDefault = [
|
|
23
|
+
'**/_*.{js,jsx,ts,tsx,md,mdx}',
|
|
24
|
+
'**/_*/**',
|
|
25
|
+
'**/*.test.{js,jsx,ts,tsx}',
|
|
26
|
+
'**/__tests__/**',
|
|
27
|
+
];
|
|
28
|
+
/**
|
|
29
|
+
* A very thin wrapper around `Micromatch.makeRe`.
|
|
30
|
+
*
|
|
31
|
+
* @see {@link createAbsoluteFilePathMatcher}
|
|
32
|
+
* @param patterns A list of glob patterns. If the list is empty, it defaults to
|
|
33
|
+
* matching none.
|
|
34
|
+
* @returns A matcher handle that tells if a file path is matched by any of the
|
|
35
|
+
* patterns.
|
|
36
|
+
*/
|
|
37
|
+
function createMatcher(patterns) {
|
|
38
|
+
if (patterns.length === 0) {
|
|
39
|
+
// `/(?:)/.test("foo")` is `true`
|
|
40
|
+
return () => false;
|
|
41
|
+
}
|
|
42
|
+
const regexp = new RegExp(patterns.map((pattern) => micromatch_1.default.makeRe(pattern).source).join('|'));
|
|
43
|
+
return (str) => regexp.test(str);
|
|
44
|
+
}
|
|
45
|
+
exports.createMatcher = createMatcher;
|
|
46
|
+
/**
|
|
47
|
+
* We use match patterns like `"** /_* /**"` (ignore the spaces), where `"_*"`
|
|
48
|
+
* should only be matched within a subfolder. This function would:
|
|
49
|
+
* - Match `/user/sebastien/website/docs/_partials/xyz.md`
|
|
50
|
+
* - Ignore `/user/_sebastien/website/docs/partials/xyz.md`
|
|
51
|
+
*
|
|
52
|
+
* @param patterns A list of glob patterns.
|
|
53
|
+
* @param rootFolders A list of root folders to resolve the glob from.
|
|
54
|
+
* @returns A matcher handle that tells if a file path is matched by any of the
|
|
55
|
+
* patterns, resolved from the first root folder that contains the path.
|
|
56
|
+
* @throws Throws when the returned matcher receives a path that doesn't belong
|
|
57
|
+
* to any of the `rootFolders`.
|
|
58
|
+
*/
|
|
59
|
+
function createAbsoluteFilePathMatcher(patterns, rootFolders) {
|
|
60
|
+
const matcher = createMatcher(patterns);
|
|
61
|
+
function getRelativeFilePath(absoluteFilePath) {
|
|
62
|
+
const rootFolder = rootFolders.find((folderPath) => absoluteFilePath.startsWith(folderPath));
|
|
63
|
+
if (!rootFolder) {
|
|
64
|
+
throw new Error(`createAbsoluteFilePathMatcher unexpected error, absoluteFilePath=${absoluteFilePath} was not contained in any of the root folders: ${rootFolders.join(', ')}`);
|
|
65
|
+
}
|
|
66
|
+
return path_1.default.relative(rootFolder, absoluteFilePath);
|
|
67
|
+
}
|
|
68
|
+
return (absoluteFilePath) => matcher(getRelativeFilePath(absoluteFilePath));
|
|
69
|
+
}
|
|
70
|
+
exports.createAbsoluteFilePathMatcher = createAbsoluteFilePathMatcher;
|
|
71
|
+
//# sourceMappingURL=globUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"globUtils.js","sourceRoot":"","sources":["../src/globUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,qEAAqE;AAErE,wDAAwB;AACxB,oEAAoC,CAAC,qCAAqC;AAE1E,0CAA0C;AAC1C,iCAAyC;AAAjC,yHAAA,OAAO,OAAU;AAEzB;;;;GAIG;AACU,QAAA,kBAAkB,GAAG;IAChC,8BAA8B;IAC9B,UAAU;IACV,2BAA2B;IAC3B,iBAAiB;CAClB,CAAC;AAIF;;;;;;;;GAQG;AACH,SAAgB,aAAa,CAAC,QAAkB;IAC9C,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;QACzB,iCAAiC;QACjC,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC;KACpB;IACD,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,oBAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CACvE,CAAC;IACF,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACnC,CAAC;AATD,sCASC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,6BAA6B,CAC3C,QAAkB,EAClB,WAAqB;IAErB,MAAM,OAAO,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IAExC,SAAS,mBAAmB,CAAC,gBAAwB;QACnD,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CACjD,gBAAgB,CAAC,UAAU,CAAC,UAAU,CAAC,CACxC,CAAC;QACF,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,IAAI,KAAK,CACb,oEAAoE,gBAAgB,kDAAkD,WAAW,CAAC,IAAI,CACpJ,IAAI,CACL,EAAE,CACJ,CAAC;SACH;QACD,OAAO,cAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,CAAC,gBAAwB,EAAE,EAAE,CAClC,OAAO,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,CAAC,CAAC;AACnD,CAAC;AAtBD,sEAsBC"}
|
package/lib/hashUtils.d.ts
CHANGED
|
@@ -4,12 +4,14 @@
|
|
|
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
|
+
/** Thin wrapper around `crypto.createHash("md5")`. */
|
|
7
8
|
export declare function md5Hash(str: string): string;
|
|
9
|
+
/** Creates an MD5 hash and truncates it to the given length. */
|
|
8
10
|
export declare function simpleHash(str: string, length: number): string;
|
|
9
11
|
/**
|
|
10
|
-
* Given an input string, convert to kebab-case and append a hash
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* filename per OS. Avoids ERRNAMETOOLONG error.
|
|
12
|
+
* Given an input string, convert to kebab-case and append a hash, avoiding name
|
|
13
|
+
* collision. Also removes part of the string if its larger than the allowed
|
|
14
|
+
* filename per OS, avoiding `ERRNAMETOOLONG` error.
|
|
14
15
|
*/
|
|
15
16
|
export declare function docuHash(str: string): string;
|
|
17
|
+
//# sourceMappingURL=hashUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hashUtils.d.ts","sourceRoot":"","sources":["../src/hashUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,sDAAsD;AACtD,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,gEAAgE;AAChE,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAE9D;AAGD;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAU5C"}
|
package/lib/hashUtils.js
CHANGED
|
@@ -7,33 +7,36 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.docuHash = exports.simpleHash = exports.md5Hash = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
10
11
|
const crypto_1 = require("crypto");
|
|
11
|
-
const lodash_1 = require("lodash");
|
|
12
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
13
|
const pathUtils_1 = require("./pathUtils");
|
|
14
|
+
/** Thin wrapper around `crypto.createHash("md5")`. */
|
|
13
15
|
function md5Hash(str) {
|
|
14
|
-
return crypto_1.createHash('md5').update(str).digest('hex');
|
|
16
|
+
return (0, crypto_1.createHash)('md5').update(str).digest('hex');
|
|
15
17
|
}
|
|
16
18
|
exports.md5Hash = md5Hash;
|
|
19
|
+
/** Creates an MD5 hash and truncates it to the given length. */
|
|
17
20
|
function simpleHash(str, length) {
|
|
18
|
-
return md5Hash(str).
|
|
21
|
+
return md5Hash(str).substring(0, length);
|
|
19
22
|
}
|
|
20
23
|
exports.simpleHash = simpleHash;
|
|
21
24
|
// Based on https://github.com/gatsbyjs/gatsby/pull/21518/files
|
|
22
25
|
/**
|
|
23
|
-
* Given an input string, convert to kebab-case and append a hash
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* filename per OS. Avoids ERRNAMETOOLONG error.
|
|
26
|
+
* Given an input string, convert to kebab-case and append a hash, avoiding name
|
|
27
|
+
* collision. Also removes part of the string if its larger than the allowed
|
|
28
|
+
* filename per OS, avoiding `ERRNAMETOOLONG` error.
|
|
27
29
|
*/
|
|
28
30
|
function docuHash(str) {
|
|
29
31
|
if (str === '/') {
|
|
30
32
|
return 'index';
|
|
31
33
|
}
|
|
32
34
|
const shortHash = simpleHash(str, 3);
|
|
33
|
-
const parsedPath = `${lodash_1.kebabCase(str)}-${shortHash}`;
|
|
34
|
-
if (pathUtils_1.isNameTooLong(parsedPath)) {
|
|
35
|
-
return `${pathUtils_1.shortName(lodash_1.kebabCase(str))}-${shortHash}`;
|
|
35
|
+
const parsedPath = `${lodash_1.default.kebabCase(str)}-${shortHash}`;
|
|
36
|
+
if ((0, pathUtils_1.isNameTooLong)(parsedPath)) {
|
|
37
|
+
return `${(0, pathUtils_1.shortName)(lodash_1.default.kebabCase(str))}-${shortHash}`;
|
|
36
38
|
}
|
|
37
39
|
return parsedPath;
|
|
38
40
|
}
|
|
39
41
|
exports.docuHash = docuHash;
|
|
42
|
+
//# sourceMappingURL=hashUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hashUtils.js","sourceRoot":"","sources":["../src/hashUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,mCAAkC;AAClC,4DAAuB;AACvB,2CAAqD;AAErD,sDAAsD;AACtD,SAAgB,OAAO,CAAC,GAAW;IACjC,OAAO,IAAA,mBAAU,EAAC,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACrD,CAAC;AAFD,0BAEC;AAED,gEAAgE;AAChE,SAAgB,UAAU,CAAC,GAAW,EAAE,MAAc;IACpD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAC3C,CAAC;AAFD,gCAEC;AAED,+DAA+D;AAC/D;;;;GAIG;AACH,SAAgB,QAAQ,CAAC,GAAW;IAClC,IAAI,GAAG,KAAK,GAAG,EAAE;QACf,OAAO,OAAO,CAAC;KAChB;IACD,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACrC,MAAM,UAAU,GAAG,GAAG,gBAAC,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,SAAS,EAAE,CAAC;IACtD,IAAI,IAAA,yBAAa,EAAC,UAAU,CAAC,EAAE;QAC7B,OAAO,GAAG,IAAA,qBAAS,EAAC,gBAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,SAAS,EAAE,CAAC;KACtD;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAVD,4BAUC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
*/
|
|
7
|
+
import type { TranslationFileContent, TranslationFile, I18n } from '@docusaurus/types';
|
|
8
|
+
/**
|
|
9
|
+
* Takes a list of translation file contents, and shallow-merges them into one.
|
|
10
|
+
*/
|
|
11
|
+
export declare function mergeTranslations(contents: TranslationFileContent[]): TranslationFileContent;
|
|
12
|
+
/**
|
|
13
|
+
* Useful to update all the messages of a translation file. Used in tests to
|
|
14
|
+
* simulate translations.
|
|
15
|
+
*/
|
|
16
|
+
export declare function updateTranslationFileMessages(translationFile: TranslationFile, updateMessage: (message: string) => string): TranslationFile;
|
|
17
|
+
/**
|
|
18
|
+
* Takes everything needed and constructs a plugin i18n path. Plugins should
|
|
19
|
+
* expect everything it needs for translations to be found under this path.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getPluginI18nPath({ localizationDir, pluginName, pluginId, subPaths, }: {
|
|
22
|
+
localizationDir: string;
|
|
23
|
+
pluginName: string;
|
|
24
|
+
pluginId?: string | undefined;
|
|
25
|
+
subPaths?: string[];
|
|
26
|
+
}): string;
|
|
27
|
+
/**
|
|
28
|
+
* Takes a path and returns a localized a version (which is basically `path +
|
|
29
|
+
* i18n.currentLocale`).
|
|
30
|
+
*
|
|
31
|
+
* This is used to resolve the `outDir` and `baseUrl` of each locale; it is NOT
|
|
32
|
+
* used to determine plugin localization file locations.
|
|
33
|
+
*/
|
|
34
|
+
export declare function localizePath({ pathType, path: originalPath, i18n, options, }: {
|
|
35
|
+
/**
|
|
36
|
+
* FS paths will treat Windows specially; URL paths will always have a
|
|
37
|
+
* trailing slash to make it a valid base URL.
|
|
38
|
+
*/
|
|
39
|
+
pathType: 'fs' | 'url';
|
|
40
|
+
/** The path, URL or file path, to be localized. */
|
|
41
|
+
path: string;
|
|
42
|
+
/** The current i18n context. */
|
|
43
|
+
i18n: I18n;
|
|
44
|
+
options?: {
|
|
45
|
+
/**
|
|
46
|
+
* By default, we don't localize the path of defaultLocale. This option
|
|
47
|
+
* would override that behavior. Setting `false` is useful for `yarn build
|
|
48
|
+
* -l zh-Hans` to always emit into the root build directory.
|
|
49
|
+
*/
|
|
50
|
+
localizePath?: boolean;
|
|
51
|
+
};
|
|
52
|
+
}): string;
|
|
53
|
+
//# sourceMappingURL=i18nUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18nUtils.d.ts","sourceRoot":"","sources":["../src/i18nUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EACV,sBAAsB,EACtB,eAAe,EACf,IAAI,EACL,MAAM,mBAAmB,CAAC;AAE3B;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,sBAAsB,EAAE,GACjC,sBAAsB,CAExB;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,eAAe,EAAE,eAAe,EAChC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,GACzC,eAAe,CAQjB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,eAAe,EACf,UAAU,EACV,QAA4B,EAC5B,QAAa,GACd,EAAE;IACD,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,GAAG,MAAM,CAQT;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,IAAI,EAAE,YAAY,EAClB,IAAI,EACJ,OAAY,GACb,EAAE;IACD;;;OAGG;IACH,QAAQ,EAAE,IAAI,GAAG,KAAK,CAAC;IACvB,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,CAAC,EAAE;QACR;;;;WAIG;QACH,YAAY,CAAC,EAAE,OAAO,CAAC;KACxB,CAAC;CACH,GAAG,MAAM,CAgBT"}
|
package/lib/i18nUtils.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.localizePath = exports.getPluginI18nPath = exports.updateTranslationFileMessages = exports.mergeTranslations = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
13
|
+
const constants_1 = require("./constants");
|
|
14
|
+
const urlUtils_1 = require("./urlUtils");
|
|
15
|
+
/**
|
|
16
|
+
* Takes a list of translation file contents, and shallow-merges them into one.
|
|
17
|
+
*/
|
|
18
|
+
function mergeTranslations(contents) {
|
|
19
|
+
return contents.reduce((acc, content) => ({ ...acc, ...content }), {});
|
|
20
|
+
}
|
|
21
|
+
exports.mergeTranslations = mergeTranslations;
|
|
22
|
+
/**
|
|
23
|
+
* Useful to update all the messages of a translation file. Used in tests to
|
|
24
|
+
* simulate translations.
|
|
25
|
+
*/
|
|
26
|
+
function updateTranslationFileMessages(translationFile, updateMessage) {
|
|
27
|
+
return {
|
|
28
|
+
...translationFile,
|
|
29
|
+
content: lodash_1.default.mapValues(translationFile.content, (translation) => ({
|
|
30
|
+
...translation,
|
|
31
|
+
message: updateMessage(translation.message),
|
|
32
|
+
})),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
exports.updateTranslationFileMessages = updateTranslationFileMessages;
|
|
36
|
+
/**
|
|
37
|
+
* Takes everything needed and constructs a plugin i18n path. Plugins should
|
|
38
|
+
* expect everything it needs for translations to be found under this path.
|
|
39
|
+
*/
|
|
40
|
+
function getPluginI18nPath({ localizationDir, pluginName, pluginId = constants_1.DEFAULT_PLUGIN_ID, subPaths = [], }) {
|
|
41
|
+
return path_1.default.join(localizationDir,
|
|
42
|
+
// Make it convenient to use for single-instance
|
|
43
|
+
// ie: return "docs", not "docs-default" nor "docs/default"
|
|
44
|
+
`${pluginName}${pluginId === constants_1.DEFAULT_PLUGIN_ID ? '' : `-${pluginId}`}`, ...subPaths);
|
|
45
|
+
}
|
|
46
|
+
exports.getPluginI18nPath = getPluginI18nPath;
|
|
47
|
+
/**
|
|
48
|
+
* Takes a path and returns a localized a version (which is basically `path +
|
|
49
|
+
* i18n.currentLocale`).
|
|
50
|
+
*
|
|
51
|
+
* This is used to resolve the `outDir` and `baseUrl` of each locale; it is NOT
|
|
52
|
+
* used to determine plugin localization file locations.
|
|
53
|
+
*/
|
|
54
|
+
function localizePath({ pathType, path: originalPath, i18n, options = {}, }) {
|
|
55
|
+
const shouldLocalizePath = options.localizePath ?? i18n.currentLocale !== i18n.defaultLocale;
|
|
56
|
+
if (!shouldLocalizePath) {
|
|
57
|
+
return originalPath;
|
|
58
|
+
}
|
|
59
|
+
// FS paths need special care, for Windows support. Note: we don't use the
|
|
60
|
+
// locale config's `path` here, because this function is used for resolving
|
|
61
|
+
// outDir, which must be the same as baseUrl. When we have the baseUrl config,
|
|
62
|
+
// we need to sync the two.
|
|
63
|
+
if (pathType === 'fs') {
|
|
64
|
+
return path_1.default.join(originalPath, i18n.currentLocale);
|
|
65
|
+
}
|
|
66
|
+
// Url paths; add a trailing slash so it's a valid base URL
|
|
67
|
+
return (0, urlUtils_1.normalizeUrl)([originalPath, i18n.currentLocale, '/']);
|
|
68
|
+
}
|
|
69
|
+
exports.localizePath = localizePath;
|
|
70
|
+
//# sourceMappingURL=i18nUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18nUtils.js","sourceRoot":"","sources":["../src/i18nUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wDAAwB;AACxB,4DAAuB;AACvB,2CAA8C;AAC9C,yCAAwC;AAOxC;;GAEG;AACH,SAAgB,iBAAiB,CAC/B,QAAkC;IAElC,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,EAAC,GAAG,GAAG,EAAE,GAAG,OAAO,EAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACvE,CAAC;AAJD,8CAIC;AAED;;;GAGG;AACH,SAAgB,6BAA6B,CAC3C,eAAgC,EAChC,aAA0C;IAE1C,OAAO;QACL,GAAG,eAAe;QAClB,OAAO,EAAE,gBAAC,CAAC,SAAS,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;YAC9D,GAAG,WAAW;YACd,OAAO,EAAE,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC;SAC5C,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC;AAXD,sEAWC;AAED;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,EAChC,eAAe,EACf,UAAU,EACV,QAAQ,GAAG,6BAAiB,EAC5B,QAAQ,GAAG,EAAE,GAMd;IACC,OAAO,cAAI,CAAC,IAAI,CACd,eAAe;IACf,gDAAgD;IAChD,2DAA2D;IAC3D,GAAG,UAAU,GAAG,QAAQ,KAAK,6BAAiB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE,EAAE,EACtE,GAAG,QAAQ,CACZ,CAAC;AACJ,CAAC;AAlBD,8CAkBC;AAED;;;;;;GAMG;AACH,SAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,IAAI,EAAE,YAAY,EAClB,IAAI,EACJ,OAAO,GAAG,EAAE,GAmBb;IACC,MAAM,kBAAkB,GACtB,OAAO,CAAC,YAAY,IAAI,IAAI,CAAC,aAAa,KAAK,IAAI,CAAC,aAAa,CAAC;IAEpE,IAAI,CAAC,kBAAkB,EAAE;QACvB,OAAO,YAAY,CAAC;KACrB;IACD,0EAA0E;IAC1E,2EAA2E;IAC3E,8EAA8E;IAC9E,2BAA2B;IAC3B,IAAI,QAAQ,KAAK,IAAI,EAAE;QACrB,OAAO,cAAI,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;KACpD;IACD,2DAA2D;IAC3D,OAAO,IAAA,uBAAY,EAAC,CAAC,YAAY,EAAE,IAAI,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC,CAAC;AAC/D,CAAC;AAvCD,oCAuCC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -4,79 +4,20 @@
|
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
7
|
+
export { NODE_MAJOR_VERSION, NODE_MINOR_VERSION, DOCUSAURUS_VERSION, DEFAULT_BUILD_DIR_NAME, DEFAULT_CONFIG_FILE_NAME, BABEL_CONFIG_FILE_NAME, GENERATED_FILES_DIR_NAME, SRC_DIR_NAME, DEFAULT_STATIC_DIR_NAME, OUTPUT_STATIC_ASSETS_DIR_NAME, THEME_PATH, DEFAULT_I18N_DIR_NAME, CODE_TRANSLATIONS_FILE_NAME, DEFAULT_PORT, DEFAULT_PLUGIN_ID, WEBPACK_URL_LOADER_LIMIT, } from './constants';
|
|
8
|
+
export { generate, readOutputHTMLFile } from './emitUtils';
|
|
9
|
+
export { getFileCommitDate, FileNotTrackedError, GitNotFoundError, } from './gitUtils';
|
|
10
|
+
export { mergeTranslations, updateTranslationFileMessages, getPluginI18nPath, localizePath, } from './i18nUtils';
|
|
11
|
+
export { removeSuffix, removePrefix, mapAsyncSequential, findAsyncSequential, } from './jsUtils';
|
|
12
|
+
export { normalizeUrl, getEditUrl, fileToPath, encodePath, isValidPathname, resolvePathname, addLeadingSlash, addTrailingSlash, removeTrailingSlash, hasSSHProtocol, buildHttpsUrl, buildSshUrl, } from './urlUtils';
|
|
13
|
+
export { type Tag, type TagsListItem, type TagModule, type FrontMatterTag, normalizeFrontMatterTags, groupTaggedItems, } from './tags';
|
|
14
|
+
export { parseMarkdownHeadingId, createExcerpt, parseFrontMatter, parseMarkdownContentTitle, parseMarkdownString, writeMarkdownHeadingId, type WriteHeadingIDOptions, } from './markdownUtils';
|
|
15
|
+
export { type ContentPaths, type BrokenMarkdownLink, replaceMarkdownLinks, } from './markdownLinks';
|
|
16
|
+
export { type SluggerOptions, type Slugger, createSlugger } from './slugger';
|
|
17
|
+
export { isNameTooLong, shortName, posixPath, toMessageRelativeFilePath, aliasedSitePath, escapePath, addTrailingPathSeparator, } from './pathUtils';
|
|
14
18
|
export { md5Hash, simpleHash, docuHash } from './hashUtils';
|
|
15
|
-
export
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*/
|
|
21
|
-
export declare function fileToPath(file: string): string;
|
|
22
|
-
export declare function encodePath(userpath: string): string;
|
|
23
|
-
/**
|
|
24
|
-
* Convert first string character to the upper case.
|
|
25
|
-
* E.g: docusaurus -> Docusaurus
|
|
26
|
-
*/
|
|
27
|
-
export declare function upperFirst(str: string): string;
|
|
28
|
-
/**
|
|
29
|
-
* Generate unique React Component Name.
|
|
30
|
-
* E.g: /foo-bar -> FooBar096
|
|
31
|
-
*/
|
|
32
|
-
export declare function genComponentName(pagePath: string): string;
|
|
33
|
-
export declare function toMessageRelativeFilePath(filePath: string): string;
|
|
34
|
-
/**
|
|
35
|
-
* Generate unique chunk name given a module path.
|
|
36
|
-
*/
|
|
37
|
-
export declare function genChunkName(modulePath: string, prefix?: string, preferredName?: string, shortId?: boolean): string;
|
|
38
|
-
export declare function idx(target: any, keyPaths?: string | (string | number)[]): any;
|
|
39
|
-
/**
|
|
40
|
-
* Given a filepath and dirpath, get the first directory.
|
|
41
|
-
*/
|
|
42
|
-
export declare function getSubFolder(file: string, refDir: string): string | null;
|
|
43
|
-
export declare function normalizeUrl(rawUrls: string[]): string;
|
|
44
|
-
/**
|
|
45
|
-
* Alias filepath relative to site directory, very useful so that we
|
|
46
|
-
* don't expose user's site structure.
|
|
47
|
-
* Example: some/path/to/website/docs/foo.md -> @site/docs/foo.md
|
|
48
|
-
*/
|
|
49
|
-
export declare function aliasedSitePath(filePath: string, siteDir: string): string;
|
|
50
|
-
export declare function getEditUrl(fileRelativePath: string, editUrl?: string): string | undefined;
|
|
51
|
-
export declare function isValidPathname(str: string): boolean;
|
|
52
|
-
export declare function resolvePathname(to: string, from?: string): string;
|
|
53
|
-
export declare function addLeadingSlash(str: string): string;
|
|
54
|
-
export declare function addTrailingPathSeparator(str: string): string;
|
|
55
|
-
export declare function addTrailingSlash(str: string): string;
|
|
56
|
-
export declare function removeTrailingSlash(str: string): string;
|
|
57
|
-
export declare function removeSuffix(str: string, suffix: string): string;
|
|
58
|
-
export declare function removePrefix(str: string, prefix: string): string;
|
|
59
|
-
export declare function getElementsAround<T extends unknown>(array: T[], aroundIndex: number): {
|
|
60
|
-
next: T | undefined;
|
|
61
|
-
previous: T | undefined;
|
|
62
|
-
};
|
|
63
|
-
export declare function getPluginI18nPath({ siteDir, locale, pluginName, pluginId, // TODO duplicated constant
|
|
64
|
-
subPaths, }: {
|
|
65
|
-
siteDir: string;
|
|
66
|
-
locale: string;
|
|
67
|
-
pluginName: string;
|
|
68
|
-
pluginId?: string | undefined;
|
|
69
|
-
subPaths?: string[];
|
|
70
|
-
}): string;
|
|
71
|
-
export declare function mapAsyncSequencial<T extends unknown, R extends unknown>(array: T[], action: (t: T) => Promise<R>): Promise<R[]>;
|
|
72
|
-
export declare function findAsyncSequential<T>(array: T[], predicate: (t: T) => Promise<boolean>): Promise<T | undefined>;
|
|
73
|
-
export declare function findFolderContainingFile(folderPaths: string[], relativeFilePath: string): Promise<string | undefined>;
|
|
74
|
-
export declare function getFolderContainingFile(folderPaths: string[], relativeFilePath: string): Promise<string>;
|
|
75
|
-
export declare function reportMessage(message: string, reportingSeverity: ReportingSeverity): void;
|
|
76
|
-
export declare function mergeTranslations(contents: TranslationFileContent[]): TranslationFileContent;
|
|
77
|
-
export declare function getSwizzledComponent(componentPath: string): string | undefined;
|
|
78
|
-
export declare function updateTranslationFileMessages(translationFile: TranslationFile, updateMessage: (message: string) => string): TranslationFile;
|
|
79
|
-
export declare function parseMarkdownHeadingId(heading: string): {
|
|
80
|
-
text: string;
|
|
81
|
-
id?: string;
|
|
82
|
-
};
|
|
19
|
+
export { Globby, GlobExcludeDefault, createMatcher, createAbsoluteFilePathMatcher, } from './globUtils';
|
|
20
|
+
export { getFileLoaderUtils } from './webpackUtils';
|
|
21
|
+
export { escapeShellArg } from './shellUtils';
|
|
22
|
+
export { getDataFilePath, getDataFileData, getContentPathList, findFolderContainingFile, getFolderContainingFile, } from './dataFileUtils';
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,EACxB,YAAY,EACZ,uBAAuB,EACvB,6BAA6B,EAC7B,UAAU,EACV,qBAAqB,EACrB,2BAA2B,EAC3B,YAAY,EACZ,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,QAAQ,EAAE,kBAAkB,EAAC,MAAM,aAAa,CAAC;AACzD,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,iBAAiB,EACjB,6BAA6B,EAC7B,iBAAiB,EACjB,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,GACpB,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,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,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,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,EAAC,cAAc,EAAC,MAAM,cAAc,CAAC;AAC5C,OAAO,EACL,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,iBAAiB,CAAC"}
|