Skip to content

Commit

Permalink
Add input to configure cache dir (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudLigny authored May 14, 2021
1 parent 250db39 commit 378e11e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
root = true

[*]
indent_style = tab
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,16 @@ Add the plugin in `package.json`:
```bash
npm install -D netlify-plugin-cecil-cache
```

### Custom cache directory

```toml
[build]
publish = "_site"

[[plugins]]
package = "netlify-plugin-cecil-cache"

[plugins.inputs]
cacheDir = ".cache"
```
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const path = require('path');
const cacheDir = inputs.cacheDir || env.CECIL_CACHE_DIR || '.cache';

const getCacheDirs = (constants) => [
constants.PUBLISH_DIR,
path.normalize(`${constants.PUBLISH_DIR}/../.cache`),
cacheDir
];

module.exports = {
async onPreBuild({ constants, utils }) {
async onPreBuild({constants, utils}) {
if (process.cwd() === constants.PUBLISH_DIR) {
utils.build.failBuild(
`Your site’s publish directory is not set correctly (“${constants.PUBLISH_DIR}”).`
Expand All @@ -21,7 +22,7 @@ module.exports = {
console.log('Cecil cache not found.');
}
},
async onPostBuild({ constants, utils }) {
async onPostBuild({constants, utils}) {
const cacheDirs = getCacheDirs(constants);

if (await utils.cache.save(cacheDirs)) {
Expand Down
4 changes: 3 additions & 1 deletion manifest.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
name: netlify-plugin-cecil-cache
inputs: []
inputs:
- name: cacheDir
description: Cache directory, relative to publish directory (default is `.cache`).
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "netlify-plugin-cecil-cache",
"version": "0.1.2",
"version": "0.2.0",
"description": "Persist the Cecil cache between Netlify builds.",
"main": "index.js",
"repository": "https://github.com/Cecilapp/netlify-plugin-cecil-cache.git",
Expand All @@ -13,6 +13,5 @@
"netlify",
"netlify-plugin",
"cecil"
],
"dependencies": {}
]
}

0 comments on commit 378e11e

Please sign in to comment.