diff --git a/README.md b/README.md index 5c296b1..da81e57 100644 --- a/README.md +++ b/README.md @@ -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') @@ -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') @@ -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') @@ -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}"`. @@ -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: @@ -146,8 +153,6 @@ Example output file name: MIT - [License File](https://github.com/intervalia/gulp-hash-filename/tree/master/LICENSE.md) - - --- # Update History diff --git a/UPDATE_HISTORY.md b/UPDATE_HISTORY.md index c4fc203..41f078d 100644 --- a/UPDATE_HISTORY.md +++ b/UPDATE_HISTORY.md @@ -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}" diff --git a/index.js b/index.js index 805de36..a42a05d 100644 --- a/index.js +++ b/index.js @@ -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)); diff --git a/lib/performHash.js b/lib/performHash.js index b92c45d..e4b17d5 100644 --- a/lib/performHash.js +++ b/lib/performHash.js @@ -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); diff --git a/package-lock.json b/package-lock.json index ded96e2..6f3f452 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "gulp-hash-filename", - "version": "2.0.0", + "version": "2.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 65777cc..2907c21 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gulp-hash-filename", - "version": "2.0.0", + "version": "2.0.1", "author": "Michael G Collins ", "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.",