mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-17 02:56:57 +02:00
chore(v2): use single method Lodash packages in docs plugin (#2519)
* chore(v2): use single method Lodash packages in docs plugin * reorder packages * TS types nightmare
This commit is contained in:
parent
36f4f9487e
commit
b4acb89888
4 changed files with 27 additions and 19 deletions
|
@ -35,7 +35,11 @@
|
|||
"@types/jest": "^24.0.23",
|
||||
"@types/loader-utils": "^1.1.3",
|
||||
"@types/lodash": "^4.14.149",
|
||||
"@types/lodash.flatmap": "^4.5.6",
|
||||
"@types/lodash.groupby": "^4.6.6",
|
||||
"@types/lodash.kebabcase": "^4.1.6",
|
||||
"@types/lodash.pick": "^4.4.6",
|
||||
"@types/lodash.pickby": "^4.6.6",
|
||||
"@types/node": "^12.12.14",
|
||||
"@types/react": "^16.9.13",
|
||||
"@types/react-dev-utils": "^9.0.1",
|
||||
|
|
|
@ -23,7 +23,10 @@
|
|||
"globby": "^10.0.1",
|
||||
"import-fresh": "^3.2.1",
|
||||
"loader-utils": "^1.2.3",
|
||||
"lodash": "^4.17.15",
|
||||
"lodash.flatmap": "^4.5.0",
|
||||
"lodash.groupby": "^4.6.0",
|
||||
"lodash.pick": "^4.4.0",
|
||||
"lodash.pickby": "^4.6.0",
|
||||
"shelljs": "^0.8.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import _ from 'lodash';
|
||||
import groupBy from 'lodash.groupby';
|
||||
import pick from 'lodash.pick';
|
||||
import pickBy from 'lodash.pickby';
|
||||
import globby from 'globby';
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
|
@ -101,13 +103,13 @@ export default function pluginContentDocs(
|
|||
const {include} = options;
|
||||
let globPattern = include.map(pattern => `${docsDir}/${pattern}`);
|
||||
if (versioning.enabled) {
|
||||
const docsGlob = _.flatten(
|
||||
include.map(pattern =>
|
||||
const docsGlob = include
|
||||
.map(pattern =>
|
||||
versionsNames.map(
|
||||
versionName => `${versionedDir}/${versionName}/${pattern}`,
|
||||
),
|
||||
),
|
||||
);
|
||||
)
|
||||
.reduce((a, b) => a.concat(b), []);
|
||||
const sidebarsGlob = versionsNames.map(
|
||||
versionName => `${versionedSidebarsDir}/${versionName}-sidebars.json`,
|
||||
);
|
||||
|
@ -149,11 +151,11 @@ export default function pluginContentDocs(
|
|||
|
||||
// Metadata for versioned docs.
|
||||
if (versioning.enabled) {
|
||||
const versionedGlob = _.flatten(
|
||||
include.map(pattern =>
|
||||
const versionedGlob = include
|
||||
.map(pattern =>
|
||||
versionsNames.map(versionName => `${versionName}/${pattern}`),
|
||||
),
|
||||
);
|
||||
)
|
||||
.reduce((a, b) => a.concat(b), []);
|
||||
const versionedFiles = await globby(versionedGlob, {
|
||||
cwd: versionedDir,
|
||||
});
|
||||
|
@ -338,7 +340,7 @@ export default function pluginContentDocs(
|
|||
// If versioning is enabled, we cleverly chunk the generated routes
|
||||
// to be by version and pick only needed base metadata.
|
||||
if (versioning.enabled) {
|
||||
const docsMetadataByVersion = _.groupBy(
|
||||
const docsMetadataByVersion = groupBy(
|
||||
Object.values(content.docsMetadata),
|
||||
'version',
|
||||
);
|
||||
|
@ -358,13 +360,12 @@ export default function pluginContentDocs(
|
|||
const neededSidebars: Set<string> =
|
||||
content.versionToSidebars[version] || new Set();
|
||||
const docsBaseMetadata: DocsBaseMetadata = {
|
||||
docsSidebars: _.pick(
|
||||
docsSidebars: pick(
|
||||
content.docsSidebars,
|
||||
Array.from(neededSidebars),
|
||||
),
|
||||
permalinkToSidebar: _.pickBy(
|
||||
content.permalinkToSidebar,
|
||||
sidebar => neededSidebars.has(sidebar),
|
||||
permalinkToSidebar: pickBy(content.permalinkToSidebar, sidebar =>
|
||||
neededSidebars.has(sidebar),
|
||||
),
|
||||
version,
|
||||
};
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import _ from 'lodash';
|
||||
import flatMap from 'lodash.flatmap';
|
||||
import fs from 'fs-extra';
|
||||
import importFresh from 'import-fresh';
|
||||
import {
|
||||
|
@ -106,12 +106,12 @@ function normalizeItem(item: SidebarItemRaw): SidebarItem[] {
|
|||
];
|
||||
}
|
||||
if (isCategoryShorthand(item)) {
|
||||
return _.flatMap(normalizeCategoryShorthand(item), normalizeItem);
|
||||
return flatMap(normalizeCategoryShorthand(item), normalizeItem);
|
||||
}
|
||||
switch (item.type) {
|
||||
case 'category':
|
||||
assertIsCategory(item);
|
||||
return [{...item, items: _.flatMap(item.items, normalizeItem)}];
|
||||
return [{...item, items: flatMap(item.items, normalizeItem)}];
|
||||
case 'link':
|
||||
assertIsLink(item);
|
||||
return [item];
|
||||
|
@ -134,7 +134,7 @@ function normalizeSidebar(sidebars: SidebarRaw): Sidebar {
|
|||
? sidebar
|
||||
: normalizeCategoryShorthand(sidebar);
|
||||
|
||||
acc[sidebarId] = _.flatMap(normalizedSidebar, normalizeItem);
|
||||
acc[sidebarId] = flatMap(normalizedSidebar, normalizeItem);
|
||||
|
||||
return acc;
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue