繁体   English   中英

如何从grunt任务中运行node_modules中的脚本?

[英]How can I run a script in node_modules from a grunt task?

我想简化从命令行运行测试套件的方法。 所以我将以下grunt-shell任务添加到我们的Gruntfile.js

module.exports = function( grunt ) {

  grunt.initConfig(
    {
      shell : {
        e2e : {
          command : "./node_modules/protractor/bin/protractor protractor_conf.js"
        }
      }
    }
  );

  grunt.loadNpmTasks( "grunt-shell" );

  grunt.registerTask( "e2e", ["shell:e2e"] );
};

当我运行任务时,我收到错误:

'.' is not recognized as an internal or external command, operable program or batch file.

我发现的运行shell命令的所有示例都运行了全局可访问的二进制文件,但我想启动本地安装的量角器二进制文件。

我在Windows上使用bash,以防万一。

我正在研究OSX ......但是它仍然适用于你?

我刚在Gruntfile中提供了一个绝对路径:

module.exports = function(grunt) {

    grunt.initConfig({
        shell: {
            test: {
                // command: 'sh /Users/default/Sites/dev/test.sh'
                command: 'node /Users/default/Sites/dev/test.js'
            }
        }
    });

    grunt.loadNpmTasks('grunt-shell');
    grunt.registerTask('default', ['shell']);
};

这为我提供了正确的输出。

我遇到的类似问题的其他一些有用的任务:

grunt-execute,grunt-run

您可以将protractor作为参数传递给node以调用它,如下所示:

module.exports = function( grunt ) {

  grunt.initConfig(
    {
      shell : {
        e2e : {
          command : "node ./node_modules/protractor/bin/protractor protractor_conf.js"
        }
      }
    }
  );

  grunt.loadNpmTasks( "grunt-shell" );

  grunt.registerTask( "e2e", ["shell:e2e"] );
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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