node.js - 如何在 gruntjs 任务中运行多个 shell 命令?

标签 node.js gruntjs

我目前使用 grunt-shellgrunt 运行 shell 命令任务。除了用 '&&' 将它们串在一起之外,有没有更好的方法在一个任务中运行多个命令?

我的 Gruntfile(部分):

grunt.initConfig({
  shell: {
    deploy: {
      options: { stdout: true },
      command: 'mkdir -p static/styles && cp public/styles/main.css static/styles'
    }
  }
});

一系列命令不起作用,但它会很好:

grunt.initConfig({
  shell: {
    deploy: {
      options: { stdout: true },
      command: [
        'mkdir -p static/styles',
        'cp public/styles/main.css static/styles'
      ]
    }
  }
});

最佳答案

您可以将它们结合在一起:

grunt.initConfig({
  shell: {
    deploy: {
      options: { stdout: true },
      command: [
        'mkdir -p static/styles',
        'cp public/styles/main.css static/styles'
      ].join('&&')
    }
  }
});

我选择不支持数组的原因是有些人可能希望 ; 作为分隔符而不是 &&,这样可以更轻松地执行上述操作。

关于node.js - 如何在 gruntjs 任务中运行多个 shell 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16122549/

相关文章:

javascript - 高阶函数(如 .map())如何在 JavaScript 内部工作?

javascript - Node 红色。从对象数组中获取项目

javascript - 如何使用单个 catch 函数进行嵌套异步等待?

javascript - 如何从 grunt 任务函数运行终端命令

javascript - 使用 grunt-ssh 下载远程资源

javascript - grunt 自动前缀配置

json - Grunt 不会从 grunt-json-server 运行 json_server 任务

javascript - 如何为 Gruntfile.js 使用替代名称?

node.js - Auth0 与 Angular2 "Supplied parameters do not match any signature of call target."

node.js - 快速记录颜色格式