Skip to content

Commit ef7e52d

Browse files
Added debug logging functionality and updated README.md
Added debug logging functionality. Changed README.md reflecting addition of badges, TOC, limitations and new usage example.
1 parent a225477 commit ef7e52d

File tree

6 files changed

+308
-62
lines changed

6 files changed

+308
-62
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
66

77
## [Unreleased]
88

9-
## [1.2.0]
9+
## [1.3.0] - 2019-03-20
10+
11+
### Added
12+
- Debug logging functionality.
13+
14+
### Changed
15+
- README.md reflecting addition of badges, TOC, limitations and new usage example.
16+
17+
## [1.2.0] - 2019-03-18
1018

1119
### Fixed
1220
- Validation of asset file name.

README.md

Lines changed: 211 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# grunt-cache-killer
22

3+
[![NPM version](http://img.shields.io/npm/v/grunt-cache-killer.svg?label=grunt-cache-killer&logo=npm)](https://www.npmjs.com/package/grunt-cache-killer?activeTab=versions) ![Maintained](https://img.shields.io/static/v1.svg?label=maintened&message=yes&color=informational&logo=npm) ![NPM dependencies](https://img.shields.io/static/v1.svg?label=dependencies&message=none&color=informational&logo=npm) ![NPN downloads](http://img.shields.io/npm/dt/grunt-cache-killer.svg?logo=npm)
4+
5+
[![GitHub version](https://img.shields.io/github/package-json/v/midnight-coding/grunt-cache-killer.svg?label=grunt-cache-killer&logo=github)](https://github.com/midnight-coding/grunt-cache-killer/releases) [![GitHub License](https://img.shields.io/github/license/midnight-coding/grunt-cache-killer.svg?color=informational&logo=github)](https://github.com/midnight-coding/grunt-cache-killer/blob/master/LICENSE-MIT) ![GitHub release date](https://img.shields.io/github/release-date/midnight-coding/grunt-cache-killer.svg?logo=github) [![GitHub open issues](https://img.shields.io/github/issues-raw/midnight-coding/grunt-cache-killer.svg?logo=github)](https://github.com/midnight-coding/grunt-cache-killer/milestones?state=open) [![GitHub closed issues](https://img.shields.io/github/issues-closed-raw/midnight-coding/grunt-cache-killer.svg?logo=github)](https://github.com/midnight-coding/grunt-cache-killer/milestones?state=closed)
6+
7+
---
8+
39
Ever wanted to ensure that your most recently deployed asset files (eg: css, js, img, etc) are being used instead of the old long-term cached versions?
410

511
Then look no further...!
@@ -9,6 +15,23 @@ This [Grunt](https://gruntjs.com/) plugin inserts a **cache avoiding** string in
915
Find this plugin at:
1016
- [https://www.npmjs.com/package/grunt-cache-killer](https://www.npmjs.com/package/grunt-cache-killer).
1117
- [https://github.com/midnight-coding/grunt-cache-killer](https://github.com/midnight-coding/grunt-cache-killer).
18+
19+
## Table Of Contents
20+
21+
* [Getting Started](#getting-started)
22+
* [The cacheKiller Task](#the-cachekiller-task)
23+
* [Overview](#overview)
24+
* [Options](#options)
25+
* [Usage](#usage)
26+
* [Limitations](#limitations)
27+
* [Usage Examples](#usage-examples)
28+
* [Default Options](#default-options)
29+
* [Simple Custom Options](#simple-custom-options)
30+
* [Complex Custom Options](#complex-custom-options)
31+
* [Hierarchical Custom Options](#hierarchical-custom-options)
32+
* [Bug Reporting](#bug-reporting)
33+
* [Contributing](#contributing)
34+
* [Release History](#release-history)
1235

1336
## Getting Started
1437

@@ -26,9 +49,9 @@ Once the plugin has been installed, it may be enabled inside your Gruntfile with
2649
grunt.loadNpmTasks('grunt-cache-killer');
2750
```
2851

29-
Alternatively, install the [load-grunt-tasks](https://www.npmjs.com/package/load-grunt-tasks) plugin to have cacheKiller load automatically.
52+
> **Tip:** Alternatively, install the [load-grunt-tasks](https://www.npmjs.com/package/load-grunt-tasks) plugin to have cacheKiller load automatically.
3053
31-
## The "cacheKiller" task
54+
## The cacheKiller Task
3255

3356
### Overview
3457

@@ -38,11 +61,15 @@ In your project's Gruntfile, add a section named `cacheKiller` to the data objec
3861
grunt.initConfig({
3962
cacheKiller: {
4063
options: {
41-
// Options
64+
prepend: '',
65+
append: '',
66+
mask: '{md5}',
67+
length: -1
4268
},
4369
taskName: {
4470
files: {
45-
'asset/path/filename.css': ['template/path/filename-1.html', 'template/path/filename-2.html']
71+
'path/to/asset/filename[mask].min.css': ['path/to/template/using/asset/filename-1.html',
72+
'path/to/template/using/asset/filename-2.html']
4673
}
4774
}
4875
}
@@ -56,40 +83,74 @@ grunt.initConfig({
5683
- `append` (string) - A string value that is used to add characters to the back of the `[mask]` placeholder. The default value is an empty string.
5784

5885
- `mask` (string) - A string value that is used to specify the passed in mask. The default value is `{md5}`.
59-
- If a **cacherKiller** mask function is used, then the string generated from that function will be inserted. If an invalid mask function is used, then an error message along with a full list of valid mask functions will be shown.
86+
- If a **cacheKiller** mask function is used (ie: Anything surrounded by curly braces. eg: `{...}`), then the string generated from that function will be inserted. If an invalid mask function is used, then an error message along with a full list of valid mask functions will be shown.
6087

6188
CacheKiller's mask functions include:
6289
- `{timestamp}` eg: `1551278199614`
6390
- `{datetimestamp}` eg: `20190228123639`
64-
- All [OpenSSL](https://www.openssl.org/) algorithms available on your system. Some common algorithims include:
91+
- All [OpenSSL](https://www.openssl.org/) algorithms available on your system. Some common algorithms include but are not limited to:
6592
- `{md4}` eg: `1f73e014cf3341a8b0715b27c031b188`
6693
- `{md5}` eg: `70a1d7fe6502fa887f5b810d9063da07`
6794
- `{sha1}` eg: `a20a181e3C2a813ae08c22fb9d61133c315517bb`
6895
- `{sha224}` eg: `d157aefcf36cdc966737aa0dc4ea85d720652185550c248de9d018f9`
6996
- `{sha256}` eg: `8736ba042ee82bc70676c964b6f7b05e063e1957c95Cb80e4f15f8b01e69c9ad`
7097

71-
**Tip:** Use one of the below listed commands at the command prompt for a full list of available algorithms on your system.
72-
```
73-
// For newer versions of OpenSSL.
74-
openssl list -digest-algorithms
75-
76-
// For older versions of OpenSSL.
77-
openssl list-message-digest-algorithms
78-
```
98+
> **Tip:** Use one of the below listed commands at the command prompt for a full list of available algorithms on your system.
99+
> ```
100+
> // For newer versions of OpenSSL.
101+
> openssl list -digest-algorithms
102+
>
103+
> // For older versions of OpenSSL.
104+
> openssl list-message-digest-algorithms
105+
> ```
79106
80107
- If a **string** is used, then that string is inserted. eg: `mask: 'my-string'`
81108
82109
- `length` (number) - A number value that is used to set the length of the mask. The default value is `-1`.
83110
- If the value of the number is negative (eg: `-1`) then the length of the given / generated string remains unchanged.
84111
- If the value of the number if positive (eg: `8`) then only that value of right-hand characters in the string will remain.
85-
- If the value of the number is zero (eg: `0`) then the mask string (excluding the prepend and append strings) is not used.
112+
- If the value of the number is zero (eg: `0`) then the mask string (excluding the prepend and append strings) is not used. (ps: Considering the primary function of cacheKiller is to place masks within filenames, use of this value would be redundant exercise).
86113
87114
### Usage
88115
89-
Within the cacheKiller's `files:` node, place the `[mask]` placeholder within the asset filename where you would like the mask to be added.
116+
If this is the first time you are running cacheKiller, it will insert the mask value into the asset filename and update any reference to it within your nominated template file(s).
90117
91-
> **Note** - Do not place the `[mask]` placeholder at the very beginning or very end of the asset filename. (eg: `public/css/[mask].website.min.css`). Doing so would mangle the template file(s). CacheKiller prevents this from happening by showing an error message and terminating the script.
118+
Running cacheKiller again will refresh the previously inserted mask value mask value of the asset filename with an updated value and again update any reference to it within your nominated template file(s).
119+
120+
Whether this is the 1st or 1,000th time your asset and template files have been updated, cacheKiller will insert the mask in the specified location each and every time.
121+
122+
Implementation is simple. Within the cacheKiller's `files:` node, place the `[mask]` placeholder within the asset filename where you would like the mask to be added.
123+
124+
```js
125+
// Here...
126+
'public/css/website[mask].min.css'
127+
128+
// Or here...
129+
'public/css/website.min[mask].css'
130+
131+
// Or anywhere else you like within the asset filename, pursuant to the below limitations.
132+
```
92133
134+
#### Limitations
135+
136+
- Do not place the `[mask]` placeholder within a directory. (eg: `public/[mask]/website.min.css`). CacheKiller is not designed to rename / update directory names, only filenames.
137+
138+
- Do not place the `[mask]` placeholder at the very beginning or very end of the asset filename. (eg: `public/css/[mask].website.min.css`). Doing so **_would_** mangle the template file(s). CacheKiller knows this, so to prevent it from happening cacheKiller will show you an error message and terminate the script.
139+
140+
- Do not move the `[mask]` placeholder back or forth within the asset filename if you have already run cacheKiller against that asset filename. Doing so **_will_** mangle the asset filename and any reference to it in the template file(s). If the `[mask]` is moved, there **_will_** be remnants of the previously added mask within the asset filename and template file(s). Whilst this may not necessarily break your applications functionality, it will break any compliance rules you may have around the naming of files.<br><br>
141+
If you need to retrospectively move the `[mask]` placeholder back or forth within the asset filename, follow the below listed steps:
142+
1. Rename the asset filename back to a generic filename. eg: `website.min.css`.
143+
2. Update any and all references to the asset filename within the template file(s) using the same generic filename. eg: `website.min.css`.
144+
3. Within the cacheKiller task, move the asset filenames `[mask]` placeholder to it's new position.
145+
4. Run the cacheKiller task.
146+
147+
- Do not rename the asset filename if you have already run cacheKiller against that asset filename. Doing so will show you an error message and terminate the script.<br><br>
148+
If you need to retrospectively rename the asset filename, follow the below listed steps.
149+
1. Rename the asset filename to your new filename. eg: `new.website.min.css`.
150+
2. Update any and all references to the asset filename within the template file(s) using your new filename. eg: `new.website.min.css`.
151+
3. Within the cacheKiller task, insert the asset filenames `[mask]` placeholder within the new asset filename. eg: `public/css/new[mask].website.min.css`.
152+
4. Run the cacheKiller task.
153+
93154
### Usage Examples
94155

95156
#### Default Options
@@ -99,12 +160,12 @@ In this example, the default options are used.
99160
```js
100161
grunt.initConfig({
101162
cacheKiller: {
102-
options: {
103-
prepend: '',
104-
append: '',
105-
mask: '{md5}',
106-
length: -1
107-
},
163+
// options: {
164+
// prepend: '',
165+
// append: '',
166+
// mask: '{md5}',
167+
// length: -1
168+
// },
108169
taskName: {
109170
files: {
110171
'public/css/app[mask].min.css': ['app/views/templates/master.html']
@@ -114,9 +175,9 @@ grunt.initConfig({
114175
});
115176
```
116177

117-
Before running cacheKiller.
178+
Before:
118179

119-
```
180+
```txt
120181
// Asset file.
121182
122183
public/css/app.min.css
@@ -128,9 +189,9 @@ public/css/app.min.css
128189
<link href="https://www.site.com/css/app.min.css" rel="stylesheet">
129190
```
130191

131-
After running cacheKiller.
192+
After:
132193

133-
```
194+
```txt
134195
// Asset file.
135196
136197
public/css/app70a1d7fe6502fa887f5b810d9063da07.min.css
@@ -141,19 +202,64 @@ public/css/app70a1d7fe6502fa887f5b810d9063da07.min.css
141202

142203
<link href="https://www.site.com/css/app70a1d7fe6502fa887f5b810d9063da07.min.css" rel="stylesheet">
143204
```
205+
#### Simple Custom Options
206+
207+
In this example, simple custom options are used.
208+
209+
```js
210+
grunt.initConfig({
211+
cacheKiller: {
212+
options: {
213+
mask: 's-rule' // String used instead of a cacheKiller mask function.
214+
},
215+
taskName: {
216+
files: {
217+
'public/css/app[mask].min.css': ['app/views/templates/master.html']
218+
}
219+
}
220+
}
221+
});
222+
```
223+
224+
Before:
225+
226+
```txt
227+
// Asset file.
228+
229+
public/css/app.min.css
230+
```
231+
232+
```html
233+
<!-- master.html -->
234+
235+
<link href="https://www.site.com/css/app.min.css" rel="stylesheet">
236+
```
144237

145-
#### Custom Options
238+
After:
146239

147-
In this example, custom options are used
240+
```txt
241+
// Asset file.
242+
243+
public/css/apps-rule.min.css
244+
```
245+
246+
```html
247+
<!-- master.html -->
248+
249+
<link href="https://www.site.com/css/apps-rule.min.css" rel="stylesheet">
250+
```
251+
252+
#### Complex Custom Options
253+
254+
In this example, complex custom options are used.
148255

149256
```js
150257
grunt.initConfig({
151258
cacheKiller: {
152259
options: {
153260
prepend: '-',
154-
append: '.dev',
155-
mask: '{md5}',
156-
length: 8
261+
append: '.prod',
262+
mask: '{datetimestamp}'
157263
},
158264
taskName: {
159265
files: {
@@ -165,9 +271,9 @@ grunt.initConfig({
165271
});
166272
```
167273

168-
Before running cacheKiller.
274+
Before:
169275

170-
```
276+
```txt
171277
// Asset files.
172278
173279
public/css/app.min.css
@@ -181,22 +287,88 @@ public/js/app.min.js
181287
<script src="https://www.site.com/js/app.min.js"></script>
182288
```
183289

184-
After running cacheKiller.
290+
After:
291+
292+
```txt
293+
// Asset files.
185294
295+
public/css/app-20190228123639.prod.min.css
296+
public/js/app-20190228123639.prod.min.js
186297
```
298+
299+
```html
300+
<!-- master.html -->
301+
302+
<link href="https://www.site.com/css/app-20190228123639.prod.min.css" rel="stylesheet">
303+
<script src="https://www.site.com/js/app-20190228123639.prod.min.js"></script>
304+
```
305+
306+
#### Hierarchical Custom Options
307+
308+
In this example, custom options are used in a hierarchical order.
309+
310+
```js
311+
grunt.initConfig({
312+
cacheKiller: {
313+
options: {
314+
mask: '{datetimestamp}'
315+
},
316+
taskName1: {
317+
options: {
318+
prepend: '-v1.1-'
319+
},
320+
files: {
321+
'public/css/app[mask].min.css': ['app/views/templates/master.html']
322+
}
323+
},
324+
taskName2: {
325+
options: {
326+
prepend: '-v1.2-'
327+
},
328+
files: {
329+
'public/css/web[mask].min.css': ['app/views/templates/master.html']
330+
}
331+
}
332+
}
333+
});
334+
```
335+
336+
Before:
337+
338+
```txt
339+
// Asset files.
340+
341+
public/css/app.min.css
342+
public/css/web.min.css
343+
```
344+
345+
```html
346+
<!-- master.html -->
347+
348+
<link href="https://www.site.com/css/app.min.css" rel="stylesheet">
349+
<link href="https://www.site.com/css/web.min.css" rel="stylesheet">
350+
```
351+
352+
After:
353+
354+
```txt
187355
// Asset files.
188356
189-
public/css/app-9063da07.dev.min.css
190-
public/js/app-f959224b.dev.min.js
357+
public/css/app-v1.1-20190228123639.min.css
358+
public/css/web-v1.2-20190228123639.min.css
191359
```
192360

193361
```html
194362
<!-- master.html -->
195363

196-
<link href="https://www.site.com/css/app-9063da07.dev.min.css" rel="stylesheet">
197-
<script src="https://www.site.com/js/app-f959224b.dev.min.js"></script>
364+
<link href="https://www.site.com/css/app-v1.1-20190228123639.min.css" rel="stylesheet">
365+
<link href="https://www.site.com/css/web-v1.2-20190228123639.min.css" rel="stylesheet">
198366
```
199367

368+
## Bug Reporting
369+
370+
If you happen to come across any issues or bugs whilst using cacheKiller, please run your cacheKiller task with the cli `--debug` option enabled. The resulting report can then be copied and pasted inside your issue request. Adding this report to your issue request will reduce the time needed to identify and fix any bugs.
371+
200372
## Contributing
201373

202374
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)