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

Commit

Permalink
fix(config): watching changes in config files with reload in develop …
Browse files Browse the repository at this point in the history
…mode
  • Loading branch information
filipowm committed Jun 3, 2020
1 parent 7e5ea1e commit 85ce5db
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 85 deletions.
4 changes: 3 additions & 1 deletion config/config-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ class EnvReader extends ConfigReader {
const read = () => {
const fileConfig = new FileReader().read()
const envConfig = new EnvReader().read()
let config = _.merge(defaults, fileConfig);
const def = _.cloneDeep(defaults)

let config = _.merge(def, fileConfig);
config = _.merge(config, envConfig);
postProcessConfig(config);
return config;
Expand Down
82 changes: 0 additions & 82 deletions config/config.js

This file was deleted.

2 changes: 1 addition & 1 deletion config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
pathPrefix: "/"
ogImage:
docsLocation: https://github.com/filipowm/gatsby-gitbook-starter
docsLocationType: git
docsLocationType: github
editable: true
favicon: "/assets/favicon.png"
themeColor: "#ff0000"
Expand Down
11 changes: 11 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const componentWithMDXScope = require("gatsby-plugin-mdx/component-with-mdx-scope");
const path = require("path");
const startCase = require("lodash.startcase");
const chokidar = require(`chokidar`)
const touch = require("./src/utils/fileUtils")

exports.createSchemaCustomization = ({ actions, schema }) => {
const { createTypes } = actions;
Expand Down Expand Up @@ -133,3 +135,12 @@ exports.onCreateNode = ({ node, getNode, actions }) => {
});
}
};

exports.onPreBootstrap = () => {
const watcher = chokidar.watch("./config", {
ignored: ["jargon*"],
})
watcher.on(`change`, path => {
touch("./gatsby-config.js")
})
}
2 changes: 1 addition & 1 deletion src/utils/algolia.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const config = require("../../config/config.js");
const config = require("../../.generated.config.js");

const pageQuery = `{
pages: allMdx {
Expand Down
18 changes: 18 additions & 0 deletions src/utils/fileUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { close, open, utimes } = require('fs');

const touch = path => {
return new Promise((resolve, reject) => {
const time = new Date();
utimes(path, time, time, err => {
if (err) {
return open(path, 'w', (err, fd) => {
if (err) return reject(err);
close(fd, err => (err ? reject(err) : resolve(fd)));
});
}
resolve();
});
});
};

module.exports = touch;

0 comments on commit 85ce5db

Please sign in to comment.