mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-03 03:12:35 +02:00
feat: throw error if there is wrong field on siteConfig.js
This commit is contained in:
parent
ef17da741a
commit
9965eec798
4 changed files with 41 additions and 4 deletions
|
@ -18,9 +18,27 @@ module.exports = function loadConfig(siteDir, deleteCache = true) {
|
|||
'projectName',
|
||||
'baseUrl'
|
||||
];
|
||||
const optionalFields = [
|
||||
'customDocsPath',
|
||||
'themePath',
|
||||
'highlight',
|
||||
'markdownPlugins'
|
||||
];
|
||||
const missingFields = requiredFields.filter(field => !config[field]);
|
||||
if (missingFields && missingFields.length > 0) {
|
||||
throw new Error(`${missingFields.join(', ')} are missing in siteConfig.js`);
|
||||
throw new Error(
|
||||
`${missingFields.join(', ')} fields are missing in siteConfig.js`
|
||||
);
|
||||
}
|
||||
|
||||
const uselessFields = Object.keys(config).filter(
|
||||
field => ![...requiredFields, ...optionalFields].includes(field)
|
||||
);
|
||||
if (uselessFields && uselessFields.length > 0) {
|
||||
throw new Error(
|
||||
`${uselessFields.join(', ')} fields are useless in siteConfig.js`
|
||||
);
|
||||
}
|
||||
|
||||
return config;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue