Gruntjs 让grunt中的循环运行相同的脚本,但传入不同的参数

Gruntjs 让grunt中的循环运行相同的脚本,但传入不同的参数,gruntjs,grunt-exec,Gruntjs,Grunt Exec,因此,我有一个javascript文件,当前可以使用cmd节点runfile.js accountName运行该文件。 我正在尝试创建一个grunt任务,该任务将循环通过一个AccountName数组,并使用grunt exec传递到此cmd 我对咕哝很陌生,如果措辞不恰当,我会道歉。非常感谢您的帮助 当前grunt文件看起来像: grunt.initConfig({ exec: { login: function(acct){ return 'node

因此,我有一个javascript文件,当前可以使用cmd
节点runfile.js accountName
运行该文件。 我正在尝试创建一个grunt任务,该任务将循环通过一个AccountName数组,并使用grunt exec传递到此cmd

我对咕哝很陌生,如果措辞不恰当,我会道歉。非常感谢您的帮助

当前grunt文件看起来像:

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

我能够用下面的代码成功地做到这一点

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);
    });
});

 };

我能够用下面的代码成功地做到这一点

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);
    });
});

 };