Skip to content

Commit 9258218

Browse files
Added ability to replace asset name even when asset name is out of sync
Added ability to replace asset name in template(s) even when asset name is out of sync
1 parent ed1bc54 commit 9258218

File tree

9 files changed

+118
-12
lines changed

9 files changed

+118
-12
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ In lieu of a formal styleguide, take care to maintain the existing coding style.
184184

185185
## Release History
186186

187-
| Date | Version | Comments |
188-
| :--------: | :-----: | :-------------------------------------------|
189-
| 01-03-2019 | 1.0.0 | Initial commit. |
190-
| 14-03-2019 | 1.0.1 | Fixed incorrect counter reference in loop. |
191-
| | | Updated README.md reflecting correct usage. |
187+
| Date | Version | Comments |
188+
| :--------: | :-----: | :----------------------------------------------------------------------------------------------------------------|
189+
| 01-03-2019 | 1.0.0 | <ul><li>Initial commit.</li></ul> |
190+
| 14-03-2019 | 1.0.1 | <ul><li>Fixed incorrect counter reference in loop.</li><li>Updated README.md reflecting correct usage.</li></ul> |
191+
| 15-03-2019 | 1.0.2 | <ul><li>Added ability to replace asset name in template(s) even when asset name is out of sync.</li></ul> |

build/gruntfile.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ module.exports = function (grunt) {
5757
// Functional tests setup.
5858
cacheKiller: {
5959
test1: {
60-
files: {'tests/functional/actual/test1/css/website[mask].min.css': ['tests/functional/actual/test1/html/master.html']
60+
files: {
61+
'tests/functional/actual/test1/css/website[mask].min.css': ['tests/functional/actual/test1/html/master.html']
6162
}
6263
},
6364
test2: {
@@ -91,15 +92,22 @@ module.exports = function (grunt) {
9192
'tests/functional/actual/test4/css/website[mask].min.css': ['tests/functional/actual/test4/html/master-1.html', 'tests/functional/actual/test4/html/master-2.html'],
9293
'tests/functional/actual/test4/js/website[mask].min.js': ['tests/functional/actual/test4/html/master-1.html', 'tests/functional/actual/test4/html/master-2.html']
9394
}
95+
},
96+
test5: {
97+
options: {
98+
prepend: "-",
99+
append: ".dev",
100+
length: 8
101+
},
102+
files: {
103+
'tests/functional/actual/test5/css/website[mask].min.css': ['tests/functional/actual/test5/html/master.html']
104+
}
94105
}
95106
},
96107

97108
// Functional tests.
98109
nodeunit: {
99-
test1: ['tests/functional/test1.js'],
100-
test2: ['tests/functional/test2.js'],
101-
test3: ['tests/functional/test3.js'],
102-
test4: ['tests/functional/test4.js']
110+
all: ['tests/functional/*.js']
103111
}
104112

105113
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "grunt-cache-killer",
33
"description": "Kill your asset cache file problems by updating their filenames and any references to them.",
4-
"version": "1.0.1",
4+
"version": "1.0.2",
55
"homepage": "https://github.com/midnight-coding/grunt-cache-killer",
66
"author": {
77
"name": "Matthew Rath",

tasks/cacheKiller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ module.exports = function (grunt) {
225225
var content = fileSystem.readFileSync($tasks[j].templates[l], 'utf8');
226226

227227
// Replace the template's matching content.
228-
var result = content.replace(new RegExp($tasks[j].asset.rename.from.file, "g"), $tasks[j].asset.rename.to.file);
228+
var result = content.replace(new RegExp($tasks[j].asset.name.pre + '.*' + $tasks[j].asset.name.post, "g"), $tasks[j].asset.rename.to.file);
229229

230230
// Synchronously write the contents to the template.
231231
fileSystem.writeFileSync($tasks[j].templates[l], result, 'utf8');
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* Test Cascading Style Sheet */
2+
3+
body {
4+
margin: 0;
5+
padding: 0;
6+
background-color: #D3D3D3;
7+
}
8+
9+
h1 {
10+
margin: 1em;
11+
padding: 1em;
12+
color: #FFF;
13+
text-align: center;
14+
background-color: #808080;
15+
}
16+
17+
.highlight {
18+
background-color: #000080;
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<!-- Metadata -->
5+
<meta charset="UTF-8">
6+
7+
<!-- Title -->
8+
<title>Test HTML Template - Master</title>
9+
10+
<!-- Stylesheets -->
11+
<link href="../css/website-9063da07.dev.min.css" rel="stylesheet">
12+
</head>
13+
<body>
14+
<h1 id="heading">Test HTML Template - Master</h1>
15+
</body>
16+
</html>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* Test Cascading Style Sheet */
2+
3+
body {
4+
margin: 0;
5+
padding: 0;
6+
background-color: #D3D3D3;
7+
}
8+
9+
h1 {
10+
margin: 1em;
11+
padding: 1em;
12+
color: #FFF;
13+
text-align: center;
14+
background-color: #808080;
15+
}
16+
17+
.highlight {
18+
background-color: #000080;
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<!-- Metadata -->
5+
<meta charset="UTF-8">
6+
7+
<!-- Title -->
8+
<title>Test HTML Template - Master</title>
9+
10+
<!-- Stylesheets -->
11+
<link href="../css/website-0123456789.min.css" rel="stylesheet">
12+
</head>
13+
<body>
14+
<h1 id="heading">Test HTML Template - Master</h1>
15+
</body>
16+
</html>

tests/functional/test5.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
var grunt = require('grunt');
4+
5+
/* Test 5 */
6+
7+
exports.cacheKiller = {
8+
9+
test_1: function (test) {
10+
test.expect(1);
11+
12+
var expected = grunt.file.read('tests/functional/expected/test5/css/website-9063da07.dev.min.css');
13+
var actual = grunt.file.read('tests/functional/actual/test5/css/website-9063da07.dev.min.css');
14+
test.equal(actual, expected, 'File names and contents should match.');
15+
16+
test.done();
17+
},
18+
19+
test_2: function (test) {
20+
test.expect(1);
21+
22+
var expected = grunt.file.read('tests/functional/expected/test5/html/master.html');
23+
var actual = grunt.file.read('tests/functional/actual/test5/html/master.html');
24+
test.equal(actual, expected, 'File names and contents should match.');
25+
26+
test.done();
27+
}
28+
};

0 commit comments

Comments
 (0)