From 378e11e5e2f725d9fa90a9f86d45dd51fd338de5 Mon Sep 17 00:00:00 2001 From: Arnaud Ligny Date: Sat, 15 May 2021 00:13:07 +0200 Subject: [PATCH] Add input to configure cache dir (#6) --- .editorconfig | 3 ++- README.md | 13 +++++++++++++ index.js | 7 ++++--- manifest.yml | 4 +++- package.json | 5 ++--- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.editorconfig b/.editorconfig index aaac325..c6c8b36 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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 diff --git a/README.md b/README.md index 1ff07e5..6bda660 100644 --- a/README.md +++ b/README.md @@ -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" +``` diff --git a/index.js b/index.js index 788d331..587e331 100644 --- a/index.js +++ b/index.js @@ -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}”).` @@ -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)) { diff --git a/manifest.yml b/manifest.yml index 1790253..69be8ef 100644 --- a/manifest.yml +++ b/manifest.yml @@ -1,2 +1,4 @@ name: netlify-plugin-cecil-cache -inputs: [] +inputs: + - name: cacheDir + description: Cache directory, relative to publish directory (default is `.cache`). diff --git a/package.json b/package.json index 092736a..cdc1746 100644 --- a/package.json +++ b/package.json @@ -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", @@ -13,6 +13,5 @@ "netlify", "netlify-plugin", "cecil" - ], - "dependencies": {} + ] }