简体   繁体   中英

Getting Grunt.js to run node.js module

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!

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);
    });
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM