1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-07-04 11:36:37 -04:00

test cache plugin for Netlify

This commit is contained in:
2020-06-05 17:29:22 -04:00
parent 85fe0084b8
commit eafbf87f49
6 changed files with 47 additions and 1 deletions

View File

@ -0,0 +1,27 @@
// Based on https://github.com/cdeleeuwe/netlify-plugin-hugo-cache-resources/blob/master/index.js
module.exports = {
async onPreBuild({ utils, inputs }) {
const paths = JSON.parse(inputs.paths);
const success = await utils.cache.restore(paths);
if (success) {
const cachedFiles = await utils.cache.list(paths);
console.log(`Restored cache of '${paths}', totaling ${cachedFiles.length} files.`);
} else {
console.log(`A cache of '${paths}' doesn't exist (yet).`);
}
},
async onPostBuild({ utils, inputs }) {
const paths = JSON.parse(inputs.paths);
const success = await utils.cache.save(paths);
if (success) {
const cachedFiles = await utils.cache.list(paths);
console.log(`Successfully cached '${paths}', totaling ${cachedFiles.length} files.`);
} else {
console.log(`Couldn't cache '${paths}'.`);
}
}
};

View File

@ -0,0 +1,4 @@
name: netlify-plugin-cache
inputs:
- name: paths
description: Array of directories to cache between builds.