Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run MULTIPLE shell commands in a gruntjs task?

I currently use grunt-shell to run shell commands from a grunt task. Is there a better way to run multiple commands in one task other than stringing them together with '&&'?

My Gruntfile (partial):

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

An array of commands doesn't work, but it would be nice:

grunt.initConfig({
  shell: {
    deploy: {
      options: { stdout: true },
      command: [
        'mkdir -p static/styles',
        'cp public/styles/main.css static/styles'
      ]
    }
  }
});
like image 366
Raine Revere Avatar asked Apr 20 '13 16:04

Raine Revere


1 Answers

You can join them together:

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

The reason I chose not to support arrays is that some might want ; as the separator instead of &&, which makes it easier to do the above.

like image 186
Sindre Sorhus Avatar answered Sep 26 '22 22:09

Sindre Sorhus