Skip to content

Commit

Permalink
Add debug log option
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudLigny committed May 15, 2021
1 parent da5796b commit 9d4794d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
19 changes: 17 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ const getCacheDirs = (constants, inputs) => [
inputs.cacheDir || process.env.CECIL_CACHE_DIR || '.cache'
];

const printDebug = (items) => {
items.forEach((item, index) => {
console.log(`${index + 1}. ${item}`);
});
}

module.exports = {
async onPreBuild({constants, inputs, utils}) {
if (process.cwd() === constants.PUBLISH_DIR) {
Expand All @@ -14,12 +20,14 @@ module.exports = {
const cacheDirs = getCacheDirs(constants, inputs);

if (await utils.cache.restore(cacheDirs)) {
const cachedFiles = await utils.cache.list();

utils.status.show({
title: 'Build cache',
summary: 'Cecil cache restored from previous build.',
text: (await utils.cache.list()).join("\n")
summary: 'Cecil cache restored from previous build. ' + cachedFiles.length + ' files.'
})
console.log('Cecil cache (%s) restored from previous build.', cacheDirs.join(', '));
if (inputs.debug) printDebug(cachedFiles);
} else {
console.log('Cecil cache not found.');
}
Expand All @@ -28,7 +36,14 @@ module.exports = {
const cacheDirs = getCacheDirs(constants, inputs);

if (await utils.cache.save(cacheDirs)) {
const cachedFiles = await utils.cache.list();

utils.status.show({
title: 'Build cache',
summary: 'Cecil cache stored to speed up next builds. ' + cachedFiles.length + ' files.'
})
console.log('Cecil cache (%s) stored to speed up next builds.', cacheDirs.join(', '));
if (inputs.debug) printDebug(cachedFiles);
} else {
console.log('No Cecil build found.');
}
Expand Down
2 changes: 2 additions & 0 deletions manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ name: netlify-plugin-cecil-cache
inputs:
- name: cacheDir
description: Cache directory, relative to publish directory (default is `.cache`).
- name: debug
description: Display list of cached files in build log.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "netlify-plugin-cecil-cache",
"version": "0.2.4",
"version": "0.2.5",
"description": "Persist the Cecil cache between Netlify builds.",
"main": "index.js",
"repository": "https://github.com/Cecilapp/netlify-plugin-cecil-cache.git",
Expand Down

0 comments on commit 9d4794d

Please sign in to comment.