mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-03 12:17:20 +02:00
refactor(v2): plugin, utils as separate package (#1298)
* refactor(v2): plugin, utils as separate package * rename docusaurus-plugin to @docusaurus/plugin * update snapshot
This commit is contained in:
parent
9597a8ce9c
commit
3a7a253db7
24 changed files with 102 additions and 43 deletions
|
@ -8,8 +8,7 @@
|
|||
const globby = require('globby');
|
||||
const path = require('path');
|
||||
const fs = require('fs-extra');
|
||||
// TODO: Do not make it relative because plugins can be from node_modules.
|
||||
const {parse, idx, normalizeUrl} = require('../../lib/load/utils');
|
||||
const {parse, idx, normalizeUrl} = require('@docusaurus/utils');
|
||||
|
||||
function fileToUrl(fileName) {
|
||||
return fileName
|
12
packages/docusaurus-plugin-content-blog/package.json
Normal file
12
packages/docusaurus-plugin-content-blog/package.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"name": "@docusaurus/plugin-content-blog",
|
||||
"version": "1.0.0",
|
||||
"description": "Blog content plugin for Docusaurus",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@docusaurus/utils": "^1.0.0",
|
||||
"fs-extra": "^7.0.1",
|
||||
"globby": "^9.1.0"
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import path from 'path';
|
||||
|
||||
import loadSetup from '../../../test/loadSetup';
|
||||
import loadSetup from '../../docusaurus/test/loadSetup';
|
||||
import DocusaurusPluginContentPages from '../index';
|
||||
|
||||
describe('docusaurus-plugin-content-pages', () => {
|
|
@ -9,7 +9,7 @@ const globby = require('globby');
|
|||
const path = require('path');
|
||||
|
||||
// TODO: Do not make it relative because plugins can be from node_modules.
|
||||
const {encodePath, fileToPath, idx} = require('../../lib/load/utils');
|
||||
const {encodePath, fileToPath, idx} = require('@docusaurus/utils');
|
||||
|
||||
const DEFAULT_OPTIONS = {
|
||||
metadataKey: 'pagesMetadata',
|
11
packages/docusaurus-plugin-content-pages/package.json
Normal file
11
packages/docusaurus-plugin-content-pages/package.json
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"name": "@docusaurus/plugin-content-pages",
|
||||
"version": "1.0.0",
|
||||
"description": "Pages content plugin for Docusaurus",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@docusaurus/utils": "^1.0.0",
|
||||
"globby": "^9.1.0"
|
||||
}
|
||||
}
|
12
packages/docusaurus-utils/package.json
Normal file
12
packages/docusaurus-utils/package.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"name": "@docusaurus/utils",
|
||||
"version": "1.0.0",
|
||||
"description": "A set of utility functions for Docusaurus packages",
|
||||
"main": "index.js",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"escape-string-regexp": "^1.0.5",
|
||||
"front-matter": "^2.3.0",
|
||||
"fs-extra": "^7.0.0"
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@ import {
|
|||
idx,
|
||||
getSubFolder,
|
||||
normalizeUrl,
|
||||
} from '@lib/load/utils';
|
||||
} from '../index';
|
||||
|
||||
describe('load utils', () => {
|
||||
test('fileToComponentName', () => {
|
|
@ -7,10 +7,10 @@
|
|||
|
||||
const path = require('path');
|
||||
const globby = require('globby');
|
||||
const {getSubFolder, idx} = require('@docusaurus/utils');
|
||||
const createOrder = require('./order');
|
||||
const loadSidebars = require('./sidebars');
|
||||
const processMetadata = require('./metadata');
|
||||
const {getSubFolder, idx} = require('../utils');
|
||||
|
||||
async function loadDocs({siteDir, docsDir, env, siteConfig}) {
|
||||
// @tested - load all sidebars including versioned sidebars
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const {getSubFolder, idx, parse, normalizeUrl} = require('../utils');
|
||||
const {getSubFolder, idx, parse, normalizeUrl} = require('@docusaurus/utils');
|
||||
|
||||
function getLanguage(filepath, refDir, env) {
|
||||
const translationEnabled = idx(env, ['translation', 'enabled']);
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const {idx} = require('../utils');
|
||||
const {idx} = require('@docusaurus/utils');
|
||||
|
||||
/**
|
||||
* Check that item contains only allowed keys
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const {idx} = require('./utils');
|
||||
const {idx} = require('@docusaurus/utils');
|
||||
const loadConfig = require('./config');
|
||||
|
||||
module.exports = function loadEnv({siteDir, siteConfig}) {
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
const ejs = require('ejs');
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const {generate} = require('@docusaurus/utils');
|
||||
const loadConfig = require('./config');
|
||||
const loadDocs = require('./docs');
|
||||
const loadEnv = require('./env');
|
||||
const loadTheme = require('./theme');
|
||||
const {generate} = require('./utils');
|
||||
const loadRoutes = require('./routes');
|
||||
const constants = require('../constants');
|
||||
|
||||
|
@ -75,26 +75,23 @@ module.exports = async function load(siteDir) {
|
|||
const context = {env, siteDir, siteConfig};
|
||||
|
||||
// Initialize plugins.
|
||||
const pluginDir = path.resolve(__dirname, '../../plugins');
|
||||
const plugins = pluginConfigs.map(
|
||||
({name, path: pluginPath = path.join(pluginDir, name), options}) => {
|
||||
let Plugin;
|
||||
// If it exist in provided path or official plugin directory
|
||||
if (pluginPath && fs.existsSync(pluginPath)) {
|
||||
const plugins = pluginConfigs.map(({name, path: pluginPath, options}) => {
|
||||
let Plugin;
|
||||
// If path itself is provided
|
||||
if (pluginPath && fs.existsSync(pluginPath)) {
|
||||
// eslint-disable-next-line
|
||||
Plugin = require(pluginPath);
|
||||
} else {
|
||||
// Resolve using node_modules as well.
|
||||
try {
|
||||
// eslint-disable-next-line
|
||||
Plugin = require(pluginPath);
|
||||
} else {
|
||||
// Resolve using node_modules as well.
|
||||
try {
|
||||
// eslint-disable-next-line
|
||||
Plugin = require(name);
|
||||
} catch (e) {
|
||||
throw new Error(`'${name}' plugin cannot be found.`);
|
||||
}
|
||||
Plugin = require(name);
|
||||
} catch (e) {
|
||||
throw new Error(`'${name}' plugin cannot be found.`);
|
||||
}
|
||||
return new Plugin(options, context);
|
||||
},
|
||||
);
|
||||
}
|
||||
return new Plugin(options, context);
|
||||
});
|
||||
|
||||
// Plugin lifecycle - loadContents().
|
||||
// Currently plugins run lifecycle in parallel and are not order-dependent. We could change
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const {normalizeUrl} = require('./utils');
|
||||
const {normalizeUrl} = require('@docusaurus/utils');
|
||||
|
||||
async function loadRoutes({
|
||||
siteConfig = {},
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
"@babel/polyfill": "^7.0.0",
|
||||
"@babel/preset-env": "^7.0.0",
|
||||
"@babel/preset-react": "^7.0.0",
|
||||
"@docusaurus/utils": "^1.0.0",
|
||||
"@mapbox/rehype-prism": "^0.3.1",
|
||||
"@mdx-js/loader": "^0.20.1",
|
||||
"@mdx-js/mdx": "^0.20.1",
|
||||
|
@ -46,7 +47,6 @@
|
|||
"css-loader": "^1.0.0",
|
||||
"docsearch.js": "^2.5.2",
|
||||
"ejs": "^2.6.1",
|
||||
"escape-string-regexp": "^1.0.5",
|
||||
"front-matter": "^2.3.0",
|
||||
"fs-extra": "^7.0.0",
|
||||
"globby": "^8.0.1",
|
||||
|
|
|
@ -20,7 +20,7 @@ module.exports = {
|
|||
favicon: 'img/docusaurus.ico',
|
||||
plugins: [
|
||||
{
|
||||
name: 'docusaurus-plugin-content-pages',
|
||||
name: '@docusaurus/plugin-content-pages',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
|
@ -20,7 +20,7 @@ module.exports = {
|
|||
favicon: 'img/docusaurus.ico',
|
||||
plugins: [
|
||||
{
|
||||
name: 'docusaurus-plugin-content-pages',
|
||||
name: '@docusaurus/plugin-content-pages',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
|
@ -21,7 +21,7 @@ module.exports = {
|
|||
favicon: 'img/docusaurus.ico',
|
||||
plugins: [
|
||||
{
|
||||
name: 'docusaurus-plugin-content-pages',
|
||||
name: '@docusaurus/plugin-content-pages',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
|
@ -21,7 +21,7 @@ module.exports = {
|
|||
favicon: 'img/docusaurus.ico',
|
||||
plugins: [
|
||||
{
|
||||
name: 'docusaurus-plugin-content-pages',
|
||||
name: '@docusaurus/plugin-content-pages',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
|
@ -20,7 +20,7 @@ module.exports = {
|
|||
favicon: 'img/docusaurus.ico',
|
||||
plugins: [
|
||||
{
|
||||
name: 'docusaurus-plugin-content-pages',
|
||||
name: '@docusaurus/plugin-content-pages',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
|
@ -36,7 +36,7 @@ Object {
|
|||
"organizationName": "endiliey",
|
||||
"plugins": Array [
|
||||
Object {
|
||||
"name": "docusaurus-plugin-content-pages",
|
||||
"name": "@docusaurus/plugin-content-pages",
|
||||
},
|
||||
],
|
||||
"projectName": "hello",
|
||||
|
|
|
@ -31,14 +31,14 @@ module.exports = {
|
|||
},
|
||||
plugins: [
|
||||
{
|
||||
name: 'docusaurus-plugin-content-blog',
|
||||
name: '@docusaurus/plugin-content-blog',
|
||||
options: {
|
||||
include: ['*.md', '*.mdx'],
|
||||
path: '../v1/website/blog',
|
||||
path: '../website-1.x/blog',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'docusaurus-plugin-content-pages',
|
||||
name: '@docusaurus/plugin-content-pages',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
"deploy": "docusaurus deploy"
|
||||
},
|
||||
"dependencies": {
|
||||
"@docusaurus/plugin-content-blog": "^1.0.0",
|
||||
"@docusaurus/plugin-content-pages": "^1.0.0",
|
||||
"classnames": "^2.2.6",
|
||||
"docusaurus-2": "^2.0.0",
|
||||
"react-youtube": "^7.9.0",
|
||||
|
|
34
yarn.lock
34
yarn.lock
|
@ -1729,7 +1729,7 @@
|
|||
resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7"
|
||||
integrity sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g==
|
||||
|
||||
"@types/glob@*":
|
||||
"@types/glob@*", "@types/glob@^7.1.1":
|
||||
version "7.1.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575"
|
||||
integrity sha512-1Bh06cbWJUHMC97acuD6UMG29nMt0Aqz1vF3guLfG+kHHJhy3AyohZFFxYk2f7Q1SQIrNwvncxAE0N/9s70F2w==
|
||||
|
@ -2341,7 +2341,7 @@ array-reduce@~0.0.0:
|
|||
resolved "https://registry.yarnpkg.com/array-reduce/-/array-reduce-0.0.0.tgz#173899d3ffd1c7d9383e4479525dbe278cab5f2b"
|
||||
integrity sha1-FziZ0//Rx9k4PkR5Ul2+J4yrXys=
|
||||
|
||||
array-union@^1.0.1:
|
||||
array-union@^1.0.1, array-union@^1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/array-union/-/array-union-1.0.2.tgz#9a34410e4f4e3da23dea375be5be70f24778ec39"
|
||||
integrity sha1-mjRBDk9OPaI96jdb5b5w8kd47Dk=
|
||||
|
@ -4498,6 +4498,13 @@ dir-glob@2.0.0:
|
|||
arrify "^1.0.1"
|
||||
path-type "^3.0.0"
|
||||
|
||||
dir-glob@^2.2.1:
|
||||
version "2.2.2"
|
||||
resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-2.2.2.tgz#fa09f0694153c8918b18ba0deafae94769fc50c4"
|
||||
integrity sha512-f9LBi5QWzIW3I6e//uxZoLBlUt9kcp66qo0sSCxL6YZKc75R1c4MFCoe/LaZiBGmgujvQdxc5Bn3QhfyvK5Hsw==
|
||||
dependencies:
|
||||
path-type "^3.0.0"
|
||||
|
||||
docsearch.js@^2.5.2:
|
||||
version "2.6.2"
|
||||
resolved "https://registry.yarnpkg.com/docsearch.js/-/docsearch.js-2.6.2.tgz#cb36a97aeac8a8d31eed5915cdee808a2248b41c"
|
||||
|
@ -5378,7 +5385,7 @@ fast-deep-equal@^2.0.1:
|
|||
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49"
|
||||
integrity sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=
|
||||
|
||||
fast-glob@^2.0.2:
|
||||
fast-glob@^2.0.2, fast-glob@^2.2.6:
|
||||
version "2.2.6"
|
||||
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-2.2.6.tgz#a5d5b697ec8deda468d85a74035290a025a95295"
|
||||
integrity sha512-0BvMaZc1k9F+MeWWMe8pL6YltFzZYcJsYU7D4JyDA6PAczaXvxqQQ/z+mDF7/4Mw01DeUc+i3CTKajnkANkV4w==
|
||||
|
@ -5703,7 +5710,7 @@ fs-extra@^5.0.0:
|
|||
jsonfile "^4.0.0"
|
||||
universalify "^0.1.0"
|
||||
|
||||
fs-extra@^7.0.0:
|
||||
fs-extra@^7.0.0, fs-extra@^7.0.1:
|
||||
version "7.0.1"
|
||||
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9"
|
||||
integrity sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==
|
||||
|
@ -6012,6 +6019,20 @@ globby@^8.0.1:
|
|||
pify "^3.0.0"
|
||||
slash "^1.0.0"
|
||||
|
||||
globby@^9.1.0:
|
||||
version "9.1.0"
|
||||
resolved "https://registry.yarnpkg.com/globby/-/globby-9.1.0.tgz#e90f4d5134109e6d855abdd31bdb1b085428592e"
|
||||
integrity sha512-VtYjhHr7ncls724Of5W6Kaahz0ag7dB4G62/2HsN+xEKG6SrPzM1AJMerGxQTwJGnN9reeyxdvXbuZYpfssCvg==
|
||||
dependencies:
|
||||
"@types/glob" "^7.1.1"
|
||||
array-union "^1.0.2"
|
||||
dir-glob "^2.2.1"
|
||||
fast-glob "^2.2.6"
|
||||
glob "^7.1.3"
|
||||
ignore "^4.0.3"
|
||||
pify "^4.0.1"
|
||||
slash "^2.0.0"
|
||||
|
||||
globule@^1.0.0:
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/globule/-/globule-1.2.1.tgz#5dffb1b191f22d20797a9369b49eab4e9839696d"
|
||||
|
@ -6570,6 +6591,11 @@ ignore@^3.3.3, ignore@^3.3.5:
|
|||
resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.10.tgz#0a97fb876986e8081c631160f8f9f389157f0043"
|
||||
integrity sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug==
|
||||
|
||||
ignore@^4.0.3:
|
||||
version "4.0.6"
|
||||
resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc"
|
||||
integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==
|
||||
|
||||
imagemin-gifsicle@^6.0.1:
|
||||
version "6.0.1"
|
||||
resolved "https://registry.yarnpkg.com/imagemin-gifsicle/-/imagemin-gifsicle-6.0.1.tgz#6abad4e95566d52e5a104aba1c24b4f3b48581b3"
|
||||
|
|
Loading…
Add table
Reference in a new issue