Skip to content

Commit

Permalink
feat(okidoc-site): improve site config yaml validation
Browse files Browse the repository at this point in the history
  • Loading branch information
bodia-uz committed Dec 5, 2019
1 parent 5274649 commit 9caeee1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/okidoc-site/site/config/configSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const configSchema = {
algoliaApiKey: Joi.string(),
algoliaIndexName: Joi.string(),
githubLink: Joi.string(),
}),
}).default({}),
mdComponents: Joi.object({
path: Joi.string().required(),
externalStyles: Joi.array().items(Joi.string()),
Expand Down
21 changes: 11 additions & 10 deletions packages/okidoc-site/site/getSiteConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,20 @@ function getEnvVariables(env) {
}

function getConfig(configPath) {
let configRaw;
try {
const config = yaml.load(configPath);

Joi.assert(
config,
configSchema,
`Invalid site config yaml file (${configPath}).`,
);

return config;
configRaw = yaml.load(configPath);
} catch (e) {
throw new Error(`Invalid site config yaml file (${configPath})`);
throw new Error(
`Could not parse site config yaml file (${configPath}): ${e.message}`,
);
}

return Joi.attempt(
configRaw,
configSchema,
`Invalid site config yaml file (${configPath})`,
);
}

const { SITE_YAML_PATH, SITE_CWD } = getEnvVariables(process.env);
Expand Down

0 comments on commit 9caeee1

Please sign in to comment.