@docusaurus/utils 2.0.0-beta.15a2b59f9 → 2.0.0-beta.17

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.
Files changed (104) hide show
  1. package/lib/constants.d.ts +20 -0
  2. package/lib/constants.d.ts.map +1 -0
  3. package/lib/constants.js +26 -0
  4. package/lib/constants.js.map +1 -0
  5. package/lib/dataFileUtils.d.ts +24 -0
  6. package/lib/dataFileUtils.d.ts.map +1 -0
  7. package/lib/dataFileUtils.js +65 -0
  8. package/lib/dataFileUtils.js.map +1 -0
  9. package/lib/emitUtils.d.ts +23 -0
  10. package/lib/emitUtils.d.ts.map +1 -0
  11. package/lib/emitUtils.js +90 -0
  12. package/lib/emitUtils.js.map +1 -0
  13. package/lib/gitUtils.d.ts +17 -0
  14. package/lib/gitUtils.d.ts.map +1 -0
  15. package/lib/gitUtils.js +63 -0
  16. package/lib/gitUtils.js.map +1 -0
  17. package/lib/globUtils.d.ts +12 -0
  18. package/lib/globUtils.d.ts.map +1 -0
  19. package/lib/globUtils.js +48 -0
  20. package/lib/globUtils.js.map +1 -0
  21. package/lib/hashUtils.d.ts +1 -0
  22. package/lib/hashUtils.d.ts.map +1 -0
  23. package/lib/hashUtils.js +7 -5
  24. package/lib/hashUtils.js.map +1 -0
  25. package/lib/i18nUtils.d.ts +17 -0
  26. package/lib/i18nUtils.d.ts.map +1 -0
  27. package/lib/i18nUtils.js +40 -0
  28. package/lib/i18nUtils.js.map +1 -0
  29. package/lib/index.d.ts +15 -75
  30. package/lib/index.d.ts.map +1 -0
  31. package/lib/index.js +84 -395
  32. package/lib/index.js.map +1 -0
  33. package/lib/jsUtils.d.ts +17 -0
  34. package/lib/jsUtils.d.ts.map +1 -0
  35. package/lib/jsUtils.js +72 -0
  36. package/lib/jsUtils.js.map +1 -0
  37. package/lib/markdownLinks.d.ts +1 -0
  38. package/lib/markdownLinks.d.ts.map +1 -0
  39. package/lib/markdownLinks.js +36 -11
  40. package/lib/markdownLinks.js.map +1 -0
  41. package/lib/markdownParser.d.ts +5 -3
  42. package/lib/markdownParser.d.ts.map +1 -0
  43. package/lib/markdownParser.js +72 -52
  44. package/lib/markdownParser.js.map +1 -0
  45. package/lib/pathUtils.d.ts +44 -0
  46. package/lib/pathUtils.d.ts.map +1 -0
  47. package/lib/pathUtils.js +88 -10
  48. package/lib/pathUtils.js.map +1 -0
  49. package/lib/slugger.d.ts +14 -0
  50. package/lib/slugger.d.ts.map +1 -0
  51. package/lib/slugger.js +19 -0
  52. package/lib/slugger.js.map +1 -0
  53. package/lib/tags.d.ts +27 -0
  54. package/lib/tags.d.ts.map +1 -0
  55. package/lib/tags.js +76 -0
  56. package/lib/tags.js.map +1 -0
  57. package/lib/urlUtils.d.ts +20 -0
  58. package/lib/urlUtils.d.ts.map +1 -0
  59. package/lib/urlUtils.js +136 -0
  60. package/lib/urlUtils.js.map +1 -0
  61. package/lib/webpackUtils.d.ts +30 -0
  62. package/lib/webpackUtils.d.ts.map +1 -0
  63. package/lib/webpackUtils.js +112 -0
  64. package/lib/webpackUtils.js.map +1 -0
  65. package/package.json +20 -10
  66. package/src/constants.ts +38 -0
  67. package/src/dataFileUtils.ts +90 -0
  68. package/src/deps.d.ts +10 -0
  69. package/src/emitUtils.ts +113 -0
  70. package/src/gitUtils.ts +93 -0
  71. package/src/globUtils.ts +64 -0
  72. package/src/hashUtils.ts +3 -3
  73. package/src/i18nUtils.ts +58 -0
  74. package/src/index.ts +87 -502
  75. package/src/jsUtils.ts +88 -0
  76. package/src/markdownLinks.ts +35 -13
  77. package/src/markdownParser.ts +76 -57
  78. package/src/pathUtils.ts +87 -8
  79. package/src/slugger.ts +24 -0
  80. package/src/tags.ts +105 -0
  81. package/src/urlUtils.ts +149 -0
  82. package/src/webpackUtils.ts +146 -0
  83. package/lib/.tsbuildinfo +0 -1
  84. package/lib/codeTranslationsUtils.d.ts +0 -11
  85. package/lib/codeTranslationsUtils.js +0 -50
  86. package/lib/escapePath.d.ts +0 -17
  87. package/lib/escapePath.js +0 -25
  88. package/lib/posixPath.d.ts +0 -14
  89. package/lib/posixPath.js +0 -28
  90. package/src/__tests__/__fixtures__/defaultCodeTranslations/en.json +0 -4
  91. package/src/__tests__/__fixtures__/defaultCodeTranslations/fr-FR.json +0 -5
  92. package/src/__tests__/__fixtures__/defaultCodeTranslations/fr.json +0 -4
  93. package/src/__tests__/__snapshots__/index.test.ts.snap +0 -8
  94. package/src/__tests__/codeTranslationsUtils.test.ts +0 -112
  95. package/src/__tests__/escapePath.test.ts +0 -25
  96. package/src/__tests__/hashUtils.test.ts +0 -51
  97. package/src/__tests__/index.test.ts +0 -631
  98. package/src/__tests__/markdownParser.test.ts +0 -817
  99. package/src/__tests__/pathUtils.test.ts +0 -63
  100. package/src/__tests__/posixPath.test.ts +0 -25
  101. package/src/codeTranslationsUtils.ts +0 -56
  102. package/src/escapePath.ts +0 -23
  103. package/src/posixPath.ts +0 -27
  104. package/tsconfig.json +0 -9
@@ -0,0 +1,20 @@
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
+ export declare const NODE_MAJOR_VERSION: number;
8
+ export declare const NODE_MINOR_VERSION: number;
9
+ export declare const DEFAULT_BUILD_DIR_NAME = "build";
10
+ export declare const DEFAULT_CONFIG_FILE_NAME = "docusaurus.config.js";
11
+ export declare const BABEL_CONFIG_FILE_NAME: string;
12
+ export declare const GENERATED_FILES_DIR_NAME: string;
13
+ export declare const SRC_DIR_NAME = "src";
14
+ export declare const STATIC_DIR_NAME = "static";
15
+ export declare const OUTPUT_STATIC_ASSETS_DIR_NAME = "assets";
16
+ export declare const THEME_PATH: string;
17
+ export declare const DEFAULT_PORT = 3000;
18
+ export declare const DEFAULT_PLUGIN_ID = "default";
19
+ export declare const WEBPACK_URL_LOADER_LIMIT: string | number;
20
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,kBAAkB,QAG9B,CAAC;AACF,eAAO,MAAM,kBAAkB,QAG9B,CAAC;AAGF,eAAO,MAAM,sBAAsB,UAAU,CAAC;AAG9C,eAAO,MAAM,wBAAwB,yBAAyB,CAAC;AAE/D,eAAO,MAAM,sBAAsB,QACiC,CAAC;AAErE,eAAO,MAAM,wBAAwB,QAC6B,CAAC;AAEnE,eAAO,MAAM,YAAY,QAAQ,CAAC;AAClC,eAAO,MAAM,eAAe,WAAW,CAAC;AACxC,eAAO,MAAM,6BAA6B,WAAW,CAAC;AACtD,eAAO,MAAM,UAAU,QAA0B,CAAC;AAClD,eAAO,MAAM,YAAY,OAAO,CAAC;AACjC,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAG3C,eAAO,MAAM,wBAAwB,iBACU,CAAC"}
@@ -0,0 +1,26 @@
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.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.NODE_MAJOR_VERSION = parseInt(process.versions.node.split('.')[0], 10);
11
+ exports.NODE_MINOR_VERSION = parseInt(process.versions.node.split('.')[1], 10);
12
+ // Can be overridden with cli option --out-dir
13
+ exports.DEFAULT_BUILD_DIR_NAME = 'build';
14
+ // Can be overridden with cli option --config
15
+ exports.DEFAULT_CONFIG_FILE_NAME = 'docusaurus.config.js';
16
+ exports.BABEL_CONFIG_FILE_NAME = process.env.DOCUSAURUS_BABEL_CONFIG_FILE_NAME || 'babel.config.js';
17
+ exports.GENERATED_FILES_DIR_NAME = process.env.DOCUSAURUS_GENERATED_FILES_DIR_NAME || '.docusaurus';
18
+ exports.SRC_DIR_NAME = 'src';
19
+ exports.STATIC_DIR_NAME = 'static';
20
+ exports.OUTPUT_STATIC_ASSETS_DIR_NAME = 'assets'; // files handled by webpack, hashed (can be cached aggressively)
21
+ exports.THEME_PATH = `${exports.SRC_DIR_NAME}/theme`;
22
+ exports.DEFAULT_PORT = 3000;
23
+ exports.DEFAULT_PLUGIN_ID = 'default';
24
+ // Temporary fix for https://github.com/facebook/docusaurus/issues/5493
25
+ exports.WEBPACK_URL_LOADER_LIMIT = process.env.WEBPACK_URL_LOADER_LIMIT ?? 10000;
26
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,kBAAkB,GAAG,QAAQ,CACxC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EACnC,EAAE,CACH,CAAC;AACW,QAAA,kBAAkB,GAAG,QAAQ,CACxC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EACnC,EAAE,CACH,CAAC;AAEF,8CAA8C;AACjC,QAAA,sBAAsB,GAAG,OAAO,CAAC;AAE9C,6CAA6C;AAChC,QAAA,wBAAwB,GAAG,sBAAsB,CAAC;AAElD,QAAA,sBAAsB,GACjC,OAAO,CAAC,GAAG,CAAC,iCAAiC,IAAI,iBAAiB,CAAC;AAExD,QAAA,wBAAwB,GACnC,OAAO,CAAC,GAAG,CAAC,mCAAmC,IAAI,aAAa,CAAC;AAEtD,QAAA,YAAY,GAAG,KAAK,CAAC;AACrB,QAAA,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,6BAA6B,GAAG,QAAQ,CAAC,CAAC,gEAAgE;AAC1G,QAAA,UAAU,GAAG,GAAG,oBAAY,QAAQ,CAAC;AACrC,QAAA,YAAY,GAAG,IAAI,CAAC;AACpB,QAAA,iBAAiB,GAAG,SAAS,CAAC;AAE3C,uEAAuE;AAC1D,QAAA,wBAAwB,GACnC,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,KAAK,CAAC"}
@@ -0,0 +1,24 @@
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 { ContentPaths } from './markdownLinks';
8
+ declare type DataFileParams = {
9
+ filePath: string;
10
+ contentPaths: ContentPaths;
11
+ };
12
+ export declare function getDataFilePath({ filePath, contentPaths, }: DataFileParams): Promise<string | undefined>;
13
+ /**
14
+ * Looks up for a data file in the content paths, returns the normalized object.
15
+ * Throws when validation fails; returns undefined when file not found
16
+ */
17
+ export declare function getDataFileData<T>(params: DataFileParams & {
18
+ fileType: string;
19
+ }, validate: (content: unknown) => T): Promise<T | undefined>;
20
+ export declare function getContentPathList(contentPaths: ContentPaths): string[];
21
+ export declare function findFolderContainingFile(folderPaths: string[], relativeFilePath: string): Promise<string | undefined>;
22
+ export declare function getFolderContainingFile(folderPaths: string[], relativeFilePath: string): Promise<string>;
23
+ export {};
24
+ //# sourceMappingURL=dataFileUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataFileUtils.d.ts","sourceRoot":"","sources":["../src/dataFileUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAGlD,aAAK,cAAc,GAAG;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;CAC5B,CAAC;AAEF,wBAAsB,eAAe,CAAC,EACpC,QAAQ,EACR,YAAY,GACb,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAU9C;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,CAAC,EACrC,MAAM,EAAE,cAAc,GAAG;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAC,EAC3C,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,CAAC,GAChC,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAcxB;AAGD,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,YAAY,GAAG,MAAM,EAAE,CAEvE;AAGD,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,MAAM,EAAE,EACrB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAI7B;AAED,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,MAAM,EAAE,EACrB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,MAAM,CAAC,CAcjB"}
@@ -0,0 +1,65 @@
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.getFolderContainingFile = exports.findFolderContainingFile = exports.getContentPathList = exports.getDataFileData = exports.getDataFilePath = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
+ const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
13
+ const path_1 = tslib_1.__importDefault(require("path"));
14
+ const index_1 = require("./index");
15
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
16
+ async function getDataFilePath({ filePath, contentPaths, }) {
17
+ // Loads a localized data file in priority
18
+ const contentPath = await findFolderContainingFile(getContentPathList(contentPaths), filePath);
19
+ if (contentPath) {
20
+ return path_1.default.join(contentPath, filePath);
21
+ }
22
+ return undefined;
23
+ }
24
+ exports.getDataFilePath = getDataFilePath;
25
+ /**
26
+ * Looks up for a data file in the content paths, returns the normalized object.
27
+ * Throws when validation fails; returns undefined when file not found
28
+ */
29
+ async function getDataFileData(params, validate) {
30
+ const filePath = await getDataFilePath(params);
31
+ if (!filePath) {
32
+ return undefined;
33
+ }
34
+ try {
35
+ const contentString = await fs_extra_1.default.readFile(filePath, { encoding: 'utf8' });
36
+ const unsafeContent = js_yaml_1.default.load(contentString);
37
+ return validate(unsafeContent);
38
+ }
39
+ catch (err) {
40
+ // TODO replace later by error cause, see https://v8.dev/features/error-cause
41
+ logger_1.default.error `The ${params.fileType} file at path=${filePath} looks invalid.`;
42
+ throw err;
43
+ }
44
+ }
45
+ exports.getDataFileData = getDataFileData;
46
+ // Order matters: we look in priority in localized folder
47
+ function getContentPathList(contentPaths) {
48
+ return [contentPaths.contentPathLocalized, contentPaths.contentPath];
49
+ }
50
+ exports.getContentPathList = getContentPathList;
51
+ // return the first folder path in which the file exists in
52
+ async function findFolderContainingFile(folderPaths, relativeFilePath) {
53
+ return (0, index_1.findAsyncSequential)(folderPaths, (folderPath) => fs_extra_1.default.pathExists(path_1.default.join(folderPath, relativeFilePath)));
54
+ }
55
+ exports.findFolderContainingFile = findFolderContainingFile;
56
+ async function getFolderContainingFile(folderPaths, relativeFilePath) {
57
+ const maybeFolderPath = await findFolderContainingFile(folderPaths, relativeFilePath);
58
+ // should never happen, as the source was read from the FS anyway...
59
+ if (!maybeFolderPath) {
60
+ throw new Error(`File "${relativeFilePath}" does not exist in any of these folders:\n- ${folderPaths.join('\n- ')}]`);
61
+ }
62
+ return maybeFolderPath;
63
+ }
64
+ exports.getFolderContainingFile = getFolderContainingFile;
65
+ //# sourceMappingURL=dataFileUtils.js.map
@@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;AACvE,CAAC;AAFD,gDAEC;AAED,2DAA2D;AACpD,KAAK,UAAU,wBAAwB,CAC5C,WAAqB,EACrB,gBAAwB;IAExB,OAAO,IAAA,2BAAmB,EAAC,WAAW,EAAE,CAAC,UAAU,EAAE,EAAE,CACrD,kBAAE,CAAC,UAAU,CAAC,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC,CACvD,CAAC;AACJ,CAAC;AAPD,4DAOC;AAEM,KAAK,UAAU,uBAAuB,CAC3C,WAAqB,EACrB,gBAAwB;IAExB,MAAM,eAAe,GAAG,MAAM,wBAAwB,CACpD,WAAW,EACX,gBAAgB,CACjB,CAAC;IACF,oEAAoE;IACpE,IAAI,CAAC,eAAe,EAAE;QACpB,MAAM,IAAI,KAAK,CACb,SAAS,gBAAgB,gDAAgD,WAAW,CAAC,IAAI,CACvF,MAAM,CACP,GAAG,CACL,CAAC;KACH;IACD,OAAO,eAAe,CAAC;AACzB,CAAC;AAjBD,0DAiBC"}
@@ -0,0 +1,23 @@
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
+ /// <reference types="node" />
8
+ export declare function generate(generatedFilesDir: string, file: string, content: string, skipCache?: boolean): Promise<void>;
9
+ /**
10
+ * Generate unique chunk name given a module path.
11
+ */
12
+ export declare function genChunkName(modulePath: string, prefix?: string, preferredName?: string, shortId?: boolean): string;
13
+ /**
14
+ * @param permalink The URL that the HTML file corresponds to, without base URL
15
+ * @param outDir Full path to the output directory
16
+ * @param trailingSlash The site config option. If provided, only one path will
17
+ * be read.
18
+ * @returns This returns a buffer, which you have to decode string yourself if
19
+ * needed. (Not always necessary since the output isn't for human consumption
20
+ * anyways, and most HTML manipulation libs accept buffers)
21
+ */
22
+ export declare function readOutputHTMLFile(permalink: string, outDir: string, trailingSlash: boolean | undefined): Promise<Buffer>;
23
+ //# sourceMappingURL=emitUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitUtils.d.ts","sourceRoot":"","sources":["../src/emitUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;AAUH,wBAAsB,QAAQ,CAC5B,iBAAiB,EAAE,MAAM,EACzB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,SAAS,GAAE,OAA+C,GACzD,OAAO,CAAC,IAAI,CAAC,CA2Bf;AAID;;GAEG;AACH,wBAAgB,YAAY,CAC1B,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,EACf,aAAa,CAAC,EAAE,MAAM,EACtB,OAAO,GAAE,OAA+C,GACvD,MAAM,CAiBR;AAED;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CACtC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,OAAO,GAAG,SAAS,GACjC,OAAO,CAAC,MAAM,CAAC,CAqBjB"}
@@ -0,0 +1,90 @@
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.readOutputHTMLFile = exports.genChunkName = exports.generate = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const path_1 = tslib_1.__importDefault(require("path"));
12
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
+ const crypto_1 = require("crypto");
14
+ const hashUtils_1 = require("./hashUtils");
15
+ const jsUtils_1 = require("./jsUtils");
16
+ const fileHash = new Map();
17
+ async function generate(generatedFilesDir, file, content, skipCache = process.env.NODE_ENV === 'production') {
18
+ const filepath = path_1.default.join(generatedFilesDir, file);
19
+ if (skipCache) {
20
+ await fs_extra_1.default.ensureDir(path_1.default.dirname(filepath));
21
+ await fs_extra_1.default.writeFile(filepath, content);
22
+ return;
23
+ }
24
+ let lastHash = fileHash.get(filepath);
25
+ // If file already exists but its not in runtime cache yet,
26
+ // we try to calculate the content hash and then compare
27
+ // This is to avoid unnecessary overwriting and we can reuse old file.
28
+ if (!lastHash && (await fs_extra_1.default.pathExists(filepath))) {
29
+ const lastContent = await fs_extra_1.default.readFile(filepath, 'utf8');
30
+ lastHash = (0, crypto_1.createHash)('md5').update(lastContent).digest('hex');
31
+ fileHash.set(filepath, lastHash);
32
+ }
33
+ const currentHash = (0, crypto_1.createHash)('md5').update(content).digest('hex');
34
+ if (lastHash !== currentHash) {
35
+ await fs_extra_1.default.ensureDir(path_1.default.dirname(filepath));
36
+ await fs_extra_1.default.writeFile(filepath, content);
37
+ fileHash.set(filepath, currentHash);
38
+ }
39
+ }
40
+ exports.generate = generate;
41
+ const chunkNameCache = new Map();
42
+ /**
43
+ * Generate unique chunk name given a module path.
44
+ */
45
+ function genChunkName(modulePath, prefix, preferredName, shortId = process.env.NODE_ENV === 'production') {
46
+ let chunkName = chunkNameCache.get(modulePath);
47
+ if (!chunkName) {
48
+ if (shortId) {
49
+ chunkName = (0, hashUtils_1.simpleHash)(modulePath, 8);
50
+ }
51
+ else {
52
+ let str = modulePath;
53
+ if (preferredName) {
54
+ const shortHash = (0, hashUtils_1.simpleHash)(modulePath, 3);
55
+ str = `${preferredName}${shortHash}`;
56
+ }
57
+ const name = str === '/' ? 'index' : (0, hashUtils_1.docuHash)(str);
58
+ chunkName = prefix ? `${prefix}---${name}` : name;
59
+ }
60
+ chunkNameCache.set(modulePath, chunkName);
61
+ }
62
+ return chunkName;
63
+ }
64
+ exports.genChunkName = genChunkName;
65
+ /**
66
+ * @param permalink The URL that the HTML file corresponds to, without base URL
67
+ * @param outDir Full path to the output directory
68
+ * @param trailingSlash The site config option. If provided, only one path will
69
+ * be read.
70
+ * @returns This returns a buffer, which you have to decode string yourself if
71
+ * needed. (Not always necessary since the output isn't for human consumption
72
+ * anyways, and most HTML manipulation libs accept buffers)
73
+ */
74
+ async function readOutputHTMLFile(permalink, outDir, trailingSlash) {
75
+ const withTrailingSlashPath = path_1.default.join(outDir, permalink, 'index.html');
76
+ const withoutTrailingSlashPath = path_1.default.join(outDir, `${permalink.replace(/\/$/, '')}.html`);
77
+ if (trailingSlash) {
78
+ return fs_extra_1.default.readFile(withTrailingSlashPath);
79
+ }
80
+ else if (trailingSlash === false) {
81
+ return fs_extra_1.default.readFile(withoutTrailingSlashPath);
82
+ }
83
+ const HTMLPath = await (0, jsUtils_1.findAsyncSequential)([withTrailingSlashPath, withoutTrailingSlashPath], fs_extra_1.default.pathExists);
84
+ if (!HTMLPath) {
85
+ throw new Error(`Expected output HTML file to be found at ${withTrailingSlashPath}`);
86
+ }
87
+ return fs_extra_1.default.readFile(HTMLPath);
88
+ }
89
+ exports.readOutputHTMLFile = readOutputHTMLFile;
90
+ //# sourceMappingURL=emitUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitUtils.js","sourceRoot":"","sources":["../src/emitUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wDAAwB;AACxB,gEAA0B;AAC1B,mCAAkC;AAClC,2CAAiD;AACjD,uCAA8C;AAE9C,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;AAEpC,KAAK,UAAU,QAAQ,CAC5B,iBAAyB,EACzB,IAAY,EACZ,OAAe,EACf,YAAqB,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;IAE1D,MAAM,QAAQ,GAAG,cAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC;IAEpD,IAAI,SAAS,EAAE;QACb,MAAM,kBAAE,CAAC,SAAS,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC3C,MAAM,kBAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACtC,OAAO;KACR;IAED,IAAI,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,C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;IACD,OAAO,kBAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC/B,CAAC;AAzBD,gDAyBC"}
@@ -0,0 +1,17 @@
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
+ export declare class GitNotFoundError extends Error {
8
+ }
9
+ export declare const getFileCommitDate: (file: string, { age, includeAuthor, }: {
10
+ age?: "oldest" | "newest" | undefined;
11
+ includeAuthor?: boolean | undefined;
12
+ }) => {
13
+ date: Date;
14
+ timestamp: number;
15
+ author?: string | undefined;
16
+ };
17
+ //# sourceMappingURL=gitUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gitUtils.d.ts","sourceRoot":"","sources":["../src/gitUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,qBAAa,gBAAiB,SAAQ,KAAK;CAAG;AAE9C,eAAO,MAAM,iBAAiB,SACtB,MAAM;;;;UASN,IAAI;eACC,MAAM;;CAqElB,CAAC"}
@@ -0,0 +1,63 @@
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.getFileCommitDate = exports.GitNotFoundError = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const path_1 = tslib_1.__importDefault(require("path"));
12
+ const shelljs_1 = tslib_1.__importDefault(require("shelljs"));
13
+ class GitNotFoundError extends Error {
14
+ }
15
+ exports.GitNotFoundError = GitNotFoundError;
16
+ const getFileCommitDate = (file, { age = 'oldest', includeAuthor = false, }) => {
17
+ if (!shelljs_1.default.which('git')) {
18
+ throw new GitNotFoundError(`Failed to retrieve git history for "${file}" because git is not installed.`);
19
+ }
20
+ if (!shelljs_1.default.test('-f', file)) {
21
+ throw new Error(`Failed to retrieve git history for "${file}" because the file does not exist.`);
22
+ }
23
+ const fileBasename = path_1.default.basename(file);
24
+ const fileDirname = path_1.default.dirname(file);
25
+ let formatArg = '--format=%ct';
26
+ if (includeAuthor) {
27
+ formatArg += ',%an';
28
+ }
29
+ let extraArgs = '--max-count=1';
30
+ if (age === 'oldest') {
31
+ // --follow is necessary to follow file renames
32
+ // --diff-filter=A ensures we only get the commit which (A)dded the file
33
+ extraArgs += ' --follow --diff-filter=A';
34
+ }
35
+ const result = shelljs_1.default.exec(`git log ${extraArgs} ${formatArg} -- "${fileBasename}"`, {
36
+ // cwd is important, see: https://github.com/facebook/docusaurus/pull/5048
37
+ cwd: fileDirname,
38
+ silent: true,
39
+ });
40
+ if (result.code !== 0) {
41
+ throw new Error(`Failed to retrieve the git history for file "${file}" with exit code ${result.code}: ${result.stderr}`);
42
+ }
43
+ let regex = /^(?<timestamp>\d+)$/;
44
+ if (includeAuthor) {
45
+ regex = /^(?<timestamp>\d+),(?<author>.+)$/;
46
+ }
47
+ const output = result.stdout.trim();
48
+ const match = output.match(regex);
49
+ if (!match ||
50
+ !match.groups ||
51
+ !match.groups.timestamp ||
52
+ (includeAuthor && !match.groups.author)) {
53
+ throw new Error(`Failed to retrieve the git history for file "${file}" with unexpected output: ${output}`);
54
+ }
55
+ const timestamp = Number(match.groups.timestamp);
56
+ const date = new Date(timestamp * 1000);
57
+ if (includeAuthor) {
58
+ return { date, timestamp, author: match.groups.author };
59
+ }
60
+ return { date, timestamp };
61
+ };
62
+ exports.getFileCommitDate = getFileCommitDate;
63
+ //# sourceMappingURL=gitUtils.js.map
@@ -0,0 +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;AAEvC,MAAM,iBAAiB,GAAG,CAC/B,IAAY,EACZ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,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAElC,IACE,CAAC,KAAK;QACN,CAAC,KAAK,CAAC,MAAM;QACb,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS;QACvB,CAAC,aAAa,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EACvC;QACA,MAAM,IAAI,KAAK,CACb,gDAAgD,IAAI,6BAA6B,MAAM,EAAE,CAC1F,CAAC;KACH;IAED,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACjD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IAExC,IAAI,aAAa,EAAE;QACjB,OAAO,EAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAC,CAAC;KACvD;IACD,OAAO,EAAC,IAAI,EAAE,SAAS,EAAC,CAAC;AAC3B,CAAC,CAAC;AAhFW,QAAA,iBAAiB,qBAgF5B"}
@@ -0,0 +1,12 @@
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
+ export { default as Globby } from 'globby';
8
+ export declare const GlobExcludeDefault: string[];
9
+ declare type Matcher = (str: string) => boolean;
10
+ export declare function createMatcher(patterns: string[]): Matcher;
11
+ export declare function createAbsoluteFilePathMatcher(patterns: string[], rootFolders: string[]): Matcher;
12
+ //# sourceMappingURL=globUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globUtils.d.ts","sourceRoot":"","sources":["../src/globUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,EAAC,OAAO,IAAI,MAAM,EAAC,MAAM,QAAQ,CAAC;AAIzC,eAAO,MAAM,kBAAkB,UAU9B,CAAC;AAEF,aAAK,OAAO,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;AAExC,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAKzD;AAMD,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,MAAM,EAAE,EAClB,WAAW,EAAE,MAAM,EAAE,GACpB,OAAO,CAmBT"}
@@ -0,0 +1,48 @@
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 micromatch_1 = tslib_1.__importDefault(require("micromatch")); // Note: Micromatch is used by Globby
13
+ const path_1 = tslib_1.__importDefault(require("path"));
14
+ var globby_1 = require("globby");
15
+ Object.defineProperty(exports, "Globby", { enumerable: true, get: function () { return tslib_1.__importDefault(globby_1).default; } });
16
+ // The default patterns we ignore when globbing
17
+ // using _ prefix for exclusion by convention
18
+ exports.GlobExcludeDefault = [
19
+ // Ignore files starting with _
20
+ '**/_*.{js,jsx,ts,tsx,md,mdx}',
21
+ // Ignore folders starting with _ (including folder content)
22
+ '**/_*/**',
23
+ // Ignore tests
24
+ '**/*.test.{js,jsx,ts,tsx}',
25
+ '**/__tests__/**',
26
+ ];
27
+ function createMatcher(patterns) {
28
+ const regexp = new RegExp(patterns.map((pattern) => micromatch_1.default.makeRe(pattern).source).join('|'));
29
+ return (str) => regexp.test(str);
30
+ }
31
+ exports.createMatcher = createMatcher;
32
+ // We use match patterns like '**/_*/**',
33
+ // This function permits to help to:
34
+ // Match /user/sebastien/website/docs/_partials/xyz.md
35
+ // Ignore /user/_sebastien/website/docs/partials/xyz.md
36
+ function createAbsoluteFilePathMatcher(patterns, rootFolders) {
37
+ const matcher = createMatcher(patterns);
38
+ function getRelativeFilePath(absoluteFilePath) {
39
+ const rootFolder = rootFolders.find((folderPath) => absoluteFilePath.startsWith(folderPath));
40
+ if (!rootFolder) {
41
+ throw new Error(`createAbsoluteFilePathMatcher unexpected error, absoluteFilePath=${absoluteFilePath} was not contained in any of the root folders ${JSON.stringify(rootFolders)}`);
42
+ }
43
+ return path_1.default.relative(rootFolder, absoluteFilePath);
44
+ }
45
+ return (absoluteFilePath) => matcher(getRelativeFilePath(absoluteFilePath));
46
+ }
47
+ exports.createAbsoluteFilePathMatcher = createAbsoluteFilePathMatcher;
48
+ //# 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,oEAAoC,CAAC,qCAAqC;AAC1E,wDAAwB;AAExB,iCAAyC;AAAjC,yHAAA,OAAO,OAAU;AAEzB,+CAA+C;AAC/C,6CAA6C;AAChC,QAAA,kBAAkB,GAAG;IAChC,+BAA+B;IAC/B,8BAA8B;IAE9B,4DAA4D;IAC5D,UAAU;IAEV,eAAe;IACf,2BAA2B;IAC3B,iBAAiB;CAClB,CAAC;AAIF,SAAgB,aAAa,CAAC,QAAkB;IAC9C,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;AALD,sCAKC;AAED,yCAAyC;AACzC,oCAAoC;AACpC,sDAAsD;AACtD,uDAAuD;AACvD,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,iDAAiD,IAAI,CAAC,SAAS,CACjJ,WAAW,CACZ,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"}
@@ -13,3 +13,4 @@ export declare function simpleHash(str: string, length: number): string;
13
13
  * filename per OS. Avoids ERRNAMETOOLONG error.
14
14
  */
15
15
  export declare function docuHash(str: string): string;
16
+ //# 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,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAE9D;AAGD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAU5C"}
package/lib/hashUtils.js CHANGED
@@ -7,11 +7,12 @@
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");
13
14
  function md5Hash(str) {
14
- return crypto_1.createHash('md5').update(str).digest('hex');
15
+ return (0, crypto_1.createHash)('md5').update(str).digest('hex');
15
16
  }
16
17
  exports.md5Hash = md5Hash;
17
18
  function simpleHash(str, length) {
@@ -30,10 +31,11 @@ function docuHash(str) {
30
31
  return 'index';
31
32
  }
32
33
  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}`;
34
+ const parsedPath = `${lodash_1.default.kebabCase(str)}-${shortHash}`;
35
+ if ((0, pathUtils_1.isNameTooLong)(parsedPath)) {
36
+ return `${(0, pathUtils_1.shortName)(lodash_1.default.kebabCase(str))}-${shortHash}`;
36
37
  }
37
38
  return parsedPath;
38
39
  }
39
40
  exports.docuHash = docuHash;
41
+ //# 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,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,SAAgB,UAAU,CAAC,GAAW,EAAE,MAAc;IACpD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AACxC,CAAC;AAFD,gCAEC;AAED,+DAA+D;AAC/D;;;;;GAKG;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,17 @@
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 } from '@docusaurus/types';
8
+ export declare function mergeTranslations(contents: TranslationFileContent[]): TranslationFileContent;
9
+ export declare function updateTranslationFileMessages(translationFile: TranslationFile, updateMessage: (message: string) => string): TranslationFile;
10
+ export declare function getPluginI18nPath({ siteDir, locale, pluginName, pluginId, subPaths, }: {
11
+ siteDir: string;
12
+ locale: string;
13
+ pluginName: string;
14
+ pluginId?: string | undefined;
15
+ subPaths?: string[];
16
+ }): string;
17
+ //# sourceMappingURL=i18nUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18nUtils.d.ts","sourceRoot":"","sources":["../src/i18nUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAC,sBAAsB,EAAE,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAG/E,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,sBAAsB,EAAE,GACjC,sBAAsB,CAExB;AAID,wBAAgB,6BAA6B,CAC3C,eAAe,EAAE,eAAe,EAChC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,GACzC,eAAe,CAQjB;AAED,wBAAgB,iBAAiB,CAAC,EAChC,OAAO,EACP,MAAM,EACN,UAAU,EACV,QAA4B,EAC5B,QAAa,GACd,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,GAAG,MAAM,CAYT"}
@@ -0,0 +1,40 @@
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.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
+ function mergeTranslations(contents) {
15
+ return contents.reduce((acc, content) => ({ ...acc, ...content }), {});
16
+ }
17
+ exports.mergeTranslations = mergeTranslations;
18
+ // Useful to update all the messages of a translation file
19
+ // Used in tests to simulate translations
20
+ function updateTranslationFileMessages(translationFile, updateMessage) {
21
+ return {
22
+ ...translationFile,
23
+ content: lodash_1.default.mapValues(translationFile.content, (translation) => ({
24
+ ...translation,
25
+ message: updateMessage(translation.message),
26
+ })),
27
+ };
28
+ }
29
+ exports.updateTranslationFileMessages = updateTranslationFileMessages;
30
+ function getPluginI18nPath({ siteDir, locale, pluginName, pluginId = constants_1.DEFAULT_PLUGIN_ID, subPaths = [], }) {
31
+ return path_1.default.join(siteDir, 'i18n',
32
+ // namespace first by locale: convenient to work in a single folder for a
33
+ // translator
34
+ locale,
35
+ // Make it convenient to use for single-instance
36
+ // ie: return "docs", not "docs-default" nor "docs/default"
37
+ `${pluginName}${pluginId === constants_1.DEFAULT_PLUGIN_ID ? '' : `-${pluginId}`}`, ...subPaths);
38
+ }
39
+ exports.getPluginI18nPath = getPluginI18nPath;
40
+ //# 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;AAEvB,2CAA8C;AAE9C,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,0DAA0D;AAC1D,yCAAyC;AACzC,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,SAAgB,iBAAiB,CAAC,EAChC,OAAO,EACP,MAAM,EACN,UAAU,EACV,QAAQ,GAAG,6BAAiB,EAC5B,QAAQ,GAAG,EAAE,GAOd;IACC,OAAO,cAAI,CAAC,IAAI,CACd,OAAO,EACP,MAAM;IACN,yEAAyE;IACzE,aAAa;IACb,MAAM;IACN,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;AAxBD,8CAwBC"}