gulp-remember-history
v1.0.0
Published
Adds previously seen files back into the stream while tracking file's history.
Downloads
19
Readme
gulp-remember-history
gulp-remember-history
is a gulp plugin that remembers files that have passed through it. gulp-remember-history
adds all the files it has ever seen back into the stream.
gulp-remember-history
pairs nicely with gulp-cached when you want to only rebuild the files that changed, but still need to operate on all files in the set.
var remember = require('gulp-remember-history');
This plugin is a fork of gulp-remember that adds history capabilities: if a file's name or path changes after being remember
ed, it will still be found in the cache when you'll need to forget
it, thanks to the history kept in all vinyl files at every change.
Usage
This example shows a scenario in which you want to wrap all script files in some type of module system, then concatenate into one app.js
file for consumption.
As long as your other plugins can keep up, this example showcases the Holy Grail of Build Tools™ - the ability to build once, git checkout different-branch
(a branch with drastically different files), and have the output be exactly what you would expect.
var gulp = require('gulp');
var header = require('gulp-header');
var footer = require('gulp-footer');
var concat = require('gulp-concat');
var cache = require('gulp-cached');
var remember = require('gulp-remember-history');
var scriptsGlob = 'src/**/*.js';
gulp.task('scripts', function () {
return gulp.src(scriptsGlob)
.pipe(cache('scripts')) // only pass through changed files
.pipe(header('(function () {')) // do special things to the changed files...
.pipe(footer('})();')) // for example, add a stupid-simple module wrap to each file
.pipe(remember('scripts')) // add back all files to the stream
.pipe(concat('app.js')) // do things that require all files
.pipe(gulp.dest('public/'))
;
});
gulp.task('watch', function () {
var watcher = gulp.watch(scriptsGlob, ['scripts']); // watch the same files in our scripts task
watcher.on('change', function (event) {
if (event.type === 'deleted') { // if a file is deleted, forget about it
delete cache.caches['scripts'][event.path];
remember.forget('scripts', event.path);
}
});
});
API
remember(name)
Returns a stream ready to remember files.
name (optional)
Type: String
The name of a specific cache you want to use. You may want to remember('javascripts')
in one area of your build while also being able to remember('images')
in another.
You can choose not to pass any name if you only care about caching one set of files in your whole build.
remember.forget(name, path)
Drops a file from a remember cache using its history.
name (optional)
Type: String
The name of the remember cache on which you want to operate. You do not need to pass this if you want to operate on the default remember cache.
Note: If the name does not refer to a cache that exists, a warning is logged. Thanks to @jcppman for this.
path (required)
Type: String
The path of the file you wish to drop from the remember cache. The path is used under the covers as the unique identifier for the file within one remember cache.
The path is also looked for in the file's history.
Note: If the path does not match a file object that exists in the given cache, a warning is logged. Thanks to @jcppman for this.
remember.forgetAll(name)
Drops all files from a remember cache.
name (optional)
Type: String
The name of the remember cache you want to wipe. You do not need to pass this if you want to operate on the default remember cache.
Note: If the name does not refer to a cache that exists, a warning is logged.
remember.cacheFor(name)
Get a raw remember cache. This can be useful for checking state of the cache, like whether or not a file has been seen before.
Note: Remembering or forgetting files by interacting directly with this returned object is not recommended.
name (optional)
Type: String
The name of the remember cache you want to retrieve. You do not need to pass this if you want to retrieve the default remember cache.
remember.historyFor(name)
Get a raw remember history. This can be useful for checking state of the history, like whether or not a file has been seen before.
Note: Remembering or forgetting files by interacting directly with this returned object is not recommended.
Another note: An history is a map mapping every filenames in each file's history to the last filename seen by remember
.
name (optional)
Type: String
The name of the remember history you want to retrieve. You do not need to pass this if you want to retrieve the default remember history.
Gotchas
File ordering
Be aware that this plugin does not make specific attempts to keep your files in any order. For example, if you add a new file governed by a glob you are watching, this file will enter the stream last, even if this file would preceed others alphabetically.
If your build process depends on file ordering, please make use of the gulp-order plugin after remember
ing files.
License
This package is licensed under the terms of the MIT license.
This project is a fork of gulp-remember, copyright (c) 2014 Aaron Haurwitz, license MIT.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.