tschaub / grunt-newer

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

Error while checking same folder for two different tasks #50

Open mbrammer opened 10 years ago

mbrammer commented 10 years ago

In my config I'm checking the same folder and files for grunt-csscomb and grunt-compass. But if the newer task has checked the state for csscomb, it doesn't work for compass anymore. I need a way to say grunt-newer to check newer files for every task.

tschaub commented 10 years ago

Can you provide a link to or paste the relevant bits of your config?

mbrammer commented 10 years ago
module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        compass: {
            options: {
                sassDir: '<%= pkg.sassAppDir %><%= pkg.theme %>/watchdir',
                cssDir: '<%= pkg.cssDir %><%= pkg.theme %>',
                raw: 'preferred_syntax = :scss\n',
                relativeAssets: true,
                imagesDir: '<%= pkg.imgDirPublic %><%= pkg.theme %>/',
                httpImagesPath: '<%= pkg.imgDir %><%= pkg.theme %>/',
                spriteLoadPath: '<%= pkg.imgDirPublic %><%= pkg.theme %>/sprite-source/',
                generatedImagesDir: '<%= pkg.imgDirPublic %><%= pkg.theme %>/sprites/',
                httpGeneratedImagesPath: '<%= pkg.imgPath %><%= pkg.theme %>/sprites/'
            },
            production: {
                outputStyle: 'compressed'
            },
            development: {
                outputStyle: 'expanded'
            }
        },

        csscomb: {
            dynamic_mappings: {
                expand: true,
                cwd: '<%= pkg.sassAppDir %>',
                src: ['**/*.scss', '!**/lib/*.scss', '!**/sprites/*.scss', '!<%= pkg.theme %>/variables.scss'],
                dest: '<%= pkg.sassAppDir %>',
                options: {
                    config: 'csscomb.json'
                }
            }
        },

        watch: {
            css: {
                files: ['<%= pkg.watchSass %>'],
                tasks: ['newer:csscomb', 'newer:compass:development'],
                options: {
                    livereload: true
                }
            }
        }
    });

    // Load the plugins
    grunt.loadNpmTasks('grunt-csscomb');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-sass');
    grunt.loadNpmTasks('grunt-contrib-compass');
    grunt.loadNpmTasks('grunt-newer');

    // Default task(s)
    grunt.registerTask('default', ['watch']);
};

If I add a new file I get this output:

Running "newer:csscomb" (newer) task

Running "newer:csscomb:dynamic_mappings" (newer) task

Running "csscomb:dynamic_mappings" (csscomb) task
>> Using custom config file "csscomb.json"...
>> Sorting file "[...]/test3.scss"...

Running "newer-postrun:csscomb:dynamic_mappings:1:[...]/node_modules/grunt-newer/.cache" (newer-postrun) task

Running "newer:compass:development" (newer) task
No newer files to process.

Done, without errors.

compass:development should run, because it's a new file...

mbrammer commented 10 years ago

I figured out that compass is the problem. If I run grunt newer:compass:development it will never find a new or updated file (also if I created a new file seconds ago without haven the grunt watcher started).

Running "newer:compass:development" (newer) task
No newer files to process.

Done, without errors.

I I just run grunt compass:development, everything is working fine.

Running "compass:development" (compass) task
unchanged [...]/sprites/layout-s460f7606d1.png
identical [...]/category.css (0.547s)
[...]
   create [...]/test.css (0.008s)
   create [...]/test2.css (0.001s)
   create [...]/test3.css (0.001s)
   create [...]/test4.css (0.001s)
   create [...]/test5.css (0.001s)
Compilation took 5.785s

Done, without errors.
benje commented 9 years ago

I also get this problem using compass with the grunt-newer plugin. :(

oliverchrist commented 9 years ago

You can use src in your compass config and it will work. E.g.

compass: {
    src: '<%= pkg.sassAppDir %><%= pkg.theme %>/watchdir/**/*.scss',
    options: {
        sassDir: '<%= pkg.sassAppDir %><%= pkg.theme %>/watchdir',
mbrammer commented 9 years ago

@oliverchrist No, that didn't work :(

oliverchrist commented 9 years ago

Have you tried putting "src" in the subtask, too?