1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-04-27 17:30:28 -04:00

test cache plugin default [skip ci]

This commit is contained in:
Jake Jarvis 2020-06-06 10:53:19 -04:00
parent 04ac760629
commit 74e19308d9
Signed by: jake
GPG Key ID: 2B0C9CF251E69A39
3 changed files with 41 additions and 3 deletions

View File

@ -39,9 +39,9 @@
# Cache resoures between builds, see plugins/netlify-plugin-cache/index.js
[[plugins]]
package = "netlify-plugin-cache"
[plugins.inputs]
paths = ["resources", "_vendor"]
package = "./plugins/netlify-plugin-cache"
# [plugins.inputs]
# paths = ["resources", "_vendor"]
[[plugins]]
package = "netlify-plugin-debug-cache"

View File

@ -0,0 +1,33 @@
// https://github.com/netlify/build/blob/master/packages/cache-utils/README.md
module.exports = {
// try to restore cache before build begins, if it exists
onPreBuild: async ({ utils: { cache }, inputs }) => {
if (await cache.restore(inputs.paths)) {
const files = await cache.list(inputs.paths)
console.log(`Successfully restored: ${inputs.paths.join(', ')} ... ${files.length} files in total.`)
} else {
console.log(`A cache of '${inputs.paths.join(', ')}' doesn't exist (yet).`)
}
},
// only save/update cache if build was successful
onSuccess: async ({ utils: { cache, status }, inputs }) => {
if (await cache.save(inputs.paths)) {
const files = await cache.list(inputs.paths)
console.log(`Successfully cached: ${inputs.paths.join(', ')} ... ${files.length} files in total.`)
// show success & more detail in deploy summary
status.show({
title: `${files.length} files cached`,
summary: 'These will be restored on the next build! ⚡',
text: `${inputs.paths.join(', ')}`,
})
} else {
// this probably happened because the default `paths` is set, so provide instructions to fix
console.log(`Attempted to cache: ${inputs.paths.join(', ')} ... but failed. :(`)
console.log(`Try setting the 'paths' input appropriately in your netlify.toml or netlify.yml.`)
console.log(`More details: https://jrvs.io/netlify-cache-usage`)
}
},
}

View File

@ -0,0 +1,5 @@
name: netlify-plugin-cache
inputs:
- name: paths
description: Array of files and/or directories to cache between builds.
default: [".cache"]