Skip to content

Commit

Permalink
Merge pull request #9 from intervalia/2.0-beta
Browse files Browse the repository at this point in the history
Bug fixes - v2.0.1
  • Loading branch information
intervalia committed Jan 2, 2019
2 parents cf5908f + b0d72d5 commit aee3403
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 22 deletions.
37 changes: 21 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,41 @@
Using hashed filenames based on content allows for filenames that only change as the content changes. This helps improve caching of your files. If the content does not change then the filename does not change and that file can still be pulled from the browser's cache.

---

>Always reference the documents on the git repo since they are updated more often then the NPM package website. I update NPM when there is a code change. I might change documentation without a code change and, at that time, I would not update the version number or NPM release.
---

## Install

```shell
npm install -g gulp-hash-filename
```

or

```shell
npm install --save-dev gulp-hash-filename
```

---

## Pull Requests and Issues

Please submit **[pull requests](https://github.com/intervalia/gulp-hash-filename/pulls)** and **[issues](https://github.com/intervalia/gulp-hash-filename/issues)**. I will do my best to review and take care of PRs and issues quickly. If you have suggestions, I would love to hear them.


---

## Usage of `gulp-hash-filename`

### Example of the `hash()` function

Here is an example of how to use the `hash()` function:
Here is an example of how to use the `hash()` function in your `gulpfile.js` file:

```js
var gulp = require('gulp');
var hash = require('gulp-hash-filename');
const gulp = require('gulp');
const hash = require('gulp-hash-filename');

gulp.task('assemble', function() {
return gulp.src('./assembly.json')
Expand All @@ -49,10 +58,10 @@ gulp.task('assemble', function() {
The example below includes minification and saving the file with both the hashed filename `"{name}-{hash}{ext}"` and the hashed and minimized filename `"{name}-{hash}-min{ext}"` format.

```js
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var hash = require('gulp-hash-filename');
const gulp = require('gulp');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const hash = require('gulp-hash-filename');

gulp.task('assemble', function() {
return gulp.src('./*.js')
Expand All @@ -67,8 +76,8 @@ gulp.task('assemble', function() {
You can change how the filename is formatted by passing in a `format` option in the `hash()` function.

```js
var gulp = require('gulp');
var hash = require('gulp-hash-filename');
const gulp = require('gulp');
const hash = require('gulp-hash-filename');

gulp.task('assemble', function() {
return gulp.src('./assembly.json')
Expand All @@ -78,10 +87,12 @@ gulp.task('assemble', function() {
.pipe(gulp.dest('./dist'))
});
```

---

### Options used in the `hash()` function

Currently (2015-01-13) there is only one option that is allowed in the `hash()` function. That is the `format` option.
There is only one option that is allowed in the `hash()` function. That is the `format` option.

`format` is used to control the output filename format. The default value for `format` is `"{name}-{hash}{ext}"`.

Expand Down Expand Up @@ -111,14 +122,10 @@ The output format used by `atime`, `ctime` and `mtime` is a format that includes
### Limiting the length of the output

> New feature as of version 1.1.0
You can limit the number of characters for the value of each parameter by adding `:value` to the parameter.

For example if you only want to use the first 8 characters of the `hash` value you would use the parameter `{hash:8}`.



### More examples

Below are some other examples of the output filename based on the following values:
Expand Down Expand Up @@ -146,8 +153,6 @@ Example output file name:

MIT - [License File](https://github.com/intervalia/gulp-hash-filename/tree/master/LICENSE.md)



---
# Update History

Expand Down
21 changes: 21 additions & 0 deletions UPDATE_HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
Update History
==============

### 2.0.1 - 2019-01-02

* Minor bug fix to allow no arguments to be passed into the `hash()` function.
* Fixed ISSUE#5. No longer crash if atime, mtime or ctime don't exist.

---

### 2.0.0

* This is really PR#7 from dwighthouse - But going a little further in updating ALL dependencies and removing code that is no longer needed.
* Fixed ISSUE#6. Directly related to PR#7.

---

### 1.2.0

* PR#3 from tuck182 - Handle generated files that do not support the `file.stat` object.

---

### 1.1.1

* Adding support for coveralls

---

### 1.1.0

* Added code to allow length limitation for any field. {hash} will use the full length while {hash:8} will only use the first 8 characters of the hash value.
* Broke single file into multiple files for testing
* Added Mocha/Chai testing for all non-gulp functionality

---
### 1.0.0


* Initial Release
* Added {name}, {ext}, {hash}, {atime}, {ctime} and {mtime} as options to the format routine
* Set default of format string to "{name}-{hash}{ext}"
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ function hashFileName(options) {
if (!opts || typeof opts !== 'object') {
opts = {};
}
const format = options.format || "{name}-{hash}{ext}";

const format = opts.format || "{name}-{hash}{ext}";

assemblyStream._transform = function(file, unused, callback) {
this.push(performHash(format, file));
Expand Down
6 changes: 3 additions & 3 deletions lib/performHash.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ function performHash(format, file) {
"ext": ext,
"hash": generateHash(file.contents),
"size": file.stat ? file.stat.size : '',
"atime": file.stat ? getDateStr(file.stat.atime) : '',
"ctime": file.stat ? getDateStr(file.stat.ctime) : '',
"mtime": file.stat ? getDateStr(file.stat.mtime) : ''
"atime": file.stat && file.stat.atime ? getDateStr(file.stat.atime) : '',
"ctime": file.stat && file.stat.ctime ? getDateStr(file.stat.ctime) : '',
"mtime": file.stat && file.stat.mtime ? getDateStr(file.stat.mtime) : ''
};
var fileName = formatStr(format, params);
file.path = path.join(dir, fileName);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gulp-hash-filename",
"version": "2.0.0",
"version": "2.0.1",
"author": "Michael G Collins <intervalia@gmail.com>",
"license": "MIT",
"description": "gulp-hash-filename is a gulp plug-in that adds a hash to the filename based on the content of that file, size of that file, or the file's atime, ctime and mtime.",
Expand Down

0 comments on commit aee3403

Please sign in to comment.