Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Commit

Permalink
Add extraDirsToCache option
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric Delpoux authored and axe312ger committed Feb 26, 2019
1 parent 98fbfaa commit 54df0f8
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ const { resolve, basename } = require(`path`)

const { ensureDir, readdir, copy } = require(`fs-extra`)

async function calculateDirs(store) {
async function calculateDirs(store, extraDirsToCache = []) {
const program = store.getState().program

const dirsToCache = [
resolve(program.directory, `public`),
resolve(program.directory, `.cache`)
...extraDirsToCache.map(dirToCache =>
resolve(program.directory, dirToCache)
),
]

for (const dir of dirsToCache) {
Expand All @@ -28,12 +31,12 @@ async function calculateDirs(store) {
}
}

exports.onPreInit = async function({ store }) {
exports.onPreInit = async function({ store }, { extraDirsToCache }) {
if (!process.env.NETLIFY_BUILD_BASE) {
return
}

const { dirsToCache, netlifyCacheDir } = await calculateDirs(store)
const { dirsToCache, netlifyCacheDir } = await calculateDirs(store, extraDirsToCache)

for (const dirPath of dirsToCache) {
const dirName = basename(dirPath)
Expand All @@ -56,12 +59,12 @@ exports.onPreInit = async function({ store }) {
console.log(`plugin-netlify-cache: Netlify cache restored`)
}

exports.onPostBuild = async function({ store }) {
exports.onPostBuild = async function({ store }, { extraDirsToCache }) {
if (!process.env.NETLIFY_BUILD_BASE) {
return
}

const { dirsToCache, netlifyCacheDir } = await calculateDirs(store)
const { dirsToCache, netlifyCacheDir } = await calculateDirs(store, extraDirsToCache)

for (const dirPath of dirsToCache) {
const dirName = basename(dirPath)
Expand Down

0 comments on commit 54df0f8

Please sign in to comment.