Skip to content

Commit

Permalink
Merge pull request #10 from cdeleeuwe/fix_count_log
Browse files Browse the repository at this point in the history
Fix file count log
  • Loading branch information
cdeleeuwe authored May 20, 2021
2 parents 2e59760 + 59dff0c commit 6f6d6c4
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 15 deletions.
33 changes: 22 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
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 }) {
const path = getResourcesDir({ inputs });
const success = await utils.cache.restore(path);
console.log(`Checking if resources exist at "${path}"`);

if (success) {
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);
} else {
console.log(`No cache found for resources folder`);
Expand All @@ -32,11 +34,20 @@ module.exports = {
const success = await utils.cache.save(path);

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`);
}
}
};
},
};
84 changes: 82 additions & 2 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"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!",
"main": "index.js",
"repository": "https://github.com/cdeleeuwe/netlify-plugin-hugo-cache-resources.git",
Expand All @@ -13,5 +13,7 @@
"netlify",
"netlify-plugin"
],
"dependencies": {}
"dependencies": {
"glob": "^7.1.7"
}
}

0 comments on commit 6f6d6c4

Please sign in to comment.