eleventy-auto-cache-buster 0.7.0 → 0.8.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.
@@ -1,11 +1,11 @@
1
- const fs = require("fs");
2
- const path = require("path");
1
+ const fs = require("fs");
2
+ const path = require("path");
3
3
  const crypto = require("crypto");
4
- const glob = require("glob");
4
+ const glob = require("glob");
5
5
 
6
6
  let enableLogging = false;
7
- let algorithm = "md5";
8
- let hashTruncate = 12;
7
+ let algorithm = "md5";
8
+ let hashTruncate = 12;
9
9
  let hashFunction;
10
10
 
11
11
  function hash(content) {
@@ -41,13 +41,14 @@ function logRed(string) {
41
41
  }
42
42
 
43
43
  const defaultOptions = {
44
- globstring: "**/*",
45
- extensions: ["css", "js", "png", "jpg", "jpeg", "gif", "mp4", "ico"],
46
- hashTruncate: 12,
47
- runAsync: true,
44
+ globstring: "**/*",
45
+ globOptions: {nodir: true},
46
+ extensions: ["css", "js", "png", "jpg", "jpeg", "gif", "mp4", "ico"],
47
+ hashTruncate: 12,
48
+ runAsync: true,
48
49
  enableLogging: enableLogging,
49
50
  hashAlgorithm: algorithm,
50
- hashFunction: hash,
51
+ hashFunction: hash,
51
52
  }
52
53
 
53
54
  function collectLocalAssets(globResults=[], outputDir, extensions=defaultOptions.extensions) {
@@ -88,7 +89,7 @@ function writeAsync(outputPath, outputData) {
88
89
  }
89
90
 
90
91
  function replaceAssetsInFile(fileData, filePath, assetPathsAndHashes, writeFunc) {
91
- let outputString = fileData;
92
+ let outputString = fileData;
92
93
  let outputChanged = false; // Check if any hashes have been added
93
94
 
94
95
  // Check for every asset
@@ -113,20 +114,20 @@ function replaceAssetsInFile(fileData, filePath, assetPathsAndHashes, writeFunc)
113
114
  if (outputChanged) {
114
115
  writeFunc(filePath, outputString);
115
116
  }
116
-
117
117
  }
118
118
 
119
119
  module.exports = function(eleventyConfig, options=defaultOptions) {
120
120
  // Override default options with set options
121
- options = Object.assign(defaultOptions, options);
122
- const globstring = options.globstring;
123
- const extensions = options.extensions;
124
- const runAsync = options.runAsync;
121
+ options = Object.assign(defaultOptions, options, {
122
+ // Object.assign seems to overwrite nested objects. @emiliorcueto added the clever handling below
123
+ globOptions: Object.assign(defaultOptions.globOptions, options.globOptions) // -- ensure `nodir` is always set
124
+ });
125
+ const { globstring, globOptions, extensions, runAsync } = options;
125
126
  // Set options to globals
126
- enableLogging = options.enableLogging;
127
- hashTruncate = options.hashTruncate;
128
- hashFunction = options.hashFunction;
129
- algorithm = options.hashAlgorithm;
127
+ enableLogging = options.enableLogging;
128
+ hashTruncate = options.hashTruncate;
129
+ hashFunction = options.hashFunction;
130
+ algorithm = options.hashAlgorithm;
130
131
 
131
132
 
132
133
  // Setup
@@ -139,7 +140,7 @@ module.exports = function(eleventyConfig, options=defaultOptions) {
139
140
  if (runAsync) {
140
141
  eleventyConfig.on("eleventy.after", async ({ dir, results, runMode, outputMode }) => {
141
142
  logYellow(`[ACB] Collecting assets & calculating hashes using ${globstring}...`);
142
- const assetPathsAndHashes = collectLocalAssets(await glob.glob(dir.output + "/" + globstring, {nodir: true}), dir.output, extensions);
143
+ const assetPathsAndHashes = collectLocalAssets(await glob.glob(dir.output + "/" + globstring, globOptions), dir.output, extensions);
143
144
 
144
145
  logRegular(`[ACB] Replacing in output...`);
145
146
  results.forEach(({inputPath, outputPath, url, content}) => {
@@ -156,7 +157,7 @@ module.exports = function(eleventyConfig, options=defaultOptions) {
156
157
  } else {
157
158
  eleventyConfig.on("eleventy.after", ({ dir, results, runMode, outputMode }) => {
158
159
  logYellow(`[ACB] Collecting assets & calculating hashes using ${globstring}...`);
159
- const assetPathsAndHashes = collectLocalAssets(glob.globSync(dir.output + "/" + globstring, {nodir: true}), dir.output, extensions);
160
+ const assetPathsAndHashes = collectLocalAssets(glob.globSync(dir.output + "/" + globstring, globOptions), dir.output, extensions);
160
161
 
161
162
  logRegular(`[ACB] Replacing in output...`);
162
163
  results.forEach(({inputPath, outputPath, url, content}) => {
@@ -166,5 +167,4 @@ module.exports = function(eleventyConfig, options=defaultOptions) {
166
167
  });
167
168
  });
168
169
  }
169
-
170
170
  }
package/README.md CHANGED
@@ -45,6 +45,7 @@ module.exports = function (eleventyConfig) {
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
47
  globstring: "subdir/**/*", // What glob string is used to locate assets.
48
+ globOptions: {nodir: true, ignore: ['node_modules/**', 'tmp/**']} // exclude multiple files or directories. (NOTE: `nodir` will automatically be set to true). Reference: https://github.com/isaacs/node-glob#readme
48
49
  extensions: ["css"], // What file extensions are accepted when locating assets.
49
50
  hashAlgorithm: "sha1", // What hash method to pass to the hash function. See Node.js' crypto.createHash documentation.
50
51
  hashFunction: function (content) { return "example" } // What function to run to calculate hashes. Overrides hashAlgorithm.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eleventy-auto-cache-buster",
3
- "version": "0.7.0",
3
+ "version": "0.8.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",