Coder Social home page Coder Social logo

gulp-save's Introduction

gulp-save Build Status

Store and restore files in stream.

Install

$ npm install --save-dev gulp-save

Usage

var gulp = require('gulp');
var save = require('gulp-save');
var uglify = require('gulp-uglify');

gulp.task('default', function () {
	return gulp.src('src/*.js')
		.pipe(save('before-uglify', opts)) //cache all files here
		.pipe(uglify())
		.pipe(gulp.dest('dist'))
		.pipe(save.restore('before-uglify')) //restore all files to the state when we cached them
		.pipe(gulp.dest('dist'));

});

API

save(cache, opts)

####cache

Type: string
Default: ``

Key where the stream will be cached.

####opts Same as vinyl clone options

save.restore(cache)

####cache

Type: string
Default: ``

Key from where stream should be restored.

save.clear(cache, cache, ...)

####cache

Type: string
Default: ``

Cache item to clear. If save.clear is called with no parameters, it will clear the whole cache.

License

MIT © Daniel Husar

gulp-save's People

Contributors

danielhusar avatar maxart2501 avatar mjancarik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gulp-save's Issues

Always create stores

At the moment, the plugin creates a store only when the first file is passed through the stream.
This leads to missing stores when the stream is empty for some reason, so restore won't find the store.

Thanks to #6 now this can be caught and dealt with, but would it be a problem to create the store right away, instead of waiting for the first file to be passed?

Clearing cache

Hi,
I was close to make myself a plugin like this, but then I found yours and noticed this is exactly what I had in mind. Nice!

One thing I'd suggest is the ability to clear the cache, because for large numbers of files and longer tasks it may nice to have memory freed as the task proceed. This comes especially useful whe manipulating images or other large files.

I had two strategies in mind: one would be adding a second, boolean argument to restore, like this:

module.exports.restore = function (store, clear) {
    ...
    cache[store].forEach(function (file) {
        this.push(file);
    }.bind(this));

    if (clear) {
        delete cache[store];
    }
    ...
};

The other approach would be adding a clear method to the plugin, that clears the whole cache (or maybe just a selection of stores):

module.exports.clear = function () {
    var stores;
    if (arguments.length) {
        stores = Array.prototype.slice.call(arguments);
    } else {
        stores = Object.keys(cache);
    }

    stores.forEach(function(store) {
        delete cache[store];
    };
};

What do you think about it?

Vinyl files should be cloned.

Hi,

First of all, congratulations for a very useful plugin.

I have used it and ran into some problems. I think it could be improved if the cached vinyl files are cloned using the clone method instead of passing the file to the constructor.

The problem with the current implementation is that properties are shared between the original vinyl files and the cached ones. Whenever you copy the file somewhere, the cached files change as well.

This behaviour is unexpected.

Thank you.

restore function

Hi,

I have problem with restore function. In next pipe task I haven't cached file.

Not working part:

cache[store].forEach(function (file) {
    this.emit('data', file);
}.bind(this));

this.emit('end');

Update to:

cache[store].forEach(function (file) {
    this.push(file);
}.bind(this));

cb();

can be restore only once

It seems that gulp-save can restore only once, is it correct?
when i call save.restore twice, the second call seems did nothing, just pipe the upper stream.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.