Skip to content

Commit

Permalink
v1.2.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
shonny-ua committed May 13, 2017
1 parent b07ac93 commit 2c67c66
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 9 deletions.
24 changes: 24 additions & 0 deletions README.md
Expand Up @@ -80,6 +80,8 @@ You set a flag, replaceReved, which will replace alredy replaced links in templa

#### dirReplacements

Type : `Object`

Specifies a directories replacement set. [gulp-rev](https://github.com/sindresorhus/gulp-rev) creates manifest files without any info about directories. E.c. if you use dirReplacements param from [Usage](#usage) example, you get next replacement:

```
Expand All @@ -94,6 +96,28 @@ Type : `String`

It is pattern for define reved files suffixes. Default value is '-[0-9a-f]{8,10}-?'. This is necessary in case of e.c. [gulp-rename](https://github.com/hparra/gulp-rename) usage. If reved filenames had different from default mask.

#### extMap

Type : `Object`

If You use some methods to modify the rev_manifest.json after use [gulp-rev](https://github.com/sindresorhus/gulp-rev) and get a result like this:
```
{
"assets/less/common.less": "assets/css/common-2c0d21e40c.css"
}
```
It means that keys and values in the rev_manifest.json have different ext : less & css.

You can define extentions maping rules for correct manifest file processing.

Default value is:
```
{
'.scss': '.css',
'.less': '.css',
'.jsx': '.js'
}
```

### Works with gulp-rev-collector

Expand Down
15 changes: 10 additions & 5 deletions index.js
Expand Up @@ -136,11 +136,16 @@ function revCollector(opts) {
patterns.forEach(function (pattern) {
// without dirReplacements we must leave asset filenames with prefixes in its original state
var prefixDelim = '([\/\\\\\'"';
if (!~pattern.indexOf('(')) {
prefixDelim += '\(';
}
if (!~pattern.indexOf('=')) {
prefixDelim += '=';
// if dir part in pattern exists, all exsotoic symbols should be correct processed using dirReplacements
if (/[\\\\\/]/.test(pattern)) {
prefixDelim += '\(=';
} else {
if (!/[\(\)]/.test(pattern)) {
prefixDelim += '\(';
}
if (!~pattern.indexOf('=')) {
prefixDelim += '=';
}
}
prefixDelim += '])';
changes.push({
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "gulp-rev-collector",
"version": "1.2.0",
"version": "1.2.1",
"description": "Static asset revision data collector from manifests, generated from different streams, and replace their links in html template.",
"license": "MIT",
"repository": {
Expand Down
57 changes: 54 additions & 3 deletions test.js
Expand Up @@ -184,9 +184,7 @@ it('should generate correct collected manifest file', function (cb) {

// https://github.com/shonny-ua/gulp-rev-collector/issues/30
it('should generate correct collected manifest file, even if the map includes different extensions', function (cb) {
var stream = revCollector({
// collectedManifest: 'collectedManifest.json'
});
var stream = revCollector();
var fileCount = 0;
var revisionMap = {
"assets/less/common.less": "assets/css/common-2c0d21e40c.css"
Expand Down Expand Up @@ -232,6 +230,59 @@ it('should generate correct collected manifest file, even if the map includes di

stream.end();
});

it('should generate correct collected manifest file, even if the map includes different exotic extensions', function (cb) {
var stream = revCollector({
extMap: {
'.loss': '.css'
}
});
var fileCount = 0;
var revisionMap = {
"assets/less/common.loss": "assets/css/common-2c0d21e40c.css"
};

var htmlFileBody = '<html><head><link rel="stylesheet" href="/assets/less/common.loss" /></head><body><img src="cdn/image.gif" /></body></html>';
var htmlRevedFileBody = '<html><head><link rel="stylesheet" href="/assets/css/common-2c0d21e40c.css" /></head><body><img src="cdn/image.gif" /></body></html>';

stream.write(new gutil.File({
path: 'rev/css/rev-manifest.json',
contents: new Buffer(JSON.stringify(revisionMap))
}));

stream.write(new gutil.File({
path: 'index.html',
contents: new Buffer(htmlFileBody)
}));

stream.on('data', function (file) {
var fpath = file.path;
var contents = file.contents.toString('utf8');
var ext = path.extname(file.path);

assert.equal(ext, '.html', 'Only html files should pass through the stream');

assert(
!/assets\/less\/common\.loss/.test(contents),
'The LESS file name should be replaced'
);

assert(
/assets\/css\/common-2c0d21e40c\.css/.test(contents),
'The LESS 2 CSS file name should be correct replaced'
);

fileCount++;
});

stream.on('end', function() {
assert.equal(fileCount, 1, 'Only one file should pass through the stream');
cb();
});

stream.end();
});

// https://github.com/shonny-ua/gulp-rev-collector/issues/32
it('should generate correct collected manifest file, even if f the name of the JS file contains “-”', function (cb) {
var stream = revCollector({
Expand Down

0 comments on commit 2c67c66

Please sign in to comment.