Skip to content

Commit

Permalink
fix(gatsby-source-filesystem): fix add/change text (#20188)
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet committed Dec 20, 2019
1 parent 84139bf commit 0fda1e6
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions packages/gatsby-source-filesystem/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ const createFSMachine = (
)
}

const log = expr => (ctx, action, meta) => {
if (meta.state.matches(`BOOTSTRAP.BOOTSTRAPPED`)) {
reporter.info(expr(ctx, action, meta))
}
}

const fsMachine = Machine(
{
id: `fs`,
Expand Down Expand Up @@ -85,9 +91,32 @@ const createFSMachine = (
},
READY: {
on: {
CHOKIDAR_ADD: { actions: `createAndProcessNode` },
CHOKIDAR_CHANGE: { actions: `createAndProcessNode` },
CHOKIDAR_UNLINK: { actions: `deletePathNode` },
CHOKIDAR_ADD: {
actions: [
`createAndProcessNode`,
log(
(_, { pathType, path }) => `added ${pathType} at ${path}`
),
],
},
CHOKIDAR_CHANGE: {
actions: [
`createAndProcessNode`,
log(
(_, { pathType, path }) =>
`changed ${pathType} at ${path}`
),
],
},
CHOKIDAR_UNLINK: {
actions: [
`deletePathNode`,
log(
(_, { pathType, path }) =>
`deleted ${pathType} at ${path}`
),
],
},
},
},
},
Expand All @@ -96,16 +125,10 @@ const createFSMachine = (
},
{
actions: {
createAndProcessNode(_, { pathType, path }, { state }) {
if (state.matches(`BOOTSTRAP.BOOTSTRAPPED`)) {
reporter.info(`added ${pathType} at ${path}`)
}
createAndProcessNode(_, { pathType, path }) {
createAndProcessNode(path).catch(err => reporter.error(err))
},
deletePathNode(_, { pathType, path }, { state }) {
if (state.matches(`BOOTSTRAP.BOOTSTRAPPED`)) {
reporter.info(`${pathType} deleted at ${path}`)
}
deletePathNode(path)
},
flushPathQueue(_, { resolve, reject }) {
Expand All @@ -128,11 +151,8 @@ exports.sourceNodes = (api, pluginOptions) => {
if (!fs.existsSync(pluginOptions.path)) {
api.reporter.panic(`
The path passed to gatsby-source-filesystem does not exist on your file system:
${pluginOptions.path}
Please pick a path to an existing directory.
See docs here - https://www.gatsbyjs.org/packages/gatsby-source-filesystem/
`)
}
Expand Down

0 comments on commit 0fda1e6

Please sign in to comment.