1

so I have this javascript file that I can currently run with the cmd node runfile.js accountName. I am trying to make a grunt task that will loop through an array of accountNames to pass into this cmd using grunt-exec.

I am pretty new to grunt and apologize if this is not worded well. Any help is very appreciated!

Current grunt file looks like:

  grunt.initConfig({
    exec: {
      login: function(acct){
        return 'node runfile.js' + acct; 
      }
    },
 });

1 Answers1

0

I was able to successfully do this with the following code.

module.exports = function(grunt) {
 grunt.initConfig({
  exec: {
    runMobile: {
          cmd: function(account, password){
            return 'node javascript.js ' + account + ' ' + password
          }
      },
    runDesktop: {
          cmd: function(account, password, first_name){
            return 'node javascript2.js ' + account + ' ' + password + ' ' + first_name
    }
  }
}
});


 grunt.loadNpmTasks('grunt-exec');
//get our list of accounts
var fs = require('fs');
var data = JSON.parse(fs.readFileSync('node_modules/selenium-webdriver/example/accounts.json', 'utf-8'));


 grunt.registerTask('default', 'Running The task',function(){
    data.accounts.forEach(function(payload){                          
      grunt.task.run('exec:runMobile:'+payload.account+':'+payload.password);
      grunt.task.run('exec:runDesktop:'+payload.account+':'+payload.password+':'+payload.first_name);
    });
});

 };