Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Commit

Permalink
feat(config): ✨ add support for using yaml configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
filipowm committed Jun 3, 2020
1 parent 4dce8bb commit 6baf02e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion config/config-reader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require("fs")
const _ = require("lodash");
const yaml = require('js-yaml')

const defaults = {
"metadata": {
Expand Down Expand Up @@ -80,7 +81,13 @@ class FileReader extends ConfigReader {

readPath(path) {
try {
return require(path);
if (path.endsWith(".yml") || path.endsWith(".yaml")) {
const fileContents = fs.readFileSync(path, 'utf8');
return yaml.safeLoad(fileContents);
} else if (path.endsWith(".json")) {
return require(path);
}
throw "Config file must be either YAML or JSON"
} catch(err) {
console.error(err)
return {};
Expand Down
2 changes: 2 additions & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
metadata:
docsLocation: "https://github.com/hasura/gatsby-gitbook-starter"

0 comments on commit 6baf02e

Please sign in to comment.