Skip to content

Commit

Permalink
Merge pull request #8 from intervalia/2.0-beta
Browse files Browse the repository at this point in the history
v2.0.0
  • Loading branch information
intervalia committed Jan 2, 2019
2 parents 1fb3d18 + 8b4e2a8 commit cf5908f
Show file tree
Hide file tree
Showing 17 changed files with 3,149 additions and 170 deletions.
2 changes: 1 addition & 1 deletion .coveralls.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
repo_token: QWTZSQe9JSq7AN5Gi14orjQcIFp9OKnYm
repo_token: wEOu920ZmXxZf02SoTKBGO0V0J0niuwnC
service_name: travis-ci
112 changes: 112 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module"
},
"env": {
"es6": true,
"node": true,
"browser": true
},
"rules": {
"complexity": ["warn", {"max": 8}],
"curly": ["warn", "multi-line"],
"default-case": "warn",
"dot-notation": "warn",
"eqeqeq": ["warn", "smart"],
"guard-for-in": "warn",
"no-alert": "error",
"no-caller": "error",
"no-case-declarations": "error",
"no-div-regex": "error",
"no-else-return": "error",
"no-empty-pattern": "error",
"no-eq-null": 0,
"no-eval": "error",
"no-extend-native": "error",
"no-extra-bind": "error",
"no-extra-label": "warn",
"no-fallthrough": "warn",
"no-floating-decimal": "warn",
"no-global-assign": "error",
"no-implicit-globals": "warn",
"no-implied-eval": "error",
"no-invalid-this": "error",
"no-iterator": "error",
"no-labels": "error",
"no-lone-blocks": "error",
"no-loop-func": "error",
"no-magic-numbers": "off",
"no-multi-spaces": "warn",
"no-multi-str": "error",
"no-native-reassign": "error",
"no-new": "error",
"no-new-func": "error",
"no-new-wrappers": "error",
"no-octal": "warn",
"no-octal-escape": "warn",
"no-param-reassign": "warn",
"no-process-env": "off",
"no-proto": "error",
"no-redeclare": "error",
"no-return-assign": "warn",
"no-script-url": "error",
"no-self-compare": "error",
"no-sequences": "error",
"no-throw-literal": "error",
"no-unused-expressions": "error",
"no-unused-labels": "error",
"no-useless-call": "error",
"no-useless-concat": "error",
"no-void": "error",
"no-with": "error",
"prefer-promise-reject-errors": "warn",
"radix": "error",
"wrap-iife": "error",
"yoda": ["error", "never", {"onlyEquality": true}],

"comma-dangle": "error",
"no-cond-assign": "error",
"no-console": "off",
"no-constant-condition": "error",
"no-control-regex": "error",
"no-debugger": "error",
"no-dupe-args": "error",
"no-dupe-keys": "error",
"no-duplicate-case": "error",
"no-empty": "error",
"no-empty-character-class": "error",
"no-ex-assign": "error",
"no-extra-boolean-cast": "error",
"no-extra-parens": "off",
"no-extra-semi": "error",
"no-func-assign": "error",
"no-inner-declarations": "error",
"no-invalid-regexp": "error",
"no-irregular-whitespace": "error",
"no-obj-calls": "error",
"no-regex-spaces": "error",
"no-sparse-arrays": "error",
"no-template-curly-in-string": "error",
"no-unexpected-multiline": "error",
"no-unreachable": "error",
"no-unsafe-finally": "error",
"no-unsafe-negation": "error",
"use-isnan": "error",
"valid-jsdoc": "warn",
"valid-typeof": "error",

"strict": "off",

"no-catch-shadow": "error",
"no-delete-var": "error",
"no-label-var": "error",
"no-shadow": "error",
"no-shadow-restricted-names": "warn",
"no-undef": "error",
"no-undef-init": "error",
"no-undefined": "off",
"no-unused-vars": "warn",
"no-use-before-define": ["error", {"functions": false}]
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
coverage/
.nyc_output/
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: node_js
node_js:
- "0.12"
- "4.0"
- "6.0"
- "8.0"
- "10.0"
- "11.0"
sudo: false
script:
- npm test
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
gulp-hash-filename
========================
# gulp-hash-filename

[![NPM version](http://img.shields.io/npm/v/gulp-hash-filename.svg)](https://npmjs.org/package/gulp-hash-filename)
[![Downloads](http://img.shields.io/npm/dm/gulp-hash-filename.svg)](https://npmjs.org/package/gulp-hash-filename)
[![Support us](http://img.shields.io/gittip/intervalia.svg)](https://www.gittip.com/intervalia/)
[![Build Status](https://travis-ci.org/intervalia/gulp-hash-filename.svg?branch=master)](https://travis-ci.org/intervalia/gulp-hash-filename)
[![Coverage Status](https://coveralls.io/repos/github/intervalia/gulp-hash-filename/badge.svg?branch=master)](https://coveralls.io/github/intervalia/gulp-hash-filename?branch=master)

Expand All @@ -17,21 +15,24 @@ Using hashed filenames based on content allows for filenames that only change as
>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
## Install

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


---
#Pull Requests and Issues
## 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`
## Usage of `gulp-hash-filename`

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

###Example of the `hash()` function
Here is an example of how to use the `hash()` function:

```js
Expand Down Expand Up @@ -78,15 +79,16 @@ gulp.task('assemble', function() {
});
```
---
##Options used in the `hash()` function
### 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.

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

**example:** Assuming the incoming filename was `"sample.js"` and the hash value was `"a8c23bc812abef98"` and that the `format` value is the default then the hashed filename would be `"sample-a8c23bc812abef98.js"`

###`format` paramaters
#### `format` paramaters

| Parameter | Description |
| --- | --- |
| {name} | The base portion of the filename. For `sample.js` the {name} is `sample`. For `sample.test.js` the {name} is `sample.test`. |
Expand All @@ -97,7 +99,8 @@ Currently (2015-01-13) there is only one option that is allowed in the `hash()`
| {ctime} | The inode or file `change` time. |
| {mtime} | The file `modify` time. |

#### `atime`, `ctime` and `mtime`
##### `atime`, `ctime` and `mtime`

For more information about what the time formats mean [go here](http://www.linux-faqs.info/general/difference-between-mtime-ctime-and-atime)

The output format used by `atime`, `ctime` and `mtime` is a format that includes the Year, Month, Date, Hours, Minutes, Seconds and Milliseconds.
Expand All @@ -106,7 +109,7 @@ The output format used by `atime`, `ctime` and `mtime` is a format that includes

>As of version 1.2.0 if a file is added through the gulp system that does not support the `file.stat` object the values for `atime`, `ctime` and `mtime` will be an empty string.
#### Limiting the length of the output
### Limiting the length of the output

> New feature as of version 1.1.0
Expand All @@ -116,7 +119,8 @@ For example if you only want to use the first 8 characters of the `hash` value y



#### More examples
### More examples

Below are some other examples of the output filename based on the following values:

| parameter | value |
Expand All @@ -138,11 +142,13 @@ Example output file name:
| {name}.{hash:8}{ext} | sample.ABCDEF00.js |

---
#License
# License

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



---
#Update History
# Update History

[Update History File](https://github.com/intervalia/gulp-hash-filename/tree/master/UPDATE_HISTORY.md)
2 changes: 2 additions & 0 deletions UPDATE_HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Update History
==============

### 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.

### 1.2.0
* PR#3 from tuck182 - Handle generated files that do not support the `file.stat` object.
Expand Down
15 changes: 8 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
var stream = require('stream');
var performHash = require('./lib/performHash');
const stream = require('stream');
const performHash = require('./lib/performHash');

function hashFileName(options) {
'use strict';
var assemblyStream = new stream.Transform({objectMode: true});
options = options || {};
var format = options.format||"{name}-{hash}{ext}";
const assemblyStream = new stream.Transform({objectMode: true});
let opts = options;
if (!opts || typeof opts !== 'object') {
opts = {};
}
const format = options.format || "{name}-{hash}{ext}";

assemblyStream._transform = function(file, unused, callback) {
this.push(performHash(format, file));
Expand All @@ -15,5 +17,4 @@ function hashFileName(options) {
return assemblyStream;
}

// exporting the plugin main function
module.exports = hashFileName;
4 changes: 2 additions & 2 deletions lib/formatStr.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ function formatStr(text, params) {

if (arguments.length > 1) {
if(typeof params !== 'object') {
params = Array.prototype.slice.call(arguments, 1);
params = Array.prototype.slice.call(arguments, 1); // eslint-disable-line no-param-reassign
re = reNum;
}
else {
re = reObj;
}

text = text.replace(re, function(item) {
text = text.replace(re, function(item) { // eslint-disable-line no-param-reassign
var temp = item.slice(1,-1).split(':');
var key = temp[0];
var length = temp[1];
Expand Down
4 changes: 1 addition & 3 deletions lib/getDateStr.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
function pad(number) {
return (number < 10) ? '0' + number : number;
}
const pad = number => `0${number}`.slice(-2);

function getDateStr(dataObj) {
return dataObj.getUTCFullYear() +
Expand Down
2 changes: 1 addition & 1 deletion lib/performHash.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function performHash(format, file) {
"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) : '',
"mtime": file.stat ? getDateStr(file.stat.mtime) : ''
};
var fileName = formatStr(format, params);
file.path = path.join(dir, fileName);
Expand Down

0 comments on commit cf5908f

Please sign in to comment.