-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (34 loc) · 1.6 KB
/
index.js
File metadata and controls
37 lines (34 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Netlify Plugin: netlify-plugin-cache
// https://github.com/jakejarvis/netlify-plugin-cache
//
// This plugin is essentially a wrapper around Netlify's native `cache-utils`:
// 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 configuration.')
console.log('More details: https://jrvs.io/netlify-cache-usage')
}
}
}