Run Shell Command Through Grunt Task - Grunt Shell

Introduction

 
Grunt is a great way to automate our development processes. Sometimes we have to rely on some packages as they are either NPM package or they are Bower components. It’s not necessary if our client’s production Server has all those packages installed already or they don’t give access to set up the environment or install missing dependencies.
 
It’s not only limited to missing packages, maybe we want to do something with Shell, for example, install those packages to a separate directory, or let’s say you just want to create a directory for any reason.
 
Grunt Shell is here to help us in this regard.
 
Install Grunt
 
First of all, you need to install Grunt in your development environment, of course, from Node Package Manager. I am using VS Code and it has a very handy integrated terminal. Press CTRL + ` to open up the terminal and install Grunt by pasting the commands given below.
 
npm install grunt
 
Install Grunt Shell
 
After the successful installation of Grunt, now install Grunt Shell by running the command given below.
 
npm install grunt-shell
 
 
Write Grunt Task
 
Create a file in your project root directory with the name Gruntfile.js and define Grunt Task in it to run Shell commands.
 
 
Gruntfile.js
  1. module.exports = function(grunt) {  
  2.     grunt.loadNpmTasks('grunt-shell');  
  3.     grunt.initConfig({  
  4.         shell: {  
  5.             command: ["npm install bower""bower install angular""bower install angularjs""bower install bootstrap""bower install jquery""bower install tether"].join('&&')  
  6.         }  
  7.     });  
  8.     grunt.registerTask('default', ['shell']);  
  9. };  
Now, run Grunt task by typing Grunt in the terminal, as it is registered as a default task. Due to this, there is no need to mention the name of the task.
 
 
All the Shell commands mentioned in the task have started executing.