@docusaurus/utils 2.0.0-beta.15d451942 → 2.0.0-beta.18
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/README.md +1 -1
- package/lib/constants.d.ts +68 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +71 -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 +35 -0
- package/lib/emitUtils.d.ts.map +1 -0
- package/lib/emitUtils.js +107 -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 +66 -0
- package/lib/gitUtils.js.map +1 -0
- package/lib/globUtils.d.ts +39 -0
- package/lib/globUtils.d.ts.map +1 -0
- package/lib/globUtils.js +66 -0
- package/lib/globUtils.js.map +1 -0
- package/lib/hashUtils.d.ts +17 -0
- package/lib/hashUtils.d.ts.map +1 -0
- package/lib/hashUtils.js +42 -0
- package/lib/hashUtils.js.map +1 -0
- package/lib/i18nUtils.d.ts +28 -0
- package/lib/i18nUtils.d.ts.map +1 -0
- package/lib/i18nUtils.js +49 -0
- package/lib/i18nUtils.js.map +1 -0
- package/lib/index.d.ts +16 -82
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +89 -411
- package/lib/index.js.map +1 -0
- package/lib/jsUtils.d.ts +45 -0
- package/lib/jsUtils.d.ts.map +1 -0
- package/lib/jsUtils.js +94 -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 +48 -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 +52 -0
- package/lib/pathUtils.d.ts.map +1 -0
- package/lib/pathUtils.js +113 -0
- package/lib/pathUtils.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 +48 -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 +208 -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 +116 -0
- package/lib/webpackUtils.js.map +1 -0
- package/package.json +20 -10
- package/src/constants.ts +90 -0
- package/src/dataFileUtils.ts +122 -0
- package/src/deps.d.ts +10 -0
- package/src/emitUtils.ts +130 -0
- package/src/gitUtils.ts +153 -0
- package/src/globUtils.ts +80 -0
- package/src/hashUtils.ts +38 -0
- package/src/i18nUtils.ts +67 -0
- package/src/index.ts +94 -521
- package/src/jsUtils.ts +102 -0
- package/src/markdownLinks.ts +89 -30
- package/src/markdownUtils.ts +354 -0
- package/src/pathUtils.ts +121 -0
- package/src/slugger.ts +36 -0
- package/src/tags.ts +117 -0
- package/src/urlUtils.ts +235 -0
- package/src/webpackUtils.ts +154 -0
- package/lib/.tsbuildinfo +0 -3972
- 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 -28
- package/lib/markdownParser.js +0 -132
- 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__/index.test.ts +0 -681
- package/src/__tests__/markdownParser.test.ts +0 -772
- 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 -177
- package/src/posixPath.ts +0 -27
- package/tsconfig.json +0 -9
package/README.md
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
/** Node major version, directly read from env. */
|
|
8
|
+
export declare const NODE_MAJOR_VERSION: number;
|
|
9
|
+
/** Node minor version, directly read from env. */
|
|
10
|
+
export declare const NODE_MINOR_VERSION: number;
|
|
11
|
+
/**
|
|
12
|
+
* Can be overridden with cli option `--out-dir`. Code should generally use
|
|
13
|
+
* `context.outDir` instead (which is always absolute and localized).
|
|
14
|
+
*/
|
|
15
|
+
export declare const DEFAULT_BUILD_DIR_NAME = "build";
|
|
16
|
+
/**
|
|
17
|
+
* Can be overridden with cli option `--config`. Code should generally use
|
|
18
|
+
* `context.siteConfigPath` instead (which is always absolute).
|
|
19
|
+
*/
|
|
20
|
+
export declare const DEFAULT_CONFIG_FILE_NAME = "docusaurus.config.js";
|
|
21
|
+
/** Can be absolute or relative to site directory. */
|
|
22
|
+
export declare const BABEL_CONFIG_FILE_NAME: string;
|
|
23
|
+
/**
|
|
24
|
+
* Can be absolute or relative to site directory. Code should generally use
|
|
25
|
+
* `context.generatedFilesDir` instead (which is always absolute).
|
|
26
|
+
*/
|
|
27
|
+
export declare const GENERATED_FILES_DIR_NAME: string;
|
|
28
|
+
/**
|
|
29
|
+
* We would assume all of the site's JS code lives in here and not outside.
|
|
30
|
+
* Relative to the site directory.
|
|
31
|
+
*/
|
|
32
|
+
export declare const SRC_DIR_NAME = "src";
|
|
33
|
+
/**
|
|
34
|
+
* Can be overridden with `config.staticDirectories`. Code should use
|
|
35
|
+
* `context.siteConfig.staticDirectories` instead (which is always absolute).
|
|
36
|
+
*/
|
|
37
|
+
export declare const DEFAULT_STATIC_DIR_NAME = "static";
|
|
38
|
+
/**
|
|
39
|
+
* Files here are handled by webpack, hashed (can be cached aggressively).
|
|
40
|
+
* Relative to the build output folder.
|
|
41
|
+
*/
|
|
42
|
+
export declare const OUTPUT_STATIC_ASSETS_DIR_NAME = "assets";
|
|
43
|
+
/**
|
|
44
|
+
* Components in this directory will receive the `@theme` alias and be able to
|
|
45
|
+
* shadow default theme components.
|
|
46
|
+
*/
|
|
47
|
+
export declare const THEME_PATH: string;
|
|
48
|
+
/**
|
|
49
|
+
* All translation-related data live here, relative to site directory. Content
|
|
50
|
+
* will be namespaced by locale.
|
|
51
|
+
*/
|
|
52
|
+
export declare const I18N_DIR_NAME = "i18n";
|
|
53
|
+
/**
|
|
54
|
+
* Translations for React code.
|
|
55
|
+
*/
|
|
56
|
+
export declare const CODE_TRANSLATIONS_FILE_NAME = "code.json";
|
|
57
|
+
/** Dev server opens on this port by default. */
|
|
58
|
+
export declare const DEFAULT_PORT = 3000;
|
|
59
|
+
/** Default plugin ID. */
|
|
60
|
+
export declare const DEFAULT_PLUGIN_ID = "default";
|
|
61
|
+
/**
|
|
62
|
+
* Allow overriding the limit after which the url loader will no longer inline
|
|
63
|
+
* assets.
|
|
64
|
+
*
|
|
65
|
+
* @see https://github.com/facebook/docusaurus/issues/5493
|
|
66
|
+
*/
|
|
67
|
+
export declare const WEBPACK_URL_LOADER_LIMIT: string | number;
|
|
68
|
+
//# 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,kDAAkD;AAClD,eAAO,MAAM,kBAAkB,QAG9B,CAAC;AACF,kDAAkD;AAClD,eAAO,MAAM,kBAAkB,QAG9B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,UAAU,CAAC;AAE9C;;;GAGG;AACH,eAAO,MAAM,wBAAwB,yBAAyB,CAAC;AAE/D,qDAAqD;AACrD,eAAO,MAAM,sBAAsB,QACiC,CAAC;AAErE;;;GAGG;AACH,eAAO,MAAM,wBAAwB,QAC6B,CAAC;AAEnE;;;GAGG;AACH,eAAO,MAAM,YAAY,QAAQ,CAAC;AAElC;;;GAGG;AACH,eAAO,MAAM,uBAAuB,WAAW,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,6BAA6B,WAAW,CAAC;AAEtD;;;GAGG;AACH,eAAO,MAAM,UAAU,QAA0B,CAAC;AAElD;;;GAGG;AACH,eAAO,MAAM,aAAa,SAAS,CAAC;AAEpC;;GAEG;AACH,eAAO,MAAM,2BAA2B,cAAc,CAAC;AAEvD,gDAAgD;AAChD,eAAO,MAAM,YAAY,OAAO,CAAC;AAEjC,yBAAyB;AACzB,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAE3C;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,iBACU,CAAC"}
|
package/lib/constants.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.WEBPACK_URL_LOADER_LIMIT = exports.DEFAULT_PLUGIN_ID = exports.DEFAULT_PORT = exports.CODE_TRANSLATIONS_FILE_NAME = exports.I18N_DIR_NAME = exports.THEME_PATH = exports.OUTPUT_STATIC_ASSETS_DIR_NAME = exports.DEFAULT_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
|
+
/** Node major version, directly read from env. */
|
|
11
|
+
exports.NODE_MAJOR_VERSION = parseInt(process.versions.node.split('.')[0], 10);
|
|
12
|
+
/** Node minor version, directly read from env. */
|
|
13
|
+
exports.NODE_MINOR_VERSION = parseInt(process.versions.node.split('.')[1], 10);
|
|
14
|
+
/**
|
|
15
|
+
* Can be overridden with cli option `--out-dir`. Code should generally use
|
|
16
|
+
* `context.outDir` instead (which is always absolute and localized).
|
|
17
|
+
*/
|
|
18
|
+
exports.DEFAULT_BUILD_DIR_NAME = 'build';
|
|
19
|
+
/**
|
|
20
|
+
* Can be overridden with cli option `--config`. Code should generally use
|
|
21
|
+
* `context.siteConfigPath` instead (which is always absolute).
|
|
22
|
+
*/
|
|
23
|
+
exports.DEFAULT_CONFIG_FILE_NAME = 'docusaurus.config.js';
|
|
24
|
+
/** Can be absolute or relative to site directory. */
|
|
25
|
+
exports.BABEL_CONFIG_FILE_NAME = process.env.DOCUSAURUS_BABEL_CONFIG_FILE_NAME ?? 'babel.config.js';
|
|
26
|
+
/**
|
|
27
|
+
* Can be absolute or relative to site directory. Code should generally use
|
|
28
|
+
* `context.generatedFilesDir` instead (which is always absolute).
|
|
29
|
+
*/
|
|
30
|
+
exports.GENERATED_FILES_DIR_NAME = process.env.DOCUSAURUS_GENERATED_FILES_DIR_NAME ?? '.docusaurus';
|
|
31
|
+
/**
|
|
32
|
+
* We would assume all of the site's JS code lives in here and not outside.
|
|
33
|
+
* Relative to the site directory.
|
|
34
|
+
*/
|
|
35
|
+
exports.SRC_DIR_NAME = 'src';
|
|
36
|
+
/**
|
|
37
|
+
* Can be overridden with `config.staticDirectories`. Code should use
|
|
38
|
+
* `context.siteConfig.staticDirectories` instead (which is always absolute).
|
|
39
|
+
*/
|
|
40
|
+
exports.DEFAULT_STATIC_DIR_NAME = 'static';
|
|
41
|
+
/**
|
|
42
|
+
* Files here are handled by webpack, hashed (can be cached aggressively).
|
|
43
|
+
* Relative to the build output folder.
|
|
44
|
+
*/
|
|
45
|
+
exports.OUTPUT_STATIC_ASSETS_DIR_NAME = 'assets';
|
|
46
|
+
/**
|
|
47
|
+
* Components in this directory will receive the `@theme` alias and be able to
|
|
48
|
+
* shadow default theme components.
|
|
49
|
+
*/
|
|
50
|
+
exports.THEME_PATH = `${exports.SRC_DIR_NAME}/theme`;
|
|
51
|
+
/**
|
|
52
|
+
* All translation-related data live here, relative to site directory. Content
|
|
53
|
+
* will be namespaced by locale.
|
|
54
|
+
*/
|
|
55
|
+
exports.I18N_DIR_NAME = 'i18n';
|
|
56
|
+
/**
|
|
57
|
+
* Translations for React code.
|
|
58
|
+
*/
|
|
59
|
+
exports.CODE_TRANSLATIONS_FILE_NAME = 'code.json';
|
|
60
|
+
/** Dev server opens on this port by default. */
|
|
61
|
+
exports.DEFAULT_PORT = 3000;
|
|
62
|
+
/** Default plugin ID. */
|
|
63
|
+
exports.DEFAULT_PLUGIN_ID = 'default';
|
|
64
|
+
/**
|
|
65
|
+
* Allow overriding the limit after which the url loader will no longer inline
|
|
66
|
+
* assets.
|
|
67
|
+
*
|
|
68
|
+
* @see https://github.com/facebook/docusaurus/issues/5493
|
|
69
|
+
*/
|
|
70
|
+
exports.WEBPACK_URL_LOADER_LIMIT = process.env.WEBPACK_URL_LOADER_LIMIT ?? 10000;
|
|
71
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";AAAA;;;;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
+
*
|
|
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
|
+
/** Path to the potential data file, relative to `contentPaths` */
|
|
10
|
+
filePath: string;
|
|
11
|
+
/**
|
|
12
|
+
* Includes the base path and localized path, both of which are eligible for
|
|
13
|
+
* sourcing data files. Both paths should be absolute.
|
|
14
|
+
*/
|
|
15
|
+
contentPaths: ContentPaths;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Looks for a data file in the potential content paths; loads a localized data
|
|
19
|
+
* file in priority.
|
|
20
|
+
*
|
|
21
|
+
* @returns An absolute path to the data file, or `undefined` if there isn't one.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getDataFilePath({ filePath, contentPaths, }: DataFileParams): Promise<string | undefined>;
|
|
24
|
+
/**
|
|
25
|
+
* Looks up for a data file in the content paths, returns the object validated
|
|
26
|
+
* and normalized according to the `validate` callback.
|
|
27
|
+
*
|
|
28
|
+
* @returns `undefined` when file not found
|
|
29
|
+
* @throws Throws when validation fails, displaying a helpful context message.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getDataFileData<T>(params: DataFileParams & {
|
|
32
|
+
/** Used for the "The X file looks invalid" message. */
|
|
33
|
+
fileType: string;
|
|
34
|
+
}, validate: (content: unknown) => T): Promise<T | undefined>;
|
|
35
|
+
/**
|
|
36
|
+
* Takes the `contentPaths` data structure and returns an ordered path list
|
|
37
|
+
* indicating their priorities. For all data, we look in the localized folder
|
|
38
|
+
* in priority.
|
|
39
|
+
*/
|
|
40
|
+
export declare function getContentPathList(contentPaths: ContentPaths): string[];
|
|
41
|
+
/**
|
|
42
|
+
* @param folderPaths a list of absolute paths.
|
|
43
|
+
* @param relativeFilePath file path relative to each `folderPaths`.
|
|
44
|
+
* @returns the first folder path in which the file exists, or `undefined` if
|
|
45
|
+
* none is found.
|
|
46
|
+
*/
|
|
47
|
+
export declare function findFolderContainingFile(folderPaths: string[], relativeFilePath: string): Promise<string | undefined>;
|
|
48
|
+
/**
|
|
49
|
+
* Fail-fast alternative to `findFolderContainingFile`.
|
|
50
|
+
*
|
|
51
|
+
* @param folderPaths a list of absolute paths.
|
|
52
|
+
* @param relativeFilePath file path relative to each `folderPaths`.
|
|
53
|
+
* @returns the first folder path in which the file exists.
|
|
54
|
+
* @throws Throws if no file can be found. You should use this method only when
|
|
55
|
+
* you actually know the file exists (e.g. when the `relativeFilePath` is read
|
|
56
|
+
* with a glob and you are just trying to localize it)
|
|
57
|
+
*/
|
|
58
|
+
export declare function getFolderContainingFile(folderPaths: string[], relativeFilePath: string): Promise<string>;
|
|
59
|
+
export {};
|
|
60
|
+
//# 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,kEAAkE;IAClE,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,YAAY,EAAE,YAAY,CAAC;CAC5B,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,EACpC,QAAQ,EACR,YAAY,GACb,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAS9C;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,CAAC,EACrC,MAAM,EAAE,cAAc,GAAG;IACvB,uDAAuD;IACvD,QAAQ,EAAE,MAAM,CAAC;CAClB,EACD,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,CAAC,GAChC,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAaxB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,YAAY,GAAG,MAAM,EAAE,CAEvE;AAED;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,MAAM,EAAE,EACrB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAI7B;AAED;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,MAAM,EAAE,EACrB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,MAAM,CAAC,CAYjB"}
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
/**
|
|
17
|
+
* Looks for a data file in the potential content paths; loads a localized data
|
|
18
|
+
* file in priority.
|
|
19
|
+
*
|
|
20
|
+
* @returns An absolute path to the data file, or `undefined` if there isn't one.
|
|
21
|
+
*/
|
|
22
|
+
async function getDataFilePath({ filePath, contentPaths, }) {
|
|
23
|
+
const contentPath = await findFolderContainingFile(getContentPathList(contentPaths), filePath);
|
|
24
|
+
if (contentPath) {
|
|
25
|
+
return path_1.default.join(contentPath, filePath);
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
exports.getDataFilePath = getDataFilePath;
|
|
30
|
+
/**
|
|
31
|
+
* Looks up for a data file in the content paths, returns the object validated
|
|
32
|
+
* and normalized according to the `validate` callback.
|
|
33
|
+
*
|
|
34
|
+
* @returns `undefined` when file not found
|
|
35
|
+
* @throws Throws when validation fails, displaying a helpful context message.
|
|
36
|
+
*/
|
|
37
|
+
async function getDataFileData(params, validate) {
|
|
38
|
+
const filePath = await getDataFilePath(params);
|
|
39
|
+
if (!filePath) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const contentString = await fs_extra_1.default.readFile(filePath, { encoding: 'utf8' });
|
|
44
|
+
const unsafeContent = js_yaml_1.default.load(contentString);
|
|
45
|
+
return validate(unsafeContent);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
logger_1.default.error `The ${params.fileType} file at path=${filePath} looks invalid.`;
|
|
49
|
+
throw err;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.getDataFileData = getDataFileData;
|
|
53
|
+
/**
|
|
54
|
+
* Takes the `contentPaths` data structure and returns an ordered path list
|
|
55
|
+
* indicating their priorities. For all data, we look in the localized folder
|
|
56
|
+
* in priority.
|
|
57
|
+
*/
|
|
58
|
+
function getContentPathList(contentPaths) {
|
|
59
|
+
return [contentPaths.contentPathLocalized, contentPaths.contentPath];
|
|
60
|
+
}
|
|
61
|
+
exports.getContentPathList = getContentPathList;
|
|
62
|
+
/**
|
|
63
|
+
* @param folderPaths a list of absolute paths.
|
|
64
|
+
* @param relativeFilePath file path relative to each `folderPaths`.
|
|
65
|
+
* @returns the first folder path in which the file exists, or `undefined` if
|
|
66
|
+
* none is found.
|
|
67
|
+
*/
|
|
68
|
+
async function findFolderContainingFile(folderPaths, relativeFilePath) {
|
|
69
|
+
return (0, index_1.findAsyncSequential)(folderPaths, (folderPath) => fs_extra_1.default.pathExists(path_1.default.join(folderPath, relativeFilePath)));
|
|
70
|
+
}
|
|
71
|
+
exports.findFolderContainingFile = findFolderContainingFile;
|
|
72
|
+
/**
|
|
73
|
+
* Fail-fast alternative to `findFolderContainingFile`.
|
|
74
|
+
*
|
|
75
|
+
* @param folderPaths a list of absolute paths.
|
|
76
|
+
* @param relativeFilePath file path relative to each `folderPaths`.
|
|
77
|
+
* @returns the first folder path in which the file exists.
|
|
78
|
+
* @throws Throws if no file can be found. You should use this method only when
|
|
79
|
+
* you actually know the file exists (e.g. when the `relativeFilePath` is read
|
|
80
|
+
* with a glob and you are just trying to localize it)
|
|
81
|
+
*/
|
|
82
|
+
async function getFolderContainingFile(folderPaths, relativeFilePath) {
|
|
83
|
+
const maybeFolderPath = await findFolderContainingFile(folderPaths, relativeFilePath);
|
|
84
|
+
if (!maybeFolderPath) {
|
|
85
|
+
throw new Error(`File "${relativeFilePath}" does not exist in any of these folders:
|
|
86
|
+
- ${folderPaths.join('\n- ')}`);
|
|
87
|
+
}
|
|
88
|
+
return maybeFolderPath;
|
|
89
|
+
}
|
|
90
|
+
exports.getFolderContainingFile = getFolderContainingFile;
|
|
91
|
+
//# sourceMappingURL=dataFileUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataFileUtils.js","sourceRoot":"","sources":["../src/dataFileUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,gEAA0B;AAC1B,8DAA2B;AAC3B,wDAAwB;AACxB,mCAA4C;AAE5C,wEAAwC;AAYxC;;;;;GAKG;AACI,KAAK,UAAU,eAAe,CAAC,EACpC,QAAQ,EACR,YAAY,GACG;IACf,MAAM,WAAW,GAAG,MAAM,wBAAwB,CAChD,kBAAkB,CAAC,YAAY,CAAC,EAChC,QAAQ,CACT,CAAC;IACF,IAAI,WAAW,EAAE;QACf,OAAO,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;KACzC;IACD,OAAO,SAAS,CAAC;AACnB,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b,SAAS,gBAAgB;IAC3B,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CACzB,CAAC;KACH;IACD,OAAO,eAAe,CAAC;AACzB,CAAC;AAfD,0DAeC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
/**
|
|
9
|
+
* Outputs a file to the generated files directory. Only writes files if content
|
|
10
|
+
* differs from cache (for hot reload performance).
|
|
11
|
+
*
|
|
12
|
+
* @param generatedFilesDir Absolute path.
|
|
13
|
+
* @param file Path relative to `generatedFilesDir`.
|
|
14
|
+
* @param content String content to write.
|
|
15
|
+
* @param skipCache If `true` (defaults as `true` for production), file is
|
|
16
|
+
* force-rewritten, skipping cache.
|
|
17
|
+
*/
|
|
18
|
+
export declare function generate(generatedFilesDir: string, file: string, content: string, skipCache?: boolean): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Generate unique chunk name given a module path.
|
|
21
|
+
*/
|
|
22
|
+
export declare function genChunkName(modulePath: string, prefix?: string, preferredName?: string, shortId?: boolean): string;
|
|
23
|
+
/**
|
|
24
|
+
* @param permalink The URL that the HTML file corresponds to, without base URL
|
|
25
|
+
* @param outDir Full path to the output directory
|
|
26
|
+
* @param trailingSlash The site config option. If provided, only one path will
|
|
27
|
+
* be read.
|
|
28
|
+
* @returns This returns a buffer, which you have to decode string yourself if
|
|
29
|
+
* needed. (Not always necessary since the output isn't for human consumption
|
|
30
|
+
* anyways, and most HTML manipulation libs accept buffers)
|
|
31
|
+
* @throws Throws when the HTML file is not found at any of the potential paths.
|
|
32
|
+
* This should never happen as it would lead to a 404.
|
|
33
|
+
*/
|
|
34
|
+
export declare function readOutputHTMLFile(permalink: string, outDir: string, trailingSlash: boolean | undefined): Promise<Buffer>;
|
|
35
|
+
//# 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;;;;;;;;;GASG;AACH,wBAAsB,QAAQ,CAC5B,iBAAiB,EAAE,MAAM,EACzB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,SAAS,GAAE,OAA+C,GACzD,OAAO,CAAC,IAAI,CAAC,CAgCf;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;;;;;;;;;;GAUG;AACH,wBAAsB,kBAAkB,CACtC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,OAAO,GAAG,SAAS,GACjC,OAAO,CAAC,MAAM,CAAC,CAqBjB"}
|
package/lib/emitUtils.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
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
|
+
/**
|
|
18
|
+
* Outputs a file to the generated files directory. Only writes files if content
|
|
19
|
+
* differs from cache (for hot reload performance).
|
|
20
|
+
*
|
|
21
|
+
* @param generatedFilesDir Absolute path.
|
|
22
|
+
* @param file Path relative to `generatedFilesDir`.
|
|
23
|
+
* @param content String content to write.
|
|
24
|
+
* @param skipCache If `true` (defaults as `true` for production), file is
|
|
25
|
+
* force-rewritten, skipping cache.
|
|
26
|
+
*/
|
|
27
|
+
async function generate(generatedFilesDir, file, content, skipCache = process.env.NODE_ENV === 'production') {
|
|
28
|
+
const filepath = path_1.default.join(generatedFilesDir, file);
|
|
29
|
+
if (skipCache) {
|
|
30
|
+
await fs_extra_1.default.outputFile(filepath, content);
|
|
31
|
+
// Cache still needs to be reset, otherwise, writing "A", "B", and "A" where
|
|
32
|
+
// "B" skips cache will cause the last "A" not be able to overwrite as the
|
|
33
|
+
// first "A" remains in cache. But if the file never existed in cache, no
|
|
34
|
+
// need to register it.
|
|
35
|
+
if (fileHash.get(filepath)) {
|
|
36
|
+
fileHash.set(filepath, (0, crypto_1.createHash)('md5').update(content).digest('hex'));
|
|
37
|
+
}
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
let lastHash = fileHash.get(filepath);
|
|
41
|
+
// If file already exists but it's not in runtime cache yet, we try to
|
|
42
|
+
// calculate the content hash and then compare. This is to avoid unnecessary
|
|
43
|
+
// overwriting and we can reuse old file.
|
|
44
|
+
if (!lastHash && (await fs_extra_1.default.pathExists(filepath))) {
|
|
45
|
+
const lastContent = await fs_extra_1.default.readFile(filepath, 'utf8');
|
|
46
|
+
lastHash = (0, crypto_1.createHash)('md5').update(lastContent).digest('hex');
|
|
47
|
+
fileHash.set(filepath, lastHash);
|
|
48
|
+
}
|
|
49
|
+
const currentHash = (0, crypto_1.createHash)('md5').update(content).digest('hex');
|
|
50
|
+
if (lastHash !== currentHash) {
|
|
51
|
+
await fs_extra_1.default.outputFile(filepath, content);
|
|
52
|
+
fileHash.set(filepath, currentHash);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.generate = generate;
|
|
56
|
+
const chunkNameCache = new Map();
|
|
57
|
+
/**
|
|
58
|
+
* Generate unique chunk name given a module path.
|
|
59
|
+
*/
|
|
60
|
+
function genChunkName(modulePath, prefix, preferredName, shortId = process.env.NODE_ENV === 'production') {
|
|
61
|
+
let chunkName = chunkNameCache.get(modulePath);
|
|
62
|
+
if (!chunkName) {
|
|
63
|
+
if (shortId) {
|
|
64
|
+
chunkName = (0, hashUtils_1.simpleHash)(modulePath, 8);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
let str = modulePath;
|
|
68
|
+
if (preferredName) {
|
|
69
|
+
const shortHash = (0, hashUtils_1.simpleHash)(modulePath, 3);
|
|
70
|
+
str = `${preferredName}${shortHash}`;
|
|
71
|
+
}
|
|
72
|
+
const name = str === '/' ? 'index' : (0, hashUtils_1.docuHash)(str);
|
|
73
|
+
chunkName = prefix ? `${prefix}---${name}` : name;
|
|
74
|
+
}
|
|
75
|
+
chunkNameCache.set(modulePath, chunkName);
|
|
76
|
+
}
|
|
77
|
+
return chunkName;
|
|
78
|
+
}
|
|
79
|
+
exports.genChunkName = genChunkName;
|
|
80
|
+
/**
|
|
81
|
+
* @param permalink The URL that the HTML file corresponds to, without base URL
|
|
82
|
+
* @param outDir Full path to the output directory
|
|
83
|
+
* @param trailingSlash The site config option. If provided, only one path will
|
|
84
|
+
* be read.
|
|
85
|
+
* @returns This returns a buffer, which you have to decode string yourself if
|
|
86
|
+
* needed. (Not always necessary since the output isn't for human consumption
|
|
87
|
+
* anyways, and most HTML manipulation libs accept buffers)
|
|
88
|
+
* @throws Throws when the HTML file is not found at any of the potential paths.
|
|
89
|
+
* This should never happen as it would lead to a 404.
|
|
90
|
+
*/
|
|
91
|
+
async function readOutputHTMLFile(permalink, outDir, trailingSlash) {
|
|
92
|
+
const withTrailingSlashPath = path_1.default.join(outDir, permalink, 'index.html');
|
|
93
|
+
const withoutTrailingSlashPath = path_1.default.join(outDir, `${permalink.replace(/\/$/, '')}.html`);
|
|
94
|
+
if (trailingSlash) {
|
|
95
|
+
return fs_extra_1.default.readFile(withTrailingSlashPath);
|
|
96
|
+
}
|
|
97
|
+
else if (trailingSlash === false) {
|
|
98
|
+
return fs_extra_1.default.readFile(withoutTrailingSlashPath);
|
|
99
|
+
}
|
|
100
|
+
const HTMLPath = await (0, jsUtils_1.findAsyncSequential)([withTrailingSlashPath, withoutTrailingSlashPath], fs_extra_1.default.pathExists);
|
|
101
|
+
if (!HTMLPath) {
|
|
102
|
+
throw new Error(`Expected output HTML file to be found at ${withTrailingSlashPath}`);
|
|
103
|
+
}
|
|
104
|
+
return fs_extra_1.default.readFile(HTMLPath);
|
|
105
|
+
}
|
|
106
|
+
exports.readOutputHTMLFile = readOutputHTMLFile;
|
|
107
|
+
//# 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;AAE3C;;;;;;;;;GASG;AACI,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,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACvC,4EAA4E;QAC5E,0EAA0E;QAC1E,yEAAyE;QACzE,uBAAuB;QACvB,IAAI,QAAQ,CA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A,6BAAmB,EACxC,CAAC,qBAAqB,EAAE,wBAAwB,CAAC,EACjD,kBAAE,CAAC,UAAU,CACd,CAAC;IACF,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,IAAI,KAAK,CACb,4CAA4C,qBAAqB,EAAE,CACpE,CAAC;KACH;IACD,OAAO,kBAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC/B,CAAC;AAzBD,gDAyBC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
/** Custom error thrown when git is not found in `PATH`. */
|
|
8
|
+
export declare class GitNotFoundError extends Error {
|
|
9
|
+
}
|
|
10
|
+
/** Custom error thrown when the current file is not tracked by git. */
|
|
11
|
+
export declare class FileNotTrackedError extends Error {
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Fetches the git history of a file and returns a relevant commit date.
|
|
15
|
+
* It gets the commit date instead of author date so that amended commits
|
|
16
|
+
* can have their dates updated.
|
|
17
|
+
*
|
|
18
|
+
* @throws {GitNotFoundError} If git is not found in `PATH`.
|
|
19
|
+
* @throws {FileNotTrackedError} If the current file is not tracked by git.
|
|
20
|
+
* @throws Also throws when `git log` exited with non-zero, or when it outputs
|
|
21
|
+
* unexpected text.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getFileCommitDate(
|
|
24
|
+
/** Absolute path to the file. */
|
|
25
|
+
file: string, args: {
|
|
26
|
+
/**
|
|
27
|
+
* `"oldest"` is the commit that added the file, following renames;
|
|
28
|
+
* `"newest"` is the last commit that edited the file.
|
|
29
|
+
*/
|
|
30
|
+
age?: 'oldest' | 'newest';
|
|
31
|
+
/** Use `includeAuthor: true` to get the author information as well. */
|
|
32
|
+
includeAuthor?: false;
|
|
33
|
+
}): {
|
|
34
|
+
/** Relevant commit date. */
|
|
35
|
+
date: Date;
|
|
36
|
+
/** Timestamp in **seconds**, as returned from git. */
|
|
37
|
+
timestamp: number;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Fetches the git history of a file and returns a relevant commit date.
|
|
41
|
+
* It gets the commit date instead of author date so that amended commits
|
|
42
|
+
* can have their dates updated.
|
|
43
|
+
*
|
|
44
|
+
* @throws {GitNotFoundError} If git is not found in `PATH`.
|
|
45
|
+
* @throws {FileNotTrackedError} If the current file is not tracked by git.
|
|
46
|
+
* @throws Also throws when `git log` exited with non-zero, or when it outputs
|
|
47
|
+
* unexpected text.
|
|
48
|
+
*/
|
|
49
|
+
export declare function getFileCommitDate(
|
|
50
|
+
/** Absolute path to the file. */
|
|
51
|
+
file: string, args: {
|
|
52
|
+
/**
|
|
53
|
+
* `"oldest"` is the commit that added the file, following renames;
|
|
54
|
+
* `"newest"` is the last commit that edited the file.
|
|
55
|
+
*/
|
|
56
|
+
age?: 'oldest' | 'newest';
|
|
57
|
+
includeAuthor: true;
|
|
58
|
+
}): {
|
|
59
|
+
/** Relevant commit date. */
|
|
60
|
+
date: Date;
|
|
61
|
+
/** Timestamp in **seconds**, as returned from git. */
|
|
62
|
+
timestamp: number;
|
|
63
|
+
/** The author's name, as returned from git. */
|
|
64
|
+
author: string;
|
|
65
|
+
};
|
|
66
|
+
//# 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,2DAA2D;AAC3D,qBAAa,gBAAiB,SAAQ,KAAK;CAAG;AAE9C,uEAAuE;AACvE,qBAAa,mBAAoB,SAAQ,KAAK;CAAG;AAEjD;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB;AAC/B,iCAAiC;AACjC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE;IACJ;;;OAGG;IACH,GAAG,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC1B,uEAAuE;IACvE,aAAa,CAAC,EAAE,KAAK,CAAC;CACvB,GACA;IACD,4BAA4B;IAC5B,IAAI,EAAE,IAAI,CAAC;IACX,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AACF;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB;AAC/B,iCAAiC;AACjC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE;IACJ;;;OAGG;IACH,GAAG,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC1B,aAAa,EAAE,IAAI,CAAC;CACrB,GACA;IACD,4BAA4B;IAC5B,IAAI,EAAE,IAAI,CAAC;IACX,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC"}
|
package/lib/gitUtils.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
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.FileNotTrackedError = 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
|
+
/** Custom error thrown when git is not found in `PATH`. */
|
|
14
|
+
class GitNotFoundError extends Error {
|
|
15
|
+
}
|
|
16
|
+
exports.GitNotFoundError = GitNotFoundError;
|
|
17
|
+
/** Custom error thrown when the current file is not tracked by git. */
|
|
18
|
+
class FileNotTrackedError extends Error {
|
|
19
|
+
}
|
|
20
|
+
exports.FileNotTrackedError = FileNotTrackedError;
|
|
21
|
+
function getFileCommitDate(file, { age = 'oldest', includeAuthor = false, }) {
|
|
22
|
+
if (!shelljs_1.default.which('git')) {
|
|
23
|
+
throw new GitNotFoundError(`Failed to retrieve git history for "${file}" because git is not installed.`);
|
|
24
|
+
}
|
|
25
|
+
if (!shelljs_1.default.test('-f', file)) {
|
|
26
|
+
throw new Error(`Failed to retrieve git history for "${file}" because the file does not exist.`);
|
|
27
|
+
}
|
|
28
|
+
let formatArg = '--format=%ct';
|
|
29
|
+
if (includeAuthor) {
|
|
30
|
+
formatArg += ',%an';
|
|
31
|
+
}
|
|
32
|
+
let extraArgs = '--max-count=1';
|
|
33
|
+
if (age === 'oldest') {
|
|
34
|
+
// --follow is necessary to follow file renames
|
|
35
|
+
// --diff-filter=A ensures we only get the commit which (A)dded the file
|
|
36
|
+
extraArgs += ' --follow --diff-filter=A';
|
|
37
|
+
}
|
|
38
|
+
const result = shelljs_1.default.exec(`git log ${extraArgs} ${formatArg} -- "${path_1.default.basename(file)}"`, {
|
|
39
|
+
// cwd is important, see: https://github.com/facebook/docusaurus/pull/5048
|
|
40
|
+
cwd: path_1.default.dirname(file),
|
|
41
|
+
silent: true,
|
|
42
|
+
});
|
|
43
|
+
if (result.code !== 0) {
|
|
44
|
+
throw new Error(`Failed to retrieve the git history for file "${file}" with exit code ${result.code}: ${result.stderr}`);
|
|
45
|
+
}
|
|
46
|
+
let regex = /^(?<timestamp>\d+)$/;
|
|
47
|
+
if (includeAuthor) {
|
|
48
|
+
regex = /^(?<timestamp>\d+),(?<author>.+)$/;
|
|
49
|
+
}
|
|
50
|
+
const output = result.stdout.trim();
|
|
51
|
+
if (!output) {
|
|
52
|
+
throw new FileNotTrackedError(`Failed to retrieve the git history for file "${file}" because the file is not tracked by git.`);
|
|
53
|
+
}
|
|
54
|
+
const match = output.match(regex);
|
|
55
|
+
if (!match) {
|
|
56
|
+
throw new Error(`Failed to retrieve the git history for file "${file}" with unexpected output: ${output}`);
|
|
57
|
+
}
|
|
58
|
+
const timestamp = Number(match.groups.timestamp);
|
|
59
|
+
const date = new Date(timestamp * 1000);
|
|
60
|
+
if (includeAuthor) {
|
|
61
|
+
return { date, timestamp, author: match.groups.author };
|
|
62
|
+
}
|
|
63
|
+
return { date, timestamp };
|
|
64
|
+
}
|
|
65
|
+
exports.getFileCommitDate = getFileCommitDate;
|
|
66
|
+
//# 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,2DAA2D;AAC3D,MAAa,gBAAiB,SAAQ,KAAK;CAAG;AAA9C,4CAA8C;AAE9C,uEAAuE;AACvE,MAAa,mBAAoB,SAAQ,KAAK;CAAG;AAAjD,kDAAiD;AA2DjD,SAAgB,iBAAiB,CAC/B,IAAY,EACZ,EACE,GAAG,GAAG,QAAQ,EACd,aAAa,GAAG,KAAK,GAItB;IAMD,IAAI,CAAC,iBAAK,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;QACvB,MAAM,IAAI,gBAAgB,CACxB,uCAAuC,IAAI,iCAAiC,CAC7E,CAAC;KACH;IAED,IAAI,CAAC,iBAAK,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;QAC3B,MAAM,IAAI,KAAK,CACb,uCAAuC,IAAI,oCAAoC,CAChF,CAAC;KACH;IAED,IAAI,SAAS,GAAG,cAAc,CAAC;IAC/B,IAAI,aAAa,EAAE;QACjB,SAAS,IAAI,MAAM,CAAC;KACrB;IAED,IAAI,SAAS,GAAG,eAAe,CAAC;IAChC,IAAI,GAAG,KAAK,QAAQ,EAAE;QACpB,+CAA+C;QAC/C,wEAAwE;QACxE,SAAS,IAAI,2BAA2B,CAAC;KAC1C;IAED,MAAM,MAAM,GAAG,iBAAK,CAAC,IAAI,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. 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
|
+
/** A re-export of the globby instance. */
|
|
8
|
+
export { default as Globby } from 'globby';
|
|
9
|
+
/**
|
|
10
|
+
* The default glob patterns we ignore when sourcing content.
|
|
11
|
+
* - Ignore files and folders starting with `_` recursively
|
|
12
|
+
* - Ignore tests
|
|
13
|
+
*/
|
|
14
|
+
export declare const GlobExcludeDefault: string[];
|
|
15
|
+
declare type Matcher = (str: string) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* A very thin wrapper around `Micromatch.makeRe`.
|
|
18
|
+
*
|
|
19
|
+
* @see {@link createAbsoluteFilePathMatcher}
|
|
20
|
+
* @param patterns A list of glob patterns.
|
|
21
|
+
* @returns A matcher handle that tells if a file path is matched by any of the
|
|
22
|
+
* patterns.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createMatcher(patterns: string[]): Matcher;
|
|
25
|
+
/**
|
|
26
|
+
* We use match patterns like `"** /_* /**"` (ignore the spaces), where `"_*"`
|
|
27
|
+
* should only be matched within a subfolder. This function would:
|
|
28
|
+
* - Match `/user/sebastien/website/docs/_partials/xyz.md`
|
|
29
|
+
* - Ignore `/user/_sebastien/website/docs/partials/xyz.md`
|
|
30
|
+
*
|
|
31
|
+
* @param patterns A list of glob patterns.
|
|
32
|
+
* @param rootFolders A list of root folders to resolve the glob from.
|
|
33
|
+
* @returns A matcher handle that tells if a file path is matched by any of the
|
|
34
|
+
* patterns, resolved from the first root folder that contains the path.
|
|
35
|
+
* @throws Throws when the returned matcher receives a path that doesn't belong
|
|
36
|
+
* to any of the `rootFolders`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function createAbsoluteFilePathMatcher(patterns: string[], rootFolders: string[]): Matcher;
|
|
39
|
+
//# sourceMappingURL=globUtils.d.ts.map
|