eleventy-auto-cache-buster 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/11tyAutoCacheBuster.js +11 -4
- package/README.md +2 -1
- package/package.json +3 -3
package/11tyAutoCacheBuster.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
2
3
|
const crypto = require("crypto");
|
|
3
4
|
const glob = require("glob");
|
|
4
5
|
|
|
@@ -40,7 +41,8 @@ function logRed(string) {
|
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
const defaultOptions = {
|
|
43
|
-
globstring: "
|
|
44
|
+
globstring: "**/*",
|
|
45
|
+
extensions: ["css", "js", "png", "jpg", "jpeg", "gif", "mp4", "ico"],
|
|
44
46
|
hashTruncate: 12,
|
|
45
47
|
runAsync: true,
|
|
46
48
|
enableLogging: enableLogging,
|
|
@@ -48,10 +50,14 @@ const defaultOptions = {
|
|
|
48
50
|
hashFunction: hash,
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
function collectLocalAssets(globResults=[], outputDir) {
|
|
53
|
+
function collectLocalAssets(globResults=[], outputDir, extensions=defaultOptions.extensions) {
|
|
52
54
|
const assetPaths = [];
|
|
53
55
|
globResults.forEach((assetPath) => {
|
|
54
56
|
assetPath = assetPath.replace(/\\/g, "/")
|
|
57
|
+
if (!extensions.includes(path.extname(assetPath).substring(1))) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
55
61
|
logGreen(`[ACB] ${assetPath} is an asset! Calculating hash...`);
|
|
56
62
|
const assetHash = hashFunction(fs.readFileSync(assetPath));
|
|
57
63
|
logGreen(`[ACB] ${assetPath} hash = ${assetHash}`);
|
|
@@ -114,6 +120,7 @@ module.exports = function(eleventyConfig, options=defaultOptions) {
|
|
|
114
120
|
// Override default options with set options
|
|
115
121
|
options = Object.assign(defaultOptions, options);
|
|
116
122
|
const globstring = options.globstring;
|
|
123
|
+
const extensions = options.extensions;
|
|
117
124
|
const runAsync = options.runAsync;
|
|
118
125
|
// Set options to globals
|
|
119
126
|
enableLogging = options.enableLogging;
|
|
@@ -132,7 +139,7 @@ module.exports = function(eleventyConfig, options=defaultOptions) {
|
|
|
132
139
|
if (runAsync) {
|
|
133
140
|
eleventyConfig.on("eleventy.after", async ({ dir, results, runMode, outputMode }) => {
|
|
134
141
|
logYellow(`[ACB] Collecting assets & calculating hashes using ${globstring}...`);
|
|
135
|
-
const assetPathsAndHashes = collectLocalAssets(await glob.glob(dir.output + "/" + globstring), dir.output);
|
|
142
|
+
const assetPathsAndHashes = collectLocalAssets(await glob.glob(dir.output + "/" + globstring, {nodir: true}), dir.output, extensions);
|
|
136
143
|
|
|
137
144
|
logRegular(`[ACB] Replacing in output...`);
|
|
138
145
|
results.forEach(({inputPath, outputPath, url, content}) => {
|
|
@@ -149,7 +156,7 @@ module.exports = function(eleventyConfig, options=defaultOptions) {
|
|
|
149
156
|
} else {
|
|
150
157
|
eleventyConfig.on("eleventy.after", ({ dir, results, runMode, outputMode }) => {
|
|
151
158
|
logYellow(`[ACB] Collecting assets & calculating hashes using ${globstring}...`);
|
|
152
|
-
const assetPathsAndHashes = collectLocalAssets(glob.globSync(dir.output + "/" + globstring), dir.output);
|
|
159
|
+
const assetPathsAndHashes = collectLocalAssets(glob.globSync(dir.output + "/" + globstring, {nodir: true}), dir.output, extensions);
|
|
153
160
|
|
|
154
161
|
logRegular(`[ACB] Replacing in output...`);
|
|
155
162
|
results.forEach(({inputPath, outputPath, url, content}) => {
|
package/README.md
CHANGED
|
@@ -44,7 +44,8 @@ module.exports = function (eleventyConfig) {
|
|
|
44
44
|
enableLogging: true, // Whether to enable eleventy-auto-cache-buster logging.
|
|
45
45
|
hashTruncate: 0, // Desired substring length of the hash. Set to 0 or lower to disable truncating
|
|
46
46
|
runAsync: false, // Whether to run asynchronously. Default is true
|
|
47
|
-
globstring: "
|
|
47
|
+
globstring: "subdir/**/*", // What glob string is used to locate assets.
|
|
48
|
+
extensions: ["css"], // What file extensions are accepted when locating assets.
|
|
48
49
|
hashAlgorithm: "sha1", // What hash method to pass to the hash function. See Node.js' crypto.createHash documentation.
|
|
49
50
|
hashFunction: function (content) { return "example" } // What function to run to calculate hashes. Overrides hashAlgorithm.
|
|
50
51
|
});
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eleventy-auto-cache-buster",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Busts cache using ?v= with minimal configuration!",
|
|
5
5
|
"main": "11tyAutoCacheBuster.js",
|
|
6
6
|
"repository": "https://github.com/Denperidge/eleventy-auto-cache-buster.git",
|
|
7
7
|
"author": "Denperidge",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"test": "ava tests
|
|
10
|
+
"test": "ava tests/test.mjs --timeout=30s"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"glob": "^10.3.10"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@11ty/eleventy": "^
|
|
16
|
+
"@11ty/eleventy": "^3.0.0",
|
|
17
17
|
"ava": "^6.1.3",
|
|
18
18
|
"jsdom": "^24.1.0"
|
|
19
19
|
}
|