Skip to content

Commit

Permalink
[1.0] During bootstrap, detect if plugins have changed and delete the…
Browse files Browse the repository at this point in the history
… cache (#927)

* Run format

* Move out console.log override helper to own module

* Extract plugin loading logic to its own module

* Fix format for www and examples

* Move js page creation to own module

* Delete the cache if any of the site's plugins or options have changed

* Add notice when the site's cache is deleted

* Fix source-drupal plugin
  • Loading branch information
KyleAMathews committed May 6, 2017
1 parent e4457d1 commit d327f16
Show file tree
Hide file tree
Showing 34 changed files with 405 additions and 260 deletions.
11 changes: 6 additions & 5 deletions examples/gatsbygram/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const _ = require("lodash")
const Promise = require("bluebird")
const path = require("path")
const slug = require("slug")
const slash = require("slash")
const _ = require(`lodash`)
const Promise = require(`bluebird`)
const path = require(`path`)
const slug = require(`slug`)
const slash = require(`slash`)

// Implement the Gatsby API “createPages”. This is
// called after the Gatsby bootstrap is finished so you have
Expand Down Expand Up @@ -61,6 +61,7 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
},
})
})

resolve()
})
})
Expand Down
8 changes: 4 additions & 4 deletions examples/hn/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const _ = require("lodash")
const Promise = require("bluebird")
const path = require("path")
const slash = require("slash")
const _ = require(`lodash`)
const Promise = require(`bluebird`)
const path = require(`path`)
const slash = require(`slash`)

// Implement the Gatsby API “createPages”. This is
// called after the Gatsby bootstrap is finished so you have
Expand Down
8 changes: 4 additions & 4 deletions examples/using-drupal/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const _ = require("lodash")
const Promise = require("bluebird")
const path = require("path")
const slash = require("slash")
const _ = require(`lodash`)
const Promise = require(`bluebird`)
const path = require(`path`)
const slash = require(`slash`)

// Implement the Gatsby API “createPages”. This is
// called after the Gatsby bootstrap is finished so you have
Expand Down
9 changes: 6 additions & 3 deletions examples/using-drupal/src/templates/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ class ArticleTemplate extends React.Component {
body = article.body.value

// Split text on new lnes and put into paragraph elements.
paragraphedBody = body.split(`\n`).map(split => {
return `<p>${split}</p>`
}).join(``)
paragraphedBody = body
.split(`\n`)
.map(split => {
return `<p>${split}</p>`
})
.join(``)
}
return (
<div>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
"lint:flow": "babel-node scripts/flow-check.js",
"format-packages": "prettier-eslint --write \"packages/**/src/*.js\"",
"format-gatsby": "prettier-eslint --write \"packages/gatsby/lib/**/*.js\"",
"format-www": "prettier-eslint --write \"www/src/**/*.js\"",
"format-examples": "prettier-eslint --write \"examples/**/src/**/*.js\"",
"format-www": "prettier-eslint --write \"www/*.js\" \"www/src/**/*.js\"",
"format-examples": "prettier-eslint --write \"examples/**/gatsby-node.js\" \"examples/**/src/**/*.js\"",
"format-scripts": "prettier-eslint --write \"scripts/**/*.js\"",
"format": "npm run format-packages && npm run format-gatsby && npm run format-www && npm run format-examples && npm run format-scripts",
"publish-canary": "lerna run build; lerna publish --canary --yes",
Expand Down
3 changes: 2 additions & 1 deletion packages/gatsby-dev-cli/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const argv = require(`yargs`)
You typically only need to configure this once.`
)
.help(`h`)
.alias(`h`, `help`).array(`packages`).argv
.alias(`h`, `help`)
.array(`packages`).argv

const conf = new Configstore(pkg.name)

Expand Down
43 changes: 23 additions & 20 deletions packages/gatsby-plugin-sharp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ async function responsiveSizes({ file, args = {} }) {
const fallbackSrc = _.minBy(images, image =>
Math.abs(options.maxWidth - image.width)
).src
const srcSet = images.map(image => `${image.src} ${Math.round(image.width)}w`)
const srcSet = images
.map(image => `${image.src} ${Math.round(image.width)}w`)
.join(`,\n`)

return {
Expand Down Expand Up @@ -405,25 +406,27 @@ async function responsiveResolution({ file, args = {} }) {
const base64Image = await base64({ file })

const fallbackSrc = images[0].src
const srcSet = images.map((image, i) => {
let resolution
switch (i) {
case 0:
resolution = `1x`
break
case 1:
resolution = `1.5x`
break
case 2:
resolution = `2x`
break
case 3:
resolution = `3x`
break
default:
}
return `${image.src} ${resolution}`
}).join(`,`)
const srcSet = images
.map((image, i) => {
let resolution
switch (i) {
case 0:
resolution = `1x`
break
case 1:
resolution = `1.5x`
break
case 2:
resolution = `2x`
break
case 3:
resolution = `3x`
break
default:
}
return `${image.src} ${resolution}`
})
.join(`,`)

return {
base64: base64Image.src,
Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby-remark-copy-linked-files/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ module.exports = ({ files, markdownNode, markdownAST, getNode }) => {
`public`,
`${linkNode.contentDigest}.${linkNode.extension}`
)
const relativePath = path.join(`/${linkNode.contentDigest}.${linkNode.extension}`)
const relativePath = path.join(
`/${linkNode.contentDigest}.${linkNode.extension}`
)
link.url = `${relativePath}`
if (!fsExtra.existsSync(newPath)) {
fsExtra.copy(linkPath, newPath, err => {
Expand Down
6 changes: 3 additions & 3 deletions packages/gatsby-remark-responsive-image/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ module.exports = ({
const fallbackSrc = _.minBy(images, image =>
Math.abs(options.maxWidth - image.width)
).src
const srcSet = images.map(
image => `${image.src} ${Math.round(image.width)}w`
).join(`,`)
const srcSet = images
.map(image => `${image.src} ${Math.round(image.width)}w`)
.join(`,`)

// TODO
// add support for sub-plugins having a gatsby-node.js so can add a
Expand Down
11 changes: 7 additions & 4 deletions packages/gatsby-source-drupal/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ exports.sourceNodes = async (
console.time(`fetch Drupal data`)
console.log(`Starting to fetch data from Drupal`)

const lastFetched = store.getState().status[`gatsby-source-drupal`]
.lastFetched
const lastFetched = store.getState().status.sourcePlugins[
`gatsby-source-drupal`
].lastFetched

let url
if (lastFetched) {
Expand Down Expand Up @@ -104,7 +105,8 @@ exports.sourceNodes = async (
// Get content digest of node.
const contentDigest = crypto
.createHash(`md5`)
.update(JSON.stringify(gatsbyNode)).digest(`hex`)
.update(JSON.stringify(gatsbyNode))
.digest(`hex`)

gatsbyNode.contentDigest = contentDigest

Expand Down Expand Up @@ -145,7 +147,8 @@ exports.sourceNodes = async (
// Get content digest of node.
const contentDigest = crypto
.createHash(`md5`)
.update(JSON.stringify(gatsbyUser)).digest(`hex`)
.update(JSON.stringify(gatsbyUser))
.digest(`hex`)

gatsbyUser.contentDigest = contentDigest

Expand Down
15 changes: 11 additions & 4 deletions packages/gatsby-source-hacker-news/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const url = require(`url`)
const _ = require(`lodash`)

const get = query => {
return axios.get(`https://www.graphqlhub.com/graphql?query=${encodeURIComponent(query)}`)
return axios.get(
`https://www.graphqlhub.com/graphql?query=${encodeURIComponent(query)}`
)
}

exports.sourceNodes = async ({
Expand All @@ -20,7 +22,9 @@ exports.sourceNodes = async ({

// Do the initial fetch
console.time(`fetch HN data`)
console.log(`starting to fetch data from the Hacker News GraphQL API. Warning, this can take a long time e.g. 10-20 seconds`)
console.log(
`starting to fetch data from the Hacker News GraphQL API. Warning, this can take a long time e.g. 10-20 seconds`
)
const result = await get(`
{
hn {
Expand Down Expand Up @@ -114,7 +118,8 @@ fragment commentsFragment on HackerNewsItem {
// Get content digest of node.
const contentDigest = crypto
.createHash(`md5`)
.update(JSON.stringify(storyNode)).digest(`hex`)
.update(JSON.stringify(storyNode))
.digest(`hex`)

storyNode.contentDigest = contentDigest

Expand All @@ -139,7 +144,9 @@ fragment commentsFragment on HackerNewsItem {
const nodeStr = JSON.stringify(commentNode)

// Get content digest of comment node.
const contentDigest = crypto.createHash(`md5`).update(nodeStr)
const contentDigest = crypto
.createHash(`md5`)
.update(nodeStr)
.digest(`hex`)

commentNode.contentDigest = contentDigest
Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby-transformer-remark/src/on-node-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ module.exports = async function onNodeCreate({

const content = await loadNodeContent(node)
const data = grayMatter(content)
const contentDigest = crypto.createHash(`md5`).update(JSON.stringify(data))
const contentDigest = crypto
.createHash(`md5`)
.update(JSON.stringify(data))
.digest(`hex`)
const markdownNode = {
id: `${node.id} >>> MarkdownRemark`,
Expand Down
Loading

0 comments on commit d327f16

Please sign in to comment.