@docusaurus/utils 2.0.0-beta.12faed89d → 2.0.0-beta.14
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 +20 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +27 -0
- package/lib/constants.js.map +1 -0
- package/lib/escapePath.d.ts +1 -0
- package/lib/escapePath.d.ts.map +1 -0
- package/lib/escapePath.js +1 -0
- package/lib/escapePath.js.map +1 -0
- package/lib/globUtils.d.ts +12 -0
- package/lib/globUtils.d.ts.map +1 -0
- package/lib/globUtils.js +48 -0
- package/lib/globUtils.js.map +1 -0
- package/lib/hashUtils.d.ts +1 -0
- package/lib/hashUtils.d.ts.map +1 -0
- package/lib/hashUtils.js +5 -4
- package/lib/hashUtils.js.map +1 -0
- package/lib/index.d.ts +11 -6
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +43 -95
- package/lib/index.js.map +1 -0
- package/lib/markdownLinks.d.ts +1 -0
- package/lib/markdownLinks.d.ts.map +1 -0
- package/lib/markdownLinks.js +20 -6
- package/lib/markdownLinks.js.map +1 -0
- package/lib/markdownParser.d.ts +1 -0
- package/lib/markdownParser.d.ts.map +1 -0
- package/lib/markdownParser.js +17 -8
- package/lib/markdownParser.js.map +1 -0
- package/lib/mdxUtils.d.ts +17 -0
- package/lib/mdxUtils.d.ts.map +1 -0
- package/lib/mdxUtils.js +31 -0
- package/lib/mdxUtils.js.map +1 -0
- package/lib/normalizeUrl.d.ts +8 -0
- package/lib/normalizeUrl.d.ts.map +1 -0
- package/lib/normalizeUrl.js +67 -0
- package/lib/normalizeUrl.js.map +1 -0
- package/lib/pathUtils.d.ts +1 -0
- package/lib/pathUtils.d.ts.map +1 -0
- package/lib/pathUtils.js +4 -5
- package/lib/pathUtils.js.map +1 -0
- package/lib/posixPath.d.ts +1 -0
- package/lib/posixPath.d.ts.map +1 -0
- package/lib/posixPath.js +1 -0
- package/lib/posixPath.js.map +1 -0
- package/lib/slugger.d.ts +14 -0
- package/lib/slugger.d.ts.map +1 -0
- package/lib/slugger.js +19 -0
- package/lib/slugger.js.map +1 -0
- package/lib/tags.d.ts +19 -0
- package/lib/tags.d.ts.map +1 -0
- package/lib/tags.js +73 -0
- package/lib/tags.js.map +1 -0
- package/lib/webpackUtils.d.ts +30 -0
- package/lib/webpackUtils.d.ts.map +1 -0
- package/lib/webpackUtils.js +110 -0
- package/lib/webpackUtils.js.map +1 -0
- package/package.json +25 -8
- package/src/constants.ts +38 -0
- package/src/deps.d.ts +14 -0
- package/src/globUtils.ts +63 -0
- package/src/index.ts +25 -95
- package/src/markdownLinks.ts +19 -8
- package/src/markdownParser.ts +21 -16
- package/src/mdxUtils.ts +32 -0
- package/src/normalizeUrl.ts +80 -0
- package/src/pathUtils.ts +2 -3
- package/src/slugger.ts +24 -0
- package/src/tags.ts +100 -0
- package/src/webpackUtils.ts +144 -0
- package/lib/.tsbuildinfo +0 -1
- package/lib/codeTranslationsUtils.d.ts +0 -11
- package/lib/codeTranslationsUtils.js +0 -50
- 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/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"}
|
package/lib/constants.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
var _a;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
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;
|
|
11
|
+
exports.NODE_MAJOR_VERSION = parseInt(process.versions.node.split('.')[0], 10);
|
|
12
|
+
exports.NODE_MINOR_VERSION = parseInt(process.versions.node.split('.')[1], 10);
|
|
13
|
+
// Can be overridden with cli option --out-dir
|
|
14
|
+
exports.DEFAULT_BUILD_DIR_NAME = 'build';
|
|
15
|
+
// Can be overridden with cli option --config
|
|
16
|
+
exports.DEFAULT_CONFIG_FILE_NAME = 'docusaurus.config.js';
|
|
17
|
+
exports.BABEL_CONFIG_FILE_NAME = process.env.DOCUSAURUS_BABEL_CONFIG_FILE_NAME || 'babel.config.js';
|
|
18
|
+
exports.GENERATED_FILES_DIR_NAME = process.env.DOCUSAURUS_GENERATED_FILES_DIR_NAME || '.docusaurus';
|
|
19
|
+
exports.SRC_DIR_NAME = 'src';
|
|
20
|
+
exports.STATIC_DIR_NAME = 'static';
|
|
21
|
+
exports.OUTPUT_STATIC_ASSETS_DIR_NAME = 'assets'; // files handled by webpack, hashed (can be cached aggressively)
|
|
22
|
+
exports.THEME_PATH = `${exports.SRC_DIR_NAME}/theme`;
|
|
23
|
+
exports.DEFAULT_PORT = 3000;
|
|
24
|
+
exports.DEFAULT_PLUGIN_ID = 'default';
|
|
25
|
+
// Temporary fix for https://github.com/facebook/docusaurus/issues/5493
|
|
26
|
+
exports.WEBPACK_URL_LOADER_LIMIT = (_a = process.env.WEBPACK_URL_LOADER_LIMIT) !== null && _a !== void 0 ? _a : 10000;
|
|
27
|
+
//# 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,MAAA,OAAO,CAAC,GAAG,CAAC,wBAAwB,mCAAI,KAAK,CAAC"}
|
package/lib/escapePath.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escapePath.d.ts","sourceRoot":"","sources":["../src/escapePath.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK9C"}
|
package/lib/escapePath.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escapePath.js","sourceRoot":"","sources":["../src/escapePath.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH;;;;;;;;;GASG;AACH,SAAgB,UAAU,CAAC,GAAW;IACpC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAEpC,uCAAuC;IACvC,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAClD,CAAC;AALD,gCAKC"}
|
|
@@ -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;AAIH,OAAO,EAAC,OAAO,IAAI,MAAM,EAAC,MAAM,QAAQ,CAAC;AAMzC,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"}
|
package/lib/globUtils.js
ADDED
|
@@ -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
|
+
var globby_1 = require("globby");
|
|
13
|
+
Object.defineProperty(exports, "Globby", { enumerable: true, get: function () { return (0, tslib_1.__importDefault)(globby_1).default; } });
|
|
14
|
+
const micromatch_1 = (0, tslib_1.__importDefault)(require("micromatch")); // Note: Micromatch is used by Globby
|
|
15
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
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,iCAAyC;AAAjC,8HAAA,OAAO,OAAU;AACzB,yEAAoC,CAAC,qCAAqC;AAC1E,6DAAwB;AAExB,+CAA+C;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,"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
|
@@ -11,7 +11,7 @@ const crypto_1 = require("crypto");
|
|
|
11
11
|
const lodash_1 = require("lodash");
|
|
12
12
|
const pathUtils_1 = require("./pathUtils");
|
|
13
13
|
function md5Hash(str) {
|
|
14
|
-
return crypto_1.createHash('md5').update(str).digest('hex');
|
|
14
|
+
return (0, crypto_1.createHash)('md5').update(str).digest('hex');
|
|
15
15
|
}
|
|
16
16
|
exports.md5Hash = md5Hash;
|
|
17
17
|
function simpleHash(str, length) {
|
|
@@ -30,10 +30,11 @@ function docuHash(str) {
|
|
|
30
30
|
return 'index';
|
|
31
31
|
}
|
|
32
32
|
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}`;
|
|
33
|
+
const parsedPath = `${(0, lodash_1.kebabCase)(str)}-${shortHash}`;
|
|
34
|
+
if ((0, pathUtils_1.isNameTooLong)(parsedPath)) {
|
|
35
|
+
return `${(0, pathUtils_1.shortName)((0, lodash_1.kebabCase)(str))}-${shortHash}`;
|
|
36
36
|
}
|
|
37
37
|
return parsedPath;
|
|
38
38
|
}
|
|
39
39
|
exports.docuHash = docuHash;
|
|
40
|
+
//# 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,mCAAiC;AACjC,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,IAAA,kBAAS,EAAC,GAAG,CAAC,IAAI,SAAS,EAAE,CAAC;IACpD,IAAI,IAAA,yBAAa,EAAC,UAAU,CAAC,EAAE;QAC7B,OAAO,GAAG,IAAA,qBAAS,EAAC,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,SAAS,EAAE,CAAC;KACpD;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAVD,4BAUC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -6,12 +6,18 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { ReportingSeverity, TranslationFileContent, TranslationFile } from '@docusaurus/types';
|
|
8
8
|
import { posixPath as posixPathImport } from './posixPath';
|
|
9
|
+
export * from './constants';
|
|
10
|
+
export * from './mdxUtils';
|
|
11
|
+
export * from './normalizeUrl';
|
|
12
|
+
export * from './tags';
|
|
9
13
|
export declare const posixPath: typeof posixPathImport;
|
|
10
|
-
export * from './codeTranslationsUtils';
|
|
11
14
|
export * from './markdownParser';
|
|
12
15
|
export * from './markdownLinks';
|
|
13
16
|
export * from './escapePath';
|
|
17
|
+
export * from './slugger';
|
|
14
18
|
export { md5Hash, simpleHash, docuHash } from './hashUtils';
|
|
19
|
+
export { Globby, GlobExcludeDefault, createMatcher, createAbsoluteFilePathMatcher, } from './globUtils';
|
|
20
|
+
export * from './webpackUtils';
|
|
15
21
|
export declare function generate(generatedFilesDir: string, file: string, content: string, skipCache?: boolean): Promise<void>;
|
|
16
22
|
export declare function objectWithKeySorted<T>(obj: Record<string, T>): Record<string, T>;
|
|
17
23
|
/**
|
|
@@ -40,7 +46,6 @@ export declare function idx(target: any, keyPaths?: string | (string | number)[]
|
|
|
40
46
|
* Given a filepath and dirpath, get the first directory.
|
|
41
47
|
*/
|
|
42
48
|
export declare function getSubFolder(file: string, refDir: string): string | null;
|
|
43
|
-
export declare function normalizeUrl(rawUrls: string[]): string;
|
|
44
49
|
/**
|
|
45
50
|
* Alias filepath relative to site directory, very useful so that we
|
|
46
51
|
* don't expose user's site structure.
|
|
@@ -56,19 +61,18 @@ export declare function addTrailingSlash(str: string): string;
|
|
|
56
61
|
export declare function removeTrailingSlash(str: string): string;
|
|
57
62
|
export declare function removeSuffix(str: string, suffix: string): string;
|
|
58
63
|
export declare function removePrefix(str: string, prefix: string): string;
|
|
59
|
-
export declare function getElementsAround<T
|
|
64
|
+
export declare function getElementsAround<T>(array: T[], aroundIndex: number): {
|
|
60
65
|
next: T | undefined;
|
|
61
66
|
previous: T | undefined;
|
|
62
67
|
};
|
|
63
|
-
export declare function getPluginI18nPath({ siteDir, locale, pluginName, pluginId,
|
|
64
|
-
subPaths, }: {
|
|
68
|
+
export declare function getPluginI18nPath({ siteDir, locale, pluginName, pluginId, subPaths, }: {
|
|
65
69
|
siteDir: string;
|
|
66
70
|
locale: string;
|
|
67
71
|
pluginName: string;
|
|
68
72
|
pluginId?: string | undefined;
|
|
69
73
|
subPaths?: string[];
|
|
70
74
|
}): string;
|
|
71
|
-
export declare function mapAsyncSequencial<T
|
|
75
|
+
export declare function mapAsyncSequencial<T, R>(array: T[], action: (t: T) => Promise<R>): Promise<R[]>;
|
|
72
76
|
export declare function findAsyncSequential<T>(array: T[], predicate: (t: T) => Promise<boolean>): Promise<T | undefined>;
|
|
73
77
|
export declare function findFolderContainingFile(folderPaths: string[], relativeFilePath: string): Promise<string | undefined>;
|
|
74
78
|
export declare function getFolderContainingFile(folderPaths: string[], relativeFilePath: string): Promise<string>;
|
|
@@ -80,3 +84,4 @@ export declare function parseMarkdownHeadingId(heading: string): {
|
|
|
80
84
|
text: string;
|
|
81
85
|
id?: string;
|
|
82
86
|
};
|
|
87
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,eAAe,EAChB,MAAM,mBAAmB,CAAC;AAI3B,OAAO,EAAC,SAAS,IAAI,eAAe,EAAC,MAAM,aAAa,CAAC;AAKzD,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AAEvB,eAAO,MAAM,SAAS,wBAAkB,CAAC;AAEzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,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,cAAc,gBAAgB,CAAC;AAG/B,wBAAsB,QAAQ,CAC5B,iBAAiB,EAAE,MAAM,EACzB,IAAI,EAAE,MAAM,E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C,CAQd;AAED,wBAAsB,mBAAmB,CAAC,CAAC,EACzC,KAAK,EAAE,CAAC,EAAE,EACV,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,GACpC,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAQxB;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;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,iBAAiB,EAAE,iBAAiB,GACnC,IAAI,CAoBN;AAED,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,sBAAsB,EAAE,GACjC,sBAAsB,CAExB;AAED,wBAAgB,oBAAoB,CAClC,aAAa,EAAE,MAAM,GACpB,MAAM,GAAG,SAAS,CAUpB;AAID,wBAAgB,6BAA6B,CAC3C,eAAe,EAAE,eAAe,EAChC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,GACzC,eAAe,CAQjB;AAID,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAWA"}
|
package/lib/index.js
CHANGED
|
@@ -6,28 +6,39 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.parseMarkdownHeadingId = exports.updateTranslationFileMessages = exports.getSwizzledComponent = exports.mergeTranslations = exports.reportMessage = exports.getFolderContainingFile = exports.findFolderContainingFile = exports.findAsyncSequential = exports.mapAsyncSequencial = exports.getPluginI18nPath = exports.getElementsAround = exports.removePrefix = exports.removeSuffix = exports.removeTrailingSlash = exports.addTrailingSlash = exports.addTrailingPathSeparator = exports.addLeadingSlash = exports.resolvePathname = exports.isValidPathname = exports.getEditUrl = exports.aliasedSitePath = exports.
|
|
9
|
+
exports.parseMarkdownHeadingId = exports.updateTranslationFileMessages = exports.getSwizzledComponent = exports.mergeTranslations = exports.reportMessage = exports.getFolderContainingFile = exports.findFolderContainingFile = exports.findAsyncSequential = exports.mapAsyncSequencial = exports.getPluginI18nPath = exports.getElementsAround = exports.removePrefix = exports.removeSuffix = exports.removeTrailingSlash = exports.addTrailingSlash = exports.addTrailingPathSeparator = exports.addLeadingSlash = exports.resolvePathname = exports.isValidPathname = exports.getEditUrl = exports.aliasedSitePath = exports.getSubFolder = exports.idx = exports.genChunkName = exports.toMessageRelativeFilePath = exports.genComponentName = exports.upperFirst = exports.encodePath = exports.fileToPath = exports.objectWithKeySorted = exports.generate = exports.createAbsoluteFilePathMatcher = exports.createMatcher = exports.GlobExcludeDefault = exports.Globby = exports.docuHash = exports.simpleHash = exports.md5Hash = exports.posixPath = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const
|
|
12
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
11
|
+
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
12
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
13
13
|
const crypto_1 = require("crypto");
|
|
14
14
|
const lodash_1 = require("lodash");
|
|
15
|
-
const escape_string_regexp_1 = tslib_1.__importDefault(require("escape-string-regexp"));
|
|
16
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
15
|
+
const escape_string_regexp_1 = (0, tslib_1.__importDefault)(require("escape-string-regexp"));
|
|
16
|
+
const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
|
|
17
17
|
const url_1 = require("url");
|
|
18
|
-
|
|
19
|
-
const resolve_pathname_1 = tslib_1.__importDefault(require("resolve-pathname"));
|
|
18
|
+
const resolve_pathname_1 = (0, tslib_1.__importDefault)(require("resolve-pathname"));
|
|
20
19
|
const posixPath_1 = require("./posixPath");
|
|
21
20
|
const hashUtils_1 = require("./hashUtils");
|
|
21
|
+
const normalizeUrl_1 = require("./normalizeUrl");
|
|
22
|
+
const constants_1 = require("./constants");
|
|
23
|
+
(0, tslib_1.__exportStar)(require("./constants"), exports);
|
|
24
|
+
(0, tslib_1.__exportStar)(require("./mdxUtils"), exports);
|
|
25
|
+
(0, tslib_1.__exportStar)(require("./normalizeUrl"), exports);
|
|
26
|
+
(0, tslib_1.__exportStar)(require("./tags"), exports);
|
|
22
27
|
exports.posixPath = posixPath_1.posixPath;
|
|
23
|
-
tslib_1.__exportStar(require("./
|
|
24
|
-
tslib_1.__exportStar(require("./
|
|
25
|
-
tslib_1.__exportStar(require("./
|
|
26
|
-
tslib_1.__exportStar(require("./
|
|
28
|
+
(0, tslib_1.__exportStar)(require("./markdownParser"), exports);
|
|
29
|
+
(0, tslib_1.__exportStar)(require("./markdownLinks"), exports);
|
|
30
|
+
(0, tslib_1.__exportStar)(require("./escapePath"), exports);
|
|
31
|
+
(0, tslib_1.__exportStar)(require("./slugger"), exports);
|
|
27
32
|
var hashUtils_2 = require("./hashUtils");
|
|
28
33
|
Object.defineProperty(exports, "md5Hash", { enumerable: true, get: function () { return hashUtils_2.md5Hash; } });
|
|
29
34
|
Object.defineProperty(exports, "simpleHash", { enumerable: true, get: function () { return hashUtils_2.simpleHash; } });
|
|
30
35
|
Object.defineProperty(exports, "docuHash", { enumerable: true, get: function () { return hashUtils_2.docuHash; } });
|
|
36
|
+
var globUtils_1 = require("./globUtils");
|
|
37
|
+
Object.defineProperty(exports, "Globby", { enumerable: true, get: function () { return globUtils_1.Globby; } });
|
|
38
|
+
Object.defineProperty(exports, "GlobExcludeDefault", { enumerable: true, get: function () { return globUtils_1.GlobExcludeDefault; } });
|
|
39
|
+
Object.defineProperty(exports, "createMatcher", { enumerable: true, get: function () { return globUtils_1.createMatcher; } });
|
|
40
|
+
Object.defineProperty(exports, "createAbsoluteFilePathMatcher", { enumerable: true, get: function () { return globUtils_1.createAbsoluteFilePathMatcher; } });
|
|
41
|
+
(0, tslib_1.__exportStar)(require("./webpackUtils"), exports);
|
|
31
42
|
const fileHash = new Map();
|
|
32
43
|
async function generate(generatedFilesDir, file, content, skipCache = process.env.NODE_ENV === 'production') {
|
|
33
44
|
const filepath = path_1.default.join(generatedFilesDir, file);
|
|
@@ -42,10 +53,10 @@ async function generate(generatedFilesDir, file, content, skipCache = process.en
|
|
|
42
53
|
// This is to avoid unnecessary overwriting and we can reuse old file.
|
|
43
54
|
if (!lastHash && fs_extra_1.default.existsSync(filepath)) {
|
|
44
55
|
const lastContent = await fs_extra_1.default.readFile(filepath, 'utf8');
|
|
45
|
-
lastHash = crypto_1.createHash('md5').update(lastContent).digest('hex');
|
|
56
|
+
lastHash = (0, crypto_1.createHash)('md5').update(lastContent).digest('hex');
|
|
46
57
|
fileHash.set(filepath, lastHash);
|
|
47
58
|
}
|
|
48
|
-
const currentHash = crypto_1.createHash('md5').update(content).digest('hex');
|
|
59
|
+
const currentHash = (0, crypto_1.createHash)('md5').update(content).digest('hex');
|
|
49
60
|
if (lastHash !== currentHash) {
|
|
50
61
|
await fs_extra_1.default.ensureDir(path_1.default.dirname(filepath));
|
|
51
62
|
await fs_extra_1.default.writeFile(filepath, content);
|
|
@@ -99,8 +110,8 @@ function genComponentName(pagePath) {
|
|
|
99
110
|
if (pagePath === '/') {
|
|
100
111
|
return 'index';
|
|
101
112
|
}
|
|
102
|
-
const pageHash = hashUtils_1.docuHash(pagePath);
|
|
103
|
-
return upperFirst(lodash_1.camelCase(pageHash));
|
|
113
|
+
const pageHash = (0, hashUtils_1.docuHash)(pagePath);
|
|
114
|
+
return upperFirst((0, lodash_1.camelCase)(pageHash));
|
|
104
115
|
}
|
|
105
116
|
exports.genComponentName = genComponentName;
|
|
106
117
|
// When you want to display a path in a message/warning/error,
|
|
@@ -111,7 +122,7 @@ exports.genComponentName = genComponentName;
|
|
|
111
122
|
// on both Unix/Windows
|
|
112
123
|
// For Windows users this is not perfect (as they see / instead of \) but it's probably good enough
|
|
113
124
|
function toMessageRelativeFilePath(filePath) {
|
|
114
|
-
return exports.posixPath(path_1.default.relative(process.cwd(), filePath));
|
|
125
|
+
return (0, exports.posixPath)(path_1.default.relative(process.cwd(), filePath));
|
|
115
126
|
}
|
|
116
127
|
exports.toMessageRelativeFilePath = toMessageRelativeFilePath;
|
|
117
128
|
const chunkNameCache = new Map();
|
|
@@ -122,15 +133,15 @@ function genChunkName(modulePath, prefix, preferredName, shortId = process.env.N
|
|
|
122
133
|
let chunkName = chunkNameCache.get(modulePath);
|
|
123
134
|
if (!chunkName) {
|
|
124
135
|
if (shortId) {
|
|
125
|
-
chunkName = hashUtils_1.simpleHash(modulePath, 8);
|
|
136
|
+
chunkName = (0, hashUtils_1.simpleHash)(modulePath, 8);
|
|
126
137
|
}
|
|
127
138
|
else {
|
|
128
139
|
let str = modulePath;
|
|
129
140
|
if (preferredName) {
|
|
130
|
-
const shortHash = hashUtils_1.simpleHash(modulePath, 3);
|
|
141
|
+
const shortHash = (0, hashUtils_1.simpleHash)(modulePath, 3);
|
|
131
142
|
str = `${preferredName}${shortHash}`;
|
|
132
143
|
}
|
|
133
|
-
const name = str === '/' ? 'index' : hashUtils_1.docuHash(str);
|
|
144
|
+
const name = str === '/' ? 'index' : (0, hashUtils_1.docuHash)(str);
|
|
134
145
|
chunkName = prefix ? `${prefix}---${name}` : name;
|
|
135
146
|
}
|
|
136
147
|
chunkNameCache.set(modulePath, chunkName);
|
|
@@ -152,77 +163,20 @@ exports.idx = idx;
|
|
|
152
163
|
* Given a filepath and dirpath, get the first directory.
|
|
153
164
|
*/
|
|
154
165
|
function getSubFolder(file, refDir) {
|
|
155
|
-
const separator = escape_string_regexp_1.default(path_1.default.sep);
|
|
156
|
-
const baseDir = escape_string_regexp_1.default(path_1.default.basename(refDir));
|
|
166
|
+
const separator = (0, escape_string_regexp_1.default)(path_1.default.sep);
|
|
167
|
+
const baseDir = (0, escape_string_regexp_1.default)(path_1.default.basename(refDir));
|
|
157
168
|
const regexSubFolder = new RegExp(`${baseDir}${separator}(.*?)${separator}.*`);
|
|
158
169
|
const match = regexSubFolder.exec(file);
|
|
159
170
|
return match && match[1];
|
|
160
171
|
}
|
|
161
172
|
exports.getSubFolder = getSubFolder;
|
|
162
|
-
function normalizeUrl(rawUrls) {
|
|
163
|
-
const urls = [...rawUrls];
|
|
164
|
-
const resultArray = [];
|
|
165
|
-
let hasStartingSlash = false;
|
|
166
|
-
let hasEndingSlash = false;
|
|
167
|
-
// If the first part is a plain protocol, we combine it with the next part.
|
|
168
|
-
if (urls[0].match(/^[^/:]+:\/*$/) && urls.length > 1) {
|
|
169
|
-
const first = urls.shift();
|
|
170
|
-
urls[0] = first + urls[0];
|
|
171
|
-
}
|
|
172
|
-
// There must be two or three slashes in the file protocol,
|
|
173
|
-
// two slashes in anything else.
|
|
174
|
-
const replacement = urls[0].match(/^file:\/\/\//) ? '$1:///' : '$1://';
|
|
175
|
-
urls[0] = urls[0].replace(/^([^/:]+):\/*/, replacement);
|
|
176
|
-
// eslint-disable-next-line
|
|
177
|
-
for (let i = 0; i < urls.length; i++) {
|
|
178
|
-
let component = urls[i];
|
|
179
|
-
if (typeof component !== 'string') {
|
|
180
|
-
throw new TypeError(`Url must be a string. Received ${typeof component}`);
|
|
181
|
-
}
|
|
182
|
-
if (component === '') {
|
|
183
|
-
if (i === urls.length - 1 && hasEndingSlash) {
|
|
184
|
-
resultArray.push('/');
|
|
185
|
-
}
|
|
186
|
-
// eslint-disable-next-line
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
if (component !== '/') {
|
|
190
|
-
if (i > 0) {
|
|
191
|
-
// Removing the starting slashes for each component but the first.
|
|
192
|
-
component = component.replace(/^[/]+/,
|
|
193
|
-
// Special case where the first element of rawUrls is empty ["", "/hello"] => /hello
|
|
194
|
-
component[0] === '/' && !hasStartingSlash ? '/' : '');
|
|
195
|
-
}
|
|
196
|
-
hasEndingSlash = component[component.length - 1] === '/';
|
|
197
|
-
// Removing the ending slashes for each component but the last.
|
|
198
|
-
// For the last component we will combine multiple slashes to a single one.
|
|
199
|
-
component = component.replace(/[/]+$/, i < urls.length - 1 ? '' : '/');
|
|
200
|
-
}
|
|
201
|
-
hasStartingSlash = true;
|
|
202
|
-
resultArray.push(component);
|
|
203
|
-
}
|
|
204
|
-
let str = resultArray.join('/');
|
|
205
|
-
// Each input component is now separated by a single slash
|
|
206
|
-
// except the possible first plain protocol part.
|
|
207
|
-
// Remove trailing slash before parameters or hash.
|
|
208
|
-
str = str.replace(/\/(\?|&|#[^!])/g, '$1');
|
|
209
|
-
// Replace ? in parameters with &.
|
|
210
|
-
const parts = str.split('?');
|
|
211
|
-
str = parts.shift() + (parts.length > 0 ? '?' : '') + parts.join('&');
|
|
212
|
-
// Dedupe forward slashes in the entire path, avoiding protocol slashes.
|
|
213
|
-
str = str.replace(/([^:]\/)\/+/g, '$1');
|
|
214
|
-
// Dedupe forward slashes at the beginning of the path.
|
|
215
|
-
str = str.replace(/^\/+/g, '/');
|
|
216
|
-
return str;
|
|
217
|
-
}
|
|
218
|
-
exports.normalizeUrl = normalizeUrl;
|
|
219
173
|
/**
|
|
220
174
|
* Alias filepath relative to site directory, very useful so that we
|
|
221
175
|
* don't expose user's site structure.
|
|
222
176
|
* Example: some/path/to/website/docs/foo.md -> @site/docs/foo.md
|
|
223
177
|
*/
|
|
224
178
|
function aliasedSitePath(filePath, siteDir) {
|
|
225
|
-
const relativePath = exports.posixPath(path_1.default.relative(siteDir, filePath));
|
|
179
|
+
const relativePath = (0, exports.posixPath)(path_1.default.relative(siteDir, filePath));
|
|
226
180
|
// Cannot use path.join() as it resolves '../' and removes
|
|
227
181
|
// the '@site'. Let webpack loader resolve it.
|
|
228
182
|
return `@site/${relativePath}`;
|
|
@@ -230,7 +184,7 @@ function aliasedSitePath(filePath, siteDir) {
|
|
|
230
184
|
exports.aliasedSitePath = aliasedSitePath;
|
|
231
185
|
function getEditUrl(fileRelativePath, editUrl) {
|
|
232
186
|
return editUrl
|
|
233
|
-
? normalizeUrl([editUrl, exports.posixPath(fileRelativePath)])
|
|
187
|
+
? (0, normalizeUrl_1.normalizeUrl)([editUrl, (0, exports.posixPath)(fileRelativePath)])
|
|
234
188
|
: undefined;
|
|
235
189
|
}
|
|
236
190
|
exports.getEditUrl = getEditUrl;
|
|
@@ -250,7 +204,7 @@ function isValidPathname(str) {
|
|
|
250
204
|
exports.isValidPathname = isValidPathname;
|
|
251
205
|
// resolve pathname and fail fast if resolution fails
|
|
252
206
|
function resolvePathname(to, from) {
|
|
253
|
-
return resolve_pathname_1.default(to, from);
|
|
207
|
+
return (0, resolve_pathname_1.default)(to, from);
|
|
254
208
|
}
|
|
255
209
|
exports.resolvePathname = resolvePathname;
|
|
256
210
|
function addLeadingSlash(str) {
|
|
@@ -292,23 +246,19 @@ function getElementsAround(array, aroundIndex) {
|
|
|
292
246
|
return { previous, next };
|
|
293
247
|
}
|
|
294
248
|
exports.getElementsAround = getElementsAround;
|
|
295
|
-
function getPluginI18nPath({ siteDir, locale, pluginName, pluginId =
|
|
296
|
-
subPaths = [], }) {
|
|
249
|
+
function getPluginI18nPath({ siteDir, locale, pluginName, pluginId = constants_1.DEFAULT_PLUGIN_ID, subPaths = [], }) {
|
|
297
250
|
return path_1.default.join(siteDir, 'i18n',
|
|
298
251
|
// namespace first by locale: convenient to work in a single folder for a translator
|
|
299
252
|
locale,
|
|
300
253
|
// Make it convenient to use for single-instance
|
|
301
254
|
// ie: return "docs", not "docs-default" nor "docs/default"
|
|
302
|
-
`${pluginName}${
|
|
303
|
-
// TODO duplicate constant :(
|
|
304
|
-
pluginId === 'default' ? '' : `-${pluginId}`}`, ...subPaths);
|
|
255
|
+
`${pluginName}${pluginId === constants_1.DEFAULT_PLUGIN_ID ? '' : `-${pluginId}`}`, ...subPaths);
|
|
305
256
|
}
|
|
306
257
|
exports.getPluginI18nPath = getPluginI18nPath;
|
|
307
258
|
async function mapAsyncSequencial(array, action) {
|
|
308
259
|
const results = [];
|
|
309
260
|
// eslint-disable-next-line no-restricted-syntax
|
|
310
261
|
for (const t of array) {
|
|
311
|
-
// eslint-disable-next-line no-await-in-loop
|
|
312
262
|
const result = await action(t);
|
|
313
263
|
results.push(result);
|
|
314
264
|
}
|
|
@@ -318,7 +268,6 @@ exports.mapAsyncSequencial = mapAsyncSequencial;
|
|
|
318
268
|
async function findAsyncSequential(array, predicate) {
|
|
319
269
|
// eslint-disable-next-line no-restricted-syntax
|
|
320
270
|
for (const t of array) {
|
|
321
|
-
// eslint-disable-next-line no-await-in-loop
|
|
322
271
|
if (await predicate(t)) {
|
|
323
272
|
return t;
|
|
324
273
|
}
|
|
@@ -345,13 +294,13 @@ function reportMessage(message, reportingSeverity) {
|
|
|
345
294
|
case 'ignore':
|
|
346
295
|
break;
|
|
347
296
|
case 'log':
|
|
348
|
-
|
|
297
|
+
logger_1.default.info(message);
|
|
349
298
|
break;
|
|
350
299
|
case 'warn':
|
|
351
|
-
|
|
300
|
+
logger_1.default.warn(message);
|
|
352
301
|
break;
|
|
353
302
|
case 'error':
|
|
354
|
-
|
|
303
|
+
logger_1.default.error(message);
|
|
355
304
|
break;
|
|
356
305
|
case 'throw':
|
|
357
306
|
throw new Error(message);
|
|
@@ -361,9 +310,7 @@ function reportMessage(message, reportingSeverity) {
|
|
|
361
310
|
}
|
|
362
311
|
exports.reportMessage = reportMessage;
|
|
363
312
|
function mergeTranslations(contents) {
|
|
364
|
-
return contents.reduce((acc, content) => {
|
|
365
|
-
return { ...acc, ...content };
|
|
366
|
-
}, {});
|
|
313
|
+
return contents.reduce((acc, content) => ({ ...acc, ...content }), {});
|
|
367
314
|
}
|
|
368
315
|
exports.mergeTranslations = mergeTranslations;
|
|
369
316
|
function getSwizzledComponent(componentPath) {
|
|
@@ -378,7 +325,7 @@ exports.getSwizzledComponent = getSwizzledComponent;
|
|
|
378
325
|
function updateTranslationFileMessages(translationFile, updateMessage) {
|
|
379
326
|
return {
|
|
380
327
|
...translationFile,
|
|
381
|
-
content: lodash_1.mapValues(translationFile.content, (translation) => ({
|
|
328
|
+
content: (0, lodash_1.mapValues)(translationFile.content, (translation) => ({
|
|
382
329
|
...translation,
|
|
383
330
|
message: updateMessage(translation.message),
|
|
384
331
|
})),
|
|
@@ -401,3 +348,4 @@ function parseMarkdownHeadingId(heading) {
|
|
|
401
348
|
}
|
|
402
349
|
}
|
|
403
350
|
exports.parseMarkdownHeadingId = parseMarkdownHeadingId;
|
|
351
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,6EAAwC;AACxC,6DAAwB;AACxB,mCAAkC;AAClC,mCAA4C;AAC5C,6FAAsD;AACtD,qEAA0B;AAC1B,6BAAwB;AAOxB,qFAAqD;AAErD,2CAAyD;AACzD,2CAAiD;AACjD,iDAA4C;AAC5C,2CAA8C;AAE9C,2DAA4B;AAC5B,0DAA2B;AAC3B,8DAA+B;AAC/B,sDAAuB;AAEV,QAAA,SAAS,GAAG,qBAAe,CAAC;AAEzC,gEAAiC;AACjC,+DAAgC;AAChC,4DAA6B;AAC7B,yDAA0B;AAC1B,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,8DAA+B;AAE/B,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAC;AACpB,KAAK,UAAU,QAAQ,CAC5B,iBAAyB,EACzB,IAAY,E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AqB;IAErB,MAAM,qBAAqB,GAAG,cAAI,CAAC,OAAO,CACxC,OAAO,CAAC,GAAG,EAAE,EACb,KAAK,EACL,aAAa,CACd,CAAC;IAEF,OAAO,kBAAE,CAAC,UAAU,CAAC,qBAAqB,CAAC;QACzC,CAAC,CAAC,qBAAqB;QACvB,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAZD,oDAYC;AAED,0DAA0D;AAC1D,yCAAyC;AACzC,SAAgB,6BAA6B,CAC3C,eAAgC,EAChC,aAA0C;IAE1C,OAAO;QACL,GAAG,eAAe;QAClB,OAAO,EAAE,IAAA,kBAAS,EAAC,eAAe,CAAC,OAAO,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;YAC5D,GAAG,WAAW;YACd,OAAO,EAAE,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC;SAC5C,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC;AAXD,sEAWC;AAED,yCAAyC;AACzC,wDAAwD;AACxD,SAAgB,sBAAsB,CAAC,OAAe;IAIpD,MAAM,oBAAoB,GAAG,yBAAyB,CAAC;IACvD,MAAM,OAAO,GAAG,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnD,IAAI,OAAO,EAAE;QACX,OAAO;YACL,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;YAChB,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;SACf,CAAC;KACH;SAAM;QACL,OAAO,EAAC,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAC,CAAC;KACvC;AACH,CAAC;AAdD,wDAcC"}
|
package/lib/markdownLinks.d.ts
CHANGED
|
@@ -25,3 +25,4 @@ export declare type ReplaceMarkdownLinksReturn<T extends ContentPaths> = {
|
|
|
25
25
|
brokenMarkdownLinks: BrokenMarkdownLink<T>[];
|
|
26
26
|
};
|
|
27
27
|
export declare function replaceMarkdownLinks<T extends ContentPaths>({ siteDir, fileString, filePath, contentPaths, sourceToPermalink, }: ReplaceMarkdownLinksParams<T>): ReplaceMarkdownLinksReturn<T>;
|
|
28
|
+
//# sourceMappingURL=markdownLinks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdownLinks.d.ts","sourceRoot":"","sources":["../src/markdownLinks.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,oBAAY,YAAY,GAAG;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,oBAAoB,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,oBAAY,kBAAkB,CAAC,CAAC,SAAS,YAAY,IAAI;IACvD,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,CAAC,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,oBAAY,0BAA0B,CAAC,CAAC,SAAS,YAAY,IAAI;IAC/D,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,CAAC,CAAC;IAChB,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C,CAAC;AAEF,oBAAY,0BAA0B,CAAC,CAAC,SAAS,YAAY,IAAI;IAC/D,UAAU,EAAE,MAAM,CAAC;IACnB,mBAAmB,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAAE,CAAC;CAC9C,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,YAAY,EAAE,EAC3D,OAAO,EACP,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,iBAAiB,GAClB,EAAE,0BAA0B,CAAC,CAAC,CAAC,GAAG,0BAA0B,CAAC,CAAC,CAAC,CA+D/D"}
|
package/lib/markdownLinks.js
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.replaceMarkdownLinks = void 0;
|
|
10
|
-
const
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
11
12
|
const index_1 = require("./index");
|
|
12
13
|
function replaceMarkdownLinks({ siteDir, fileString, filePath, contentPaths, sourceToPermalink, }) {
|
|
13
14
|
const { contentPath, contentPathLocalized } = contentPaths;
|
|
@@ -30,12 +31,24 @@ function replaceMarkdownLinks({ siteDir, fileString, filePath, contentPaths, sou
|
|
|
30
31
|
while (mdMatch !== null) {
|
|
31
32
|
// Replace it to correct html link.
|
|
32
33
|
const mdLink = mdMatch[1];
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
const sourcesToTry = [
|
|
35
|
+
path_1.default.resolve(path_1.default.dirname(filePath), decodeURIComponent(mdLink)),
|
|
36
|
+
`${contentPathLocalized}/${decodeURIComponent(mdLink)}`,
|
|
37
|
+
`${contentPath}/${decodeURIComponent(mdLink)}`,
|
|
38
|
+
];
|
|
39
|
+
const aliasedSourceMatch = sourcesToTry
|
|
40
|
+
.map((source) => (0, index_1.aliasedSitePath)(source, siteDir))
|
|
41
|
+
.find((source) => sourceToPermalink[source]);
|
|
42
|
+
const permalink = aliasedSourceMatch
|
|
43
|
+
? sourceToPermalink[aliasedSourceMatch]
|
|
44
|
+
: undefined;
|
|
37
45
|
if (permalink) {
|
|
38
|
-
|
|
46
|
+
// MDX won't be happy if the permalink contains a space, we need to convert it to %20
|
|
47
|
+
const encodedPermalink = permalink
|
|
48
|
+
.split('/')
|
|
49
|
+
.map((part) => part.replace(/\s/g, '%20'))
|
|
50
|
+
.join('/');
|
|
51
|
+
modifiedLine = modifiedLine.replace(mdLink, encodedPermalink);
|
|
39
52
|
}
|
|
40
53
|
else {
|
|
41
54
|
const brokenMarkdownLink = {
|
|
@@ -53,3 +66,4 @@ function replaceMarkdownLinks({ siteDir, fileString, filePath, contentPaths, sou
|
|
|
53
66
|
return { newContent, brokenMarkdownLinks };
|
|
54
67
|
}
|
|
55
68
|
exports.replaceMarkdownLinks = replaceMarkdownLinks;
|
|
69
|
+
//# sourceMappingURL=markdownLinks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdownLinks.js","sourceRoot":"","sources":["../src/markdownLinks.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,6DAAwB;AACxB,mCAAwC;AA0BxC,SAAgB,oBAAoB,CAAyB,EAC3D,OAAO,EACP,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,iBAAiB,GACa;IAC9B,MAAM,EAAC,WAAW,EAAE,oBAAoB,EAAC,GAAG,YAAY,CAAC;IAEzD,MAAM,mBAAmB,GAA4B,EAAE,CAAC;IAExD,+DAA+D;IAC/D,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QAChD,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;YACjC,WAAW,GAAG,CAAC,WAAW,CAAC;SAC5B;QACD,IAAI,WAAW,EAAE;YACf,OAAO,IAAI,CAAC;SACb;QAED,IAAI,YAAY,GAAG,IAAI,CAAC;QACxB,2DAA2D;QAC3D,6EAA6E;QAC7E,+DAA+D;QAC/D,MAAM,OAAO,GAAG,uDAAuD,CAAC;QACxE,IAAI,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACzC,OAAO,OAAO,KAAK,IAAI,EAAE;YACvB,mCAAmC;YACnC,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YAE1B,MAAM,YAAY,GAAG;gBACnB,cAAI,CAAC,OAAO,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,kBAAkB,CAAC,MAAM,CAAC,CAAC;gBAChE,GAAG,oBAAoB,IAAI,kBAAkB,CAAC,MAAM,C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