Getting Grunt.js to run node.js module

时间:2015-10-30 22:54:41

标签: javascript node.js gruntjs node-modules

I have written a node.js module that can be run either from file using 'require' or by running node copyright.update() from the terminal. I'm happy with this functionality and it works in both cases. I want to also be able to run it from Gruntfile.js.

Currently my grunt file looks like this:

module.exports = function(grunt) {

    grunt.initConfig({

        "update-copyright": {
            "run": true
        }
    });

    grunt.task.loadTasks('./runner');
};

And the script in the runner directory looks like this:

var copyright = require('./update-copyright');

module.exports = function(grunt) {

    grunt.registerMultiTask('update-copyright', 'update copyright headers', function() {
        var done = this.async();
        copyright.update(done);
    });
};

When I run 'grunt update-copright' I get the usual Done, without errors but nothing has actually been executed. I'm sure I'm missing something simple. Any help is greatly appreciated!

1 个答案:

答案 0 :(得分:0)

Thanks to the comment by Igor Raush I got it to run with: var copyright = require('./update-copyright'); module.exports = function(grunt) { grunt.registerMultiTask('update-copyright', 'update copyright headers', function() { var done = this.async(); copyright.update(done); }); };