Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 让Grunt.js运行node.js模块_Javascript_Node.js_Gruntjs_Node Modules - Fatal编程技术网

Javascript 让Grunt.js运行node.js模块

Javascript 让Grunt.js运行node.js模块,javascript,node.js,gruntjs,node-modules,Javascript,Node.js,Gruntjs,Node Modules,我编写了一个node.js模块,可以使用'require'从文件运行,也可以从终端运行node copyright.update()。我对这个功能很满意,它在这两种情况下都能工作。我还希望能够从Gruntfile.js运行它 当前我的grunt文件如下所示: module.exports = function(grunt) { grunt.initConfig({ "update-copyright": { "run": true

我编写了一个node.js模块,可以使用'require'从文件运行,也可以从终端运行node copyright.update()。我对这个功能很满意,它在这两种情况下都能工作。我还希望能够从Gruntfile.js运行它

当前我的grunt文件如下所示:

module.exports = function(grunt) {

    grunt.initConfig({

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

    grunt.task.loadTasks('./runner');
};
var copyright = require('./update-copyright');

module.exports = function(grunt) {

    grunt.registerMultiTask('update-copyright', 'update copyright headers', function() {
        var done = this.async();
        copyright.update(done);
    });
};
runner目录中的脚本如下所示:

module.exports = function(grunt) {

    grunt.initConfig({

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

    grunt.task.loadTasks('./runner');
};
var copyright = require('./update-copyright');

module.exports = function(grunt) {

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

当我运行“grunt update copright”时,我完成了通常的操作,没有错误,但实际上没有执行任何操作。我肯定我错过了一些简单的东西。非常感谢您的帮助

多亏了Igor Raush的评论,我才得以运行它:

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

module.exports = function(grunt) {

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

您的任务是否完全同步?感谢您的关注。它是完全异步的。这就是问题所在吗?谢谢@IgorRaush-解决了!Grunt将在任务有机会执行任何操作之前终止进程。看起来这就是问题所在:)