feat(v2): option and config validation life cycle method for official plugins (#2943)

* add validation for blog plugin

* fix wrong default component

* fix test and add yup to package.json

* remove console.log

* add validation for classic theme and code block theme

* add yup to packages

* remove console.log

* fix build

* fix logo required

* replaced yup with joi

* fix test

* remove hapi from docusuars core

* replace joi with @hapi/joi

* fix eslint

* fix remark plugin type

* change remark plugin validation to match documentation

* move schema to it's own file

* allow unknown only on outer theme object

* fix type for schema type

* fix yarn.lock

* support both commonjs and ES modules

* add docs for new lifecycle method
This commit is contained in:
Anshul Goyal 2020-06-24 23:38:16 +05:30 committed by GitHub
parent ce10646606
commit 81d855355e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 490 additions and 63 deletions

View file

@ -9,6 +9,16 @@ import fs from 'fs-extra';
import path from 'path';
import pluginContentBlog from '../index';
import {DocusaurusConfig, LoadContext} from '@docusaurus/types';
import {PluginOptionSchema} from '../validation';
function validateAndNormalize(schema, options) {
const {value, error} = schema.validate(options);
if (error) {
throw error;
} else {
return value;
}
}
describe('loadBlog', () => {
const siteDir = path.join(__dirname, '__fixtures__', 'website');
@ -26,11 +36,11 @@ describe('loadBlog', () => {
siteConfig,
generatedFilesDir,
} as LoadContext,
{
validateAndNormalize(PluginOptionSchema, {
path: pluginPath,
editUrl:
'https://github.com/facebook/docusaurus/edit/master/website-1x',
},
}),
);
const {blogPosts} = await plugin.loadContent();