From 288d7fec8c822cb15a40d32155144e055d83104e Mon Sep 17 00:00:00 2001 From: Cassius de Leeuwe Date: Thu, 20 May 2021 21:04:38 +0700 Subject: [PATCH 1/2] log file count correctly --- index.js | 33 ++++++++++++------- package-lock.json | 82 ++++++++++++++++++++++++++++++++++++++++++++++- package.json | 4 ++- 3 files changed, 106 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index f4d1863..a5da2cf 100644 --- a/index.js +++ b/index.js @@ -1,18 +1,18 @@ 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); @@ -20,7 +20,9 @@ module.exports = { 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`); @@ -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`); } - } -}; \ No newline at end of file + }, +}; diff --git a/package-lock.json b/package-lock.json index 2756a21..718d8dc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,85 @@ { "name": "netlify-plugin-hugo-cache-resources", "version": "0.2.0", - "lockfileVersion": 1 + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" + }, + "glob": { + "version": "7.1.7", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz", + "integrity": "sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==", + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "requires": { + "wrappy": "1" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + } + } } diff --git a/package.json b/package.json index 08eb655..ee419f5 100644 --- a/package.json +++ b/package.json @@ -13,5 +13,7 @@ "netlify", "netlify-plugin" ], - "dependencies": {} + "dependencies": { + "glob": "^7.1.7" + } } From 59dff0c7fd0754770efc37c100ae2174f820e77a Mon Sep 17 00:00:00 2001 From: Cassius de Leeuwe Date: Thu, 20 May 2021 21:06:45 +0700 Subject: [PATCH 2/2] 0.2.1 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 718d8dc..c3a2b18 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "netlify-plugin-hugo-cache-resources", - "version": "0.2.0", + "version": "0.2.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index ee419f5..61eef40 100644 --- a/package.json +++ b/package.json @@ -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",