tschaub / grunt-newer

Configure Grunt tasks to run with newer files only.
https://npmjs.org/package/grunt-newer
MIT License
944 stars 53 forks source link

Ability to not overwrite config of a task #36

Open kfiku opened 10 years ago

kfiku commented 10 years ago

I Propose to add the ability to not overwrite config of a task. There are a tasks like grunticon witch need original config (with all files) to work right - so grunt-newer will run full task if any file will change. To ignore changing config (line 120) need to add in never task options changeConfig: false. You can specify changeConfig to all task, or to single taks:

newer: {
    options: {
        cache: 'app/cache/grunt',
        changeConfig: false
    }
}

or

newer: {
    options: {
        cache: 'app/cache/grunt',
        grunticon: {
            changeConfig: false
        }
    }
}
tschaub commented 10 years ago

The way this is implemented, it looks like it would have the same effect as not prefixing your grunticon task with newer.

The point of overwriting the config is so a task works with a limited set of files (only those that are newer). If you don't modify the config, the newer task will have no effect.

Can you give an example of your grunticon config and describe how you expect things to behave with regard to modifying files?

kfiku commented 10 years ago

I known what is newer :) it's grate think, but in grunticon situation I need to run grunticon only if any source file change, but full task, with all files.

grunticon is task that manage svg/png files for all devices and generating png/svs/css for it. So you can't go only with, for example, 3 of 10 images, becouse you end up with css classes for 3 images.

In grunticon like in other css sprite generators images for it is not changing very often, but you need this task in build process. It's also take a while to process (in my situation is 43sec.). So if we can make it faster - check if any file is chcange - it will be very cool.

Example grunticon task

grunticon: {
    options: {
        pngfolder: '',
        template: '<%= conf.app %>/images/sprite/template.hbs'
    },
    icons: {
        files: [{
            expand: true,
            cwd: '<%= conf.app %>/images/sprite',
            src: ['*.svg', '*.png'],
            ext: '.png',
            dest: '<%= conf.app %>/images/generated'
        }],
    }
};
mattkime commented 10 years ago

+1 @kfiku

I'm interested in this functionality as well. I'm taking a look at your patch to see if it solves my problem as well.

thanks!

kfiku commented 10 years ago

@mattkime we are blocked by @tschaub. I think @tschaub don't see a lot of use cases where this feature can be grate. Also grate can be somethink like hybrid with grunt-never and https://github.com/rse/grunt-newer-explicit

tschaub commented 10 years ago

If newer is used in front of a task with a many:1 source:dest file mapping, the task will be run with all source files if any one of them has changed. This sounds like the behavior you want with the grunticon task.

However, with the above configuration, because expand is true in the files config, this looks like a 1:1 src:dest mapping to Grunt (for each source file, one dest file will be generated). It looks like the grunticon task is a special case that doesn't generate 1 dest file for each source file or 1 dest file for many source files. Instead it generates a few dest files for many source files.

Previously (@v0.5.4) there was an any-newer task that would handle cases like this (including all source files if any one of them was newer than a dest file). I'd be curious to hear if using the any-newer task (in the 0.5.4 release) works for you.

kfiku commented 10 years ago

@tschaub I see you still don't understand how grunticon works and how my commit allow newer works with it. Grunticon must be run with all files because it generates ont only one file from many and not many to many. You specify folder where you have svg|png|jpg... files that you want to mage sprite from, next it generate: 3 css files (3 options), png fallbacks for older browsers.

So again:

You say: The way this is implemented, it looks like it would have the same effect as not prefixing your grunticon task with newer But no, svg sprite source files don't change very often, but we need grunticon in build taks and it can be very long (10-50s.). This update will speed think up

mattkime commented 9 years ago

I believe the options.override feature solves this general problem. move to close this pr but i wanted to give @kfiku a heads up