mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-01 16:00:29 +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",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue