Skip to content

Commit 468ae68

Browse files
committed
Merge pull request #16 from evcohen/ecohen-master
Allow passing of glob patterns to grepFiles option
2 parents 65c18ec + fe1020d commit 468ae68

File tree

5 files changed

+55
-7
lines changed

5 files changed

+55
-7
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ grunt.registerTask('default', 'lint rjs jpgmin gifmin pngmin concat cssmin versi
118118

119119
#### @param {options.grepFiles}
120120
- accepts: array of strings
121-
- list of files (relative filepaths) containing references to the {options.assets} which need to be renamed
121+
- list of files (relative filepaths or globbed filepaths) containing references to the {options.assets} which need to be renamed
122+
- a globbed filepath specifies all files that matches a certain pattern (i.e. /x/y/*.html will match all files in that directory with .html suffix)
122123

123124
#### @param {options.newVersion}
124125
- accepts: string (only numbers or letters)

lib/main.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var fs = require('fs');
66
var async = require('async');
77
var _ = require('underscore');
88
var util = require('util');
9+
var glob = require('glob');
910
// var cryto = require('cryto');
1011

1112
// my libs
@@ -41,7 +42,12 @@ var Version = function (opts) {
4142
this.keepOldVersions = opts.keepOldVersions;
4243

4344
// Find and replace references to assets in the list of files in the grep array //
44-
this.grepFiles = (opts.grepFiles && _.isArray(opts.grepFiles)) ? opts.grepFiles : [];
45+
var grepFiles = (opts.grepFiles && _.isArray(opts.grepFiles)) ? opts.grepFiles : [];
46+
47+
// Allow globbed file paths to be passed into grepFiles option.
48+
this.grepFiles = grepFiles.reduce(function appendGlobbedFiles(files, currentFile) {
49+
return files.concat(glob.sync(currentFile));
50+
}, []);
4551

4652
this.baseOpts = {
4753
newVersion: opts.newVersion,

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-version-assets",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "version your static assets",
55
"main": "index.js",
66
"scripts": {
@@ -22,9 +22,9 @@
2222
"url": "https://github.com/techjacker/node-version-assets"
2323
},
2424
"github": "https://github.com/techjacker/node-version-assets",
25-
"engineStrict" : true,
25+
"engineStrict": true,
2626
"engines": {
27-
"node": ">=4"
27+
"node": ">=4"
2828
},
2929
"bugs": {
3030
"url": "https://github.com/techjacker/node-version-assets/issues"
@@ -52,6 +52,7 @@
5252
"dependencies": {
5353
"async": "~1.5.0",
5454
"crypto": "0.0.3",
55+
"glob": "^6.0.1",
5556
"underscore": "~1.8.3"
5657
},
5758
"devDependencies": {

test-utils/fixtures/index2.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!--========================= MINIFIED STYLESHEETS =========================-->
2+
<link rel="stylesheet" type="text/css" href="css/all-min.150c54ae1d5c95288a9cfd221d285e26.css">
3+
4+
5+
<script type="text/javascript" src="js/vendor/requirejs/require.js"></script>
6+
<script type="text/javascript" src="js/vendor/blah/blah.js"></script>
7+
<script type="text/javascript" src="js/app.oldie.8c65328fa6911cdaee9d3e4efe7a39c8.js"></script>
8+
<script type="text/javascript" src="js/app.newie.608a5034effb0308d3def22c128af397.js"></script>
9+
<!--[if lt IE 9 | IEMobile 7]>
10+
<script type="text/javascript">
11+
require.config({
12+
paths: {
13+
main: "js/app.oldie.1360871038416"
14+
}
15+
});
16+
</script>
17+
<![endif]-->
18+
<!--[if gte IE 9 | (gt IEMobile 7) | !IE]><!-->
19+
<script type="text/javascript">
20+
require.config({
21+
paths: {
22+
main: "js/app.newie.1360871038416"
23+
}
24+
});
25+
</script>
26+
<!--[endif]-->
27+
28+
29+
<script type="text/javascript">
30+
// var appPath = (!!window.Worker) ? 'js/app.client' : 'js/app.server';
31+
require(["main"]);
32+
</script>

test/main.test.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,27 @@ var cssFile = "all-min.css",
2020
grepFiles: [fixturesDir + "index.html"],
2121
// requireJs: true,
2222
newVersion: 1111111111
23-
};
23+
},
24+
globOpts = _.extend({}, opts, { grepFiles: [fixturesDir + "*.html"] });
2425

2526
var cleaner = require('./../test-utils/test-cleanup');
2627

2728
test('Main Contructor Fn: shd assign correct properties', function(t) {
2829

2930
var mainInstance = new Main(opts),
31+
mainGlobInstance = new Main(globOpts),
3032
mainInstanceDefaultsChecking = new Main(_.extend({}, opts, {cb: null, newVersion: null, grepFiles: null}));
3133

3234
// shd assign correctly
3335
t.equal(mainInstance.cb, opts.cb);
3436
t.equal(mainInstance.assets, opts.assets);
35-
t.equal(mainInstance.grepFiles, opts.grepFiles);
37+
t.same(mainInstance.grepFiles, opts.grepFiles);
38+
39+
// shd assign glob options correctly
40+
var htmlFixtures = [fixturesDir + 'index.html', fixturesDir + 'index2.html'];
41+
t.equal(mainGlobInstance.cb, opts.cb);
42+
t.equal(mainGlobInstance.assets, opts.assets);
43+
t.same(mainGlobInstance.grepFiles, htmlFixtures);
3644

3745
// defaults
3846
t.equal(mainInstanceDefaultsChecking.requireJs, undefined);

0 commit comments

Comments
 (0)