netlify-plugin-hugo-cache-resources
Advanced tools
Comparing version 0.2.0 to 0.2.1
33
index.js
const { join } = require("path"); | ||
const glob = require("glob"); | ||
const getResourcesDir = ({ inputs }) => { | ||
return join(inputs.srcdir, 'resources'); | ||
} | ||
return join(inputs.srcdir, "resources"); | ||
}; | ||
const printList = (items) => { | ||
console.log('---'); | ||
console.log("---"); | ||
items.forEach((item, index) => { | ||
console.log(`${index + 1}. ${item}`); | ||
}); | ||
} | ||
}; | ||
module.exports = { | ||
async onPreBuild({ utils, inputs }) { | ||
@@ -23,3 +23,5 @@ const path = getResourcesDir({ inputs }); | ||
const cachedFiles = await utils.cache.list(path); | ||
console.log(`Restored cached resources folder. Total files: ${cachedFiles.length}`); | ||
console.log( | ||
`Restored cached resources folder. Total files: ${cachedFiles.length}` | ||
); | ||
if (inputs.debug) printList(cachedFiles); | ||
@@ -36,9 +38,18 @@ } else { | ||
if (success) { | ||
const cachedFiles = await utils.cache.list(path); | ||
console.log(`Saved resources folder to cache. Total files: ${cachedFiles.length}`); | ||
if (inputs.debug) printList(cachedFiles); | ||
const cached = await utils.cache.list(path); | ||
const files = [ | ||
...new Set( | ||
cached.map((c) => glob.sync(`${c}/**/*`, { nodir: true })).flat() | ||
), | ||
]; | ||
console.log( | ||
`Saved resources folder to cache. Total files: ${files.length}` | ||
); | ||
if (inputs.debug) { | ||
printList(files); | ||
} | ||
} else { | ||
console.log(`No resources folder cached`); | ||
} | ||
} | ||
}; | ||
}, | ||
}; |
{ | ||
"name": "netlify-plugin-hugo-cache-resources", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Persist Hugo resources folder between Netlify builds for huge build speed improvements!", | ||
@@ -16,3 +16,5 @@ "main": "index.js", | ||
], | ||
"dependencies": {} | ||
"dependencies": { | ||
"glob": "^7.1.7" | ||
} | ||
} |
@@ -7,8 +7,8 @@ # Netlify Build Plugin: Persist Hugo resources Between Builds | ||
Note: Restoring cache only comes from the production branch. So once cache is saved on the production branch, the next preview build would use the cache. For example, when pushing to the same preview build, the latest preview build will not get the cache from the previous preview build, but will get it from master. | ||
## Usage | ||
To install, add the following lines to your `netlify.toml` file: | ||
You can install this plugin in the Netlify UI from this [direct in-app installation link](https://app.netlify.com/plugins/netlify-plugin-hugo-cache-resources/install) or from the [Plugins directory](https://app.netlify.com/plugins). | ||
For file-based installation, add the following lines to your `netlify.toml` file: | ||
```toml | ||
@@ -28,2 +28,8 @@ [build] | ||
Note: The `[[plugins]]` line is required for each plugin, even if you have other plugins in your `netlify.toml` file already. | ||
Note: The `[[plugins]]` line is required for each plugin, even if you have other plugins in your `netlify.toml` file already. | ||
To complete file-based installation, from your project's base directory, use npm, yarn, or any other Node.js package manager to add the plugin to `devDependencies` in `package.json`. | ||
```bash | ||
npm install -D netlify-plugin-hugo-cache-resources | ||
``` |
3538
47
34
1
+ Addedglob@^7.1.7
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedwrappy@1.0.2(transitive)