Skip to content

Commit

Permalink
Merge pull request #74 from jgable/deps-upd
Browse files Browse the repository at this point in the history
Dependencies update
  • Loading branch information
dangreen authored Jan 7, 2019
2 parents 68aaa15 + d3daa90 commit 4f49df9
Show file tree
Hide file tree
Showing 20 changed files with 7,024 additions and 1,732 deletions.
16 changes: 16 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"exclude": "node_modules/**",
"presets": [
"babel-preset-trigen"
],
"env": {
"test": {
"presets": [
["babel-preset-trigen", {
"targets": { "node": "current" },
"commonjs": true
}]
]
}
}
}
1 change: 1 addition & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extends browserslist-config-trigen/node
3 changes: 3 additions & 0 deletions .clean-publish
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"packageManager": "yarn"
}
6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "trigen/base",
"env": {
"node": true
}
}
6 changes: 0 additions & 6 deletions .eslintrc.js

This file was deleted.

6 changes: 6 additions & 0 deletions .huskyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"hooks": {
"pre-commit": "lint-staged",
"pre-push": "npm test"
}
}
3 changes: 3 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"src/**/*.js": ["eslint --cache", "git add"]
}
5 changes: 5 additions & 0 deletions .size-limit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[{
path: "lib/index.js",
limit: "20 KB",
webpack: false
}]
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.1.0] - 2019-01-07
### Changed
- Dependencies were updated.
- README.md was updated.

## [1.0.2] - 2017-12-30
### Changed
- `gulp-util` -> `plugin-error`
162 changes: 108 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,79 +25,39 @@ A temp file based caching proxy task for [gulp](http://gulpjs.com/).

## Install

```sh
```bash
npm i -D gulp-cache
# or
yarn add -D gulp-cache
```

## Usage
## API

```js
import fs from 'fs';
import gulp from 'gulp';
import jshint from 'gulp-jshint';
import cache from 'gulp-cache';
### `gulpCachePlugin(gulpPluginToCache, options?)`

gulp.task('lint', () =>
gulp.src('./lib/*.js')
.pipe(cache(jshint('.jshintrc'), {
key: makeHashKey,
// What on the result indicates it was successful
success(jshintedFile) {
return jshintedFile.jshint.success;
},
// What to store as the result of the successful action
value(jshintedFile) {
// Will be extended onto the file object on a cache hit next time task is ran
return {
jshint: jshintedFile.jshint
};
}
}))
.pipe(jshint.reporter('default'))
});
#### `gulpPluginToCache`

const jsHintVersion = '2.4.1',
jshintOptions = fs.readFileSync('.jshintrc');
Target plugin, the output of which will be cached.

function makeHashKey(file) {
// Key off the file contents, jshint version and options
return `${file.contents.toString('utf8')}${jshintVersion}${jshintOptions}`;
}
```
#### `options`

## Clearing the cache
Options for `gulp-cache` plugin.

If you find yourself needing to clear the cache, there is a handy dandy `cache.clearAll()` method:

```js
import cache from 'gulp-cache';

gulp.task('clear', () =>
cache.clearAll()
);
```

You can then run it with `gulp clear`.

## Options

#### `fileCache`
##### `options.fileCache`

> [Optional] Where to store the cache objects
- Defaults to `new Cache({ cacheDirName: 'gulp-cache' })`

- Create your own with [`new cache.Cache({ cacheDirName: 'custom-cache' })`](https://github.com/jgable/cache-swap)

#### `name`
##### `options.name`

> [Optional] The name of the bucket which stores the cached objects
- Defaults to `default`

#### `key`
##### `options.key`

> [Optional] What to use to determine the uniqueness of an input file for this task.
Expand All @@ -107,15 +67,15 @@ You can then run it with `gulp clear`.

- Defaults to `file.contents` if a Buffer, or `undefined` if a Stream.

#### `success`
##### `options.success`

> [Optional] How to determine if the resulting file was successful.
- Must return a truthy value that is used to determine whether to cache the result of the task. `Promise` is supported.

- Defaults to true, so any task results will be cached.

#### `value`
##### `options.value`

> [Optional] What to store as the cached result of the task.
Expand All @@ -127,14 +87,108 @@ You can then run it with `gulp clear`.

- Defaults to `'contents'` which will grab the resulting file.contents and store them as a string.

## Usage examples

### Simple

```js
import gulp from 'gulp';
import favicons from 'gulp-favicons';
import srcset from 'gulp-srcset';
import cache from 'gulp-cache';

gulp.task('favicon', () =>
gulp.src('src/favicon.svg')
.pipe(cache(
// Target plugin, the output of which will be cached.
favicons(faviconsConfig),
// Options for `gulp-cache` plugin.
{
// Bucket to store favicons in cache.
name: 'favicons'
}
))
.pipe(gulp.dest('./favicons'))
);

gulp.task('images', () =>
gulp.src('src/**/*.{jpg,png,svg}')
.pipe(cache(
// Target plugin, the output of which will be cached.
srcset(srcsetRules),
// Options for `gulp-cache` plugin.
{
// Bucket to store images in cache.
name: 'images'
}
))
.pipe(gulp.dest('./images'))
);
```

### Complex

```js
import fs from 'fs';
import gulp from 'gulp';
import jshint from 'gulp-jshint';
import cache from 'gulp-cache';

const jsHintVersion = '2.4.1';
const jshintOptions = fs.readFileSync('.jshintrc');

function makeHashKey(file) {
// Key off the file contents, jshint version and options
return `${file.contents.toString('utf8')}${jshintVersion}${jshintOptions}`;
}

gulp.task('lint', () =>
gulp.src('src/**/*.js')
.pipe(cache(
// Target plugin, the output of which will be cached.
jshint('.jshintrc'),
// Options for `gulp-cache` plugin.
{
key: makeHashKey,
// What on the result indicates it was successful
success(jshintedFile) {
return jshintedFile.jshint.success;
},
// What to store as the result of the successful action
value(jshintedFile) {
// Will be extended onto the file object on a cache hit next time task is ran
return {
jshint: jshintedFile.jshint
};
}
}
))
.pipe(jshint.reporter('default'))
});
```

## Clearing the cache

If you find yourself needing to clear the cache, there is a handy dandy `cache.clearAll()` method:

```js
import cache from 'gulp-cache';

gulp.task('clear', () =>
cache.clearAll()
);
```

You can then run it with `gulp clear`.

## One-to-many caching

To support one-to-many caching in Your Gulp-plugin, you should:

* Use `clone` method, to save `_cachedKey` property:
```js
const outputFile1 = inputFile.clone({ contents: false }),
outputFile2 = inputFile.clone({ contents: false });
const outputFile1 = inputFile.clone({ contents: false });
const outputFile2 = inputFile.clone({ contents: false });

outputFile1.contents = new Buffer(...);
outputFile2.contents = new Buffer(...);
Expand Down
13 changes: 13 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"testEnvironment": "node",
"testRegex": "/test/.*\\.spec\\.js$",
"collectCoverage": true,
"collectCoverageFrom": [
"src/**/*.js",
"!**/node_modules/**"
],
"coverageReporters": [
"lcovonly",
"text"
]
}
Loading

0 comments on commit 4f49df9

Please sign in to comment.