grunt-newer won't work properly with Watchify

868 views Asked by At

I use Grunt for Node with a bunch of packages. For example jsHint, jsDoc, Browserify, Uglify ...

I run the Gruntfile with Watchify and Newer for automation. So far, so good.

The Gruntfile, which works totaly fine:

module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        jshint: {
            all: ['my/js/files/*.js']
        },
        jsdoc : {
            dist : {
                src: ['my/js/files/*.js'], 
                options: {
                    destination: 'doc'
                }
            }
        },
        browserify: {
            'public/js/files/script.js': ['my/js/files/*.js']
        },
        uglify: {
            my_target: {
                files: {
                    'public/js/files/script.js': ['public/js/files/script.js']
                }
            }
        },
        htmlmin: {
            dist: {
                files: {
                    'public/html/index.html': ['public/html/index.html']
                }
            }
        },
        cssmin: {
            combine: {
                files: {
                    'public/css/css.min.css': ['my/css/files/*.css']
                }
            }
        },
        watch: {
            javascript: {
                files: ['my/js/files/*.js'],
                tasks: ['newer:jshint:all', 'jsdoc', 'browserify', 'uglify']
            },
            html: {
                files: ['public/html/index.html'],
                tasks: ['htmlmin']
            },
            css: {
                files: ['public/css/*.css'],
                tasks: ['cssmin']
            }
        }
    });

    // load plugins
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-jsdoc');
    grunt.loadNpmTasks('grunt-browserify');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-htmlmin');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-newer');
};

It works as far as I only use Newer for jsHint. But if I try the same with jsDoc or Uglify I get Error-Messages.

Example:

I try this ...

tasks: ['newer:jshint:all', 'newer:jsdoc:all', 'browserify', 'uglify']

instead of ...

tasks: ['newer:jshint:all', 'jsdoc', 'browserify', 'uglify']

I get Error-Messages:

Running "newer:jsdoc:all" (newer) task
Warning: Cannot read property 'files' of undefined Use --force to continue.
Aborted due to warnings.

Why does it work for jsHint but not for the rest? Has anybody an idea? Would much appreciate some Hints!

Kind regards

1

There are 1 answers

1
hereandnow78 On BEST ANSWER

the target of your jshint task is all, so newer:jshint:all is correct.

your jsdoc target is dist, so you have to use this target: newer:jsdoc:dist

for you it is even easier, you only have one target per task (only your watch task has multiple targets) so you could only do it like this:

 ['newer:jshint', 'newer:jsdoc', 'browserify', 'uglify']