无法将 G运行t 转换为 运行 node.js 脚本

Trouble getting Grunt to run node.js script

我是 g运行t 和节点菜鸟,但我设法编写了一个节点脚本来执行我想要的操作并从命令行运行。我不想将脚本发布为节点模块,但我想从我的 g运行t 文件中 运行 它。

我需要对脚本进行哪些更改(如果有)才能使其生效?

关于配置 g运行t 文件和自定义任务的了解越多,我就越困惑。我目前有这样的东西:

module.exports = function(grunt) {

    grunt.initConfig({
        'mytaskname': 'what goes here?'
    });

    grunt.loadNpmTasks('./node_modules/script_name');

    grunt.registerTask('run-from-command-line', 'description', function() {
        grunt.log.writeln('Not running...');
    });
}

如有任何帮助,我们将不胜感激。

您可以使用 grunt-execute 插件执行此操作,它在 node.js 子进程中执行文件。

示例: 如果您的节点脚本在 "node-scripts/script.js" 中,Gruntfile.js 将如下所示:

module.exports = function(grunt) {
    grunt.initConfig({
        execute: {
            target: {
                src: ["node-scripts/script.js"]
            }
        }
    });

    // Load the plugins
    grunt.loadNpmTasks("grunt-execute");

    grunt.registerTask("default", ["execute"]);
};