1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2026-01-15 08:02:56 -05:00

extracted & published netlify-plugin-cache on NPM: https://github.com/jakejarvis/netlify-plugin-cache

This commit is contained in:
2020-06-06 10:22:14 -04:00
parent fd06f71df4
commit 04ac760629
5 changed files with 29 additions and 52 deletions

View File

@@ -1,30 +0,0 @@
// 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 {
console.log(`Failed caching ${inputs.paths.join(', ')}. :(`)
}
},
}

View File

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